mmcdara

7891 Reputation

22 Badges

9 years, 54 days

MaplePrimes Activity


These are replies submitted by mmcdara

@FDS 

Hi,

  • How can you write normalisatie in one line:
    normalisatie := C__i /~ C__0):
    
    The "~" operator makes the prefixed operator to act element per element (type help(operators,elementwise (~)); here all the elements of C__i are divided by the same constant C__0
     
  • Why do you have to use 'copy'?
    I wrote it as a reminder, more to remind myself that there was a problem here that needed to be addressed eventually than from real necessity.
    But writting local gamma__i_min :=Gamma__i_min will do the same thing. So you can indeed remove the 'copy'.

@dharr 

Not my day!

First I didn't read the entire question, which is a bad start.
Next I had written a first reply saying that you were right: there is no documentation about `<,>` nor `<|>` (completing this while saying that `[ ]`and `{ }` seem undocumented too).
And finally I deleted this reply to write this stupid answer.

Time to go bed

@dharr 

Thank you Dharr for having corrected me.

You are right, I should have say "confusing" instead of "conflictual" about the procedure integraal.

You are right too about the loop: in fact I don't like this notation where the initial value of the counter is ommited (I never use it) and I didn't check what it was doing before writting i:=0.

In the for help page there is this example

tot := 0:
for i from 11 by 2 while i < 100 do
   tot := tot + i
end do:
tot;

which I would have written in a more "natural" way 

tot := 0:
for i from 11 to 100 by 2 do
   tot := tot + i
end do:
tot;

I was learnt about for.. do, while..do and repeat..until structures, and in my mind they are distinct structures not to be mixed...but I guess I'm from the old school.

To find it I went to the Maple 2023 programming guide

https://www.maplesoft.com/documentation_center/Maple2023/ProgrammingGuide.pdf,

at page 30:   So simply go to the help page 

help(LinearAlgebra,General,MVshortcut (MVshortcut)); #all but obvious

​​

@C_R 

Thanks C_R, I was petty sure I had seen it before

@Carl Love 

Great!

(I think I've seen this before on this site, but my memory sometimes plays tricks at me).

@maple 

Sorry I messed up, my answer is updated now

@Carl Love 

Thanks Carl for having corrected me.
I edited my answer meanwhile.

@dharr  @acer

Great thanks to both of you for these extremely nice solutions!

I vote up for each of you, of course,  but I'm very embarrassed to choose the best answer.
On one side I prefer the "@acer's catch the limit", which seems more generic to me, while on the other side I find very clever @dharr's earlier nice (as @acer himself says) solution.

@delvin 

Thanks

@delvin 

I was kidding, don't take it at face value.

What I wanted to say is that as soon as you have more equations than unknowns the existence of a solution is hazardous, unless those equations are linked in some way such that their number reduces after simple algebraic transformations.

In the three attach files you will find:

  • a simple proof that T1 has solutions and that your original system can be reduced to a system of 2 equations in 2 unknowns (file T1_details.mw , file  T1_details_2.mw proves there exist 4 solutions one can easily obtain by hand)
  • a simple proof that T2 doesn't have any solution even if you add d as an unknown.

T1_details.mw  and  T1_details_2.mw

T2_details.mw



I recognize in your question a divided difference approximation of a diffusion equation with diffusion coefficient 1+a*gamma*alpha(x).
Am I right?

If it is so, then your discrete approximation of the diffusion scheme is not consistent

This can easily seen by putting alpha(x) = Constant.
The proof is given at the end of the attached file whose first part is dedicated to the construction of a consistent approximation of the diffusion term

diff(alpha(x)*diff(u(x, t), x), x)


 

restart


Consistent divided difference approximation of a diffusion term

diffusion := Diff(alpha(x)*Diff(u(x, t), x), x)

Diff(alpha(x)*(Diff(u(x, t), x)), x)

(1)

# Introducing the flux phi(x, t) = alpha(x)*Diff(u(x, t), x),
# rewrite diffusion this way

flux_div := Diff(phi(x, t), x)

Diff(phi(x, t), x)

(2)

# Assuming the spatial mesh is uniform with (constant) step
# h = x[i+1]-x[i] whatever the value of i (let's put apart the
# problem of boundary conditions).
#
# At point x=x[i] a centered divided difference approximation
# of flux_div is

cdd_flux_diff := i -> (phi(x[i]+h/2, t) - phi(x[i]-h/2, t))/h

proc (i) options operator, arrow; (phi(x[i]+(1/2)*h, t)-phi(x[i]-(1/2)*h, t))/h end proc

(3)

# A centered divided difference approximation of phi(x[i]+(1/2)*h, t) at
# point x=x[i]+h/2 is

phi(x[i]+(1/2)*h, t) = alpha(x[i]+(1/2)*h)*(u(x[i]+h, t) - u(x[i], t))/h

phi(x[i]+(1/2)*h, t) = alpha(x[i]+(1/2)*h)*(u(x[i]+h, t)-u(x[i], t))/h

(4)

# A centered divided difference approximation of phi(x[i]-(1/2)*h, t) at
# point x=x[i]-h/2 is

phi(x[i]-(1/2)*h, t) = alpha(x[i]-(1/2)*h)*(u(x[i], t) - u(x[i]-h, t))/h

phi(x[i]-(1/2)*h, t) = alpha(x[i]-(1/2)*h)*(u(x[i], t)-u(x[i]-h, t))/h

(5)

# Combining relations 5, 6 and 7 gives

cdd_diffusion := eval(cdd_flux_diff(i), [(4), (5)])

(alpha(x[i]+(1/2)*h)*(u(x[i]+h, t)-u(x[i], t))/h-alpha(x[i]-(1/2)*h)*(u(x[i], t)-u(x[i]-h, t))/h)/h

(6)

# Write cdd_diffusion in a more convenient form

select(has, indets(cdd_diffusion, function), t);

cdd_diffusion := collect(cdd_diffusion, %);

{u(x[i], t), u(x[i]-h, t), u(x[i]+h, t)}

 

(-alpha(x[i]+(1/2)*h)/h-alpha(x[i]-(1/2)*h)/h)*u(x[i], t)/h+alpha(x[i]-(1/2)*h)*u(x[i]-h, t)/h^2+alpha(x[i]+(1/2)*h)*u(x[i]+h, t)/h^2

(7)

# Assuming alpha(x) is continuous within each cell x[i]..x[i+1] whatever the
# value of i, simple approximations of alpha at "mid" points x[i]-(1/2)*h and
# then are

alpha(x[i]-(1/2)*h) = (alpha(x[i]-h) + alpha(x[i]))/2,
alpha(x[i]+(1/2)*h) = (alpha(x[i]) + alpha(x[i]+h))/2;

alpha(x[i]-(1/2)*h) = (1/2)*alpha(x[i]-h)+(1/2)*alpha(x[i]), alpha(x[i]+(1/2)*h) = (1/2)*alpha(x[i])+(1/2)*alpha(x[i]+h)

(8)

# Plug these relations into (7)

cdd_diffusion := map(simplify, eval(cdd_diffusion, [(8)]))

-(1/2)*(2*alpha(x[i])+alpha(x[i]+h)+alpha(x[i]-h))*u(x[i], t)/h^2+(1/2)*(alpha(x[i]-h)+alpha(x[i]))*u(x[i]-h, t)/h^2+(1/2)*(alpha(x[i])+alpha(x[i]+h))*u(x[i]+h, t)/h^2

(9)

# You wrote

yours := -(
-(1/2)*(2*alpha(x[i])+alpha(x[i]+h)+alpha(x[i]-h))*u(x[i], t)/h^2+(1/2)*(alpha(x[i]+h)+alpha(x[i]-h))*u(x[i]-h, t)/h^2-(1/2)*(alpha(x[i]+h)-alpha(x[i]-h))*u(x[i]+h, t)/h^2
)

(1/2)*(2*alpha(x[i])+alpha(x[i]+h)+alpha(x[i]-h))*u(x[i], t)/h^2-(1/2)*(alpha(x[i]+h)+alpha(x[i]-h))*u(x[i]-h, t)/h^2+(1/2)*(alpha(x[i]+h)-alpha(x[i]-h))*u(x[i]+h, t)/h^2

(10)

# assuming alpha is a constant C gives

eval(yours, alpha=(z -> C))

2*C*u(x[i], t)/h^2-C*u(x[i]-h, t)/h^2

(11)

# as expression (9) gives
# (you should recognize here the correct estimation of C*diff(u(x, t), x$2)
eval((9), alpha=(z -> C))

-2*C*u(x[i], t)/h^2+C*u(x[i]-h, t)/h^2+C*u(x[i]+h, t)/h^2

(12)

# Proof that (12) approximates C*diff(u(x, t), x$2) = C*(D[1, 1](u))(x[i], t)
# at point x=x[i] with error O(h^2)

taylor((12), h, 3)

series(C*(D[1, 1](u))(x[i], t)+O(h^1),h,1)

(13)

# What does your expression (11) approximates?

taylor((11), h, 3)

Error, does not have a taylor expansion, try series()

 

series((11), h, 3)

series((C*u(x[i], t))/h^2+(C*(D[1](u))(x[i], t))/h-(1/2)*C*(D[1, 1](u))(x[i], t)+O(h^1),h,1)

(14)

# Obviously formula (10) is not a consistent approximation of
# the continuous diffusion operator (1)

 

Add on

 

with(IntegrationTools):

# Mass conservation within cell x=x[i]-h/2..x[i]+h/2.
#
# For any function psi(x) "regular enough" one gets this weak expression
# of mass conservation

MC := Int(eval(diffusion, [u=((x, t) -> U(x))])*psi(x), x=X[i]-h/2..X[i]+h/2) = 0

Int((Diff(alpha(x)*(Diff(U(x), x)), x))*psi(x), x = X[i]-(1/2)*h .. X[i]+(1/2)*h) = 0

(15)

# Integrating by parts gives

MC := Parts(MC, psi(x)) assuming h > 0

alpha(X[i]+(1/2)*h)*(D(U))(X[i]+(1/2)*h)*psi(X[i]+(1/2)*h)-alpha(X[i]-(1/2)*h)*(D(U))(X[i]-(1/2)*h)*psi(X[i]-(1/2)*h)-(Int(alpha(x)*(Diff(U(x), x))*(diff(psi(x), x)), x = X[i]-(1/2)*h .. X[i]+(1/2)*h)) = 0

(16)

# A particular choice of psi(x) is psi(x)=constant which, without loss of
# generality, can be chosen equal to 1.
# This gives:

value(eval(MC, psi=(x -> 1)))

alpha(X[i]+(1/2)*h)*(D(U))(X[i]+(1/2)*h)-alpha(X[i]-(1/2)*h)*(D(U))(X[i]-(1/2)*h) = 0

(17)

# This is basically the equation cdd_flux_diff(i)=0.
#
# Now you can use any formula you want to approximate the 4 terms
# relation (17) contains, provided the final result is a consistent
# approximation of the fluxes at walls x=X[i]-h/2 and X[i]+h/2.
#
# What is used here is a staggered mesh where cells are X[i]-h/2..X[i]+h/2,
# U(x) is expressed at the center of the cells and fluxes at their walls.

 

 

Download Unconsistent_scheme.mw

The discretization of the term diff(u(x, t), t) is not consistent neither: a term of the form u(x[i], t[n+p]), with p=+1 (explicit scheme), p=-1 (fully implicit scheme), or any other value of p, is missing.

Before thinking to build the matrices and vectors you have in mind, I advice you to verify your discretization scheme.

As I can only use Maple 2015 at the moment and many improvements have since been made to pdsolve, I can just give you a simple advice: browse this site https://www.12000.org/my_notes/pde_in_CAS/pde_in_cas.htm to find if Maple (site edited up to Maple 2021) is capable to handle your problem.

I wasn't capable to find a test case corresponding to your problem but, on the other side, I'm not sure this problem is well posed (I have to get back to my old notes to check that).
I seem to remember that the boundary conditions have to be set at both ends of the bar and, even in this case, you do not necesseraly have a well-posed problem.

@delvin 

I use to use only worksheet mode with 1D inputs.
Here is the file written with Maple 2015
Balance_2015.mw

Strangely your reply is not correctly displayed with Safari (see below) as it is with Firefox.
I believe this is the first time I notice this.

The first one is a classical advice to all newbye: download your Maple worksheet by using the green up-arrow in the menu bar.

Given the complexity of your pdes there is no chance at all that you can get a formal solution.
To expect a numerical approximation of the solution you will have to give numerical values to all the sonstants and provide initial and boundary conditions.
Actually, I'm not even sure that Maple can solve numerically this system.

The last advidce: write command lines in separate blocks to understand where the error come from.
If you write the commands in a single block all the errors are displayed stacked at the end of the block.

Take inspiration from this

restart:

alias(U[1]=U[1](t, x, y, z)):
alias(U[2]=U[2](t, x, y, z)):
alias(U[3]=U[3](t, x, y, z)):
alias(phi=phi(t, x, y, z)):

PDE1 := c[1, 1]*diff(U[1], y, y) + c[1, 2]*diff(U[2], x, y) + c[1, 3]*diff(U[3], x, z) + e[3, 1]*diff(phi, x, z) + c[6, 6]*diff(U[2], x, y) + c[6, 6]*diff(U[1], y, y) + c[4, 4]*diff(U[3], x, z) + c[4, 4]*diff(U[1], z, z) + e[1, 5]*diff(phi, x, y) = rho*diff(U[1], t, t):

 

PDE1 := simplify(PDE1, size);

(c[1, 1]+c[6, 6])*(diff(diff(U[1], y), y))+(c[1, 2]+c[6, 6])*(diff(diff(U[2], x), y))+(c[1, 3]+c[4, 4])*(diff(diff(U[3], x), z))+e[1, 5]*(diff(diff(phi, x), y))+e[3, 1]*(diff(diff(phi, x), z))+c[4, 4]*(diff(diff(U[1], z), z)) = rho*(diff(diff(U[1], t), t))

(2)

# Proceed this way for the other pdes.

 

Download Corrections.mw

First 39 40 41 42 43 44 45 Last Page 41 of 154