awass

301 Reputation

10 Badges

19 years, 145 days

MaplePrimes Activity


These are questions asked by awass

restart;
Here is my pde and a procedure that plots the solution.
K1:=proc(g)
uses PDEtools,plots:
local pde, ic,ans;
pde:=-4*x*diff(f(u,x),u,x)+4*diff(f(u,x),u)=x^4*diff(f(u,x),x,x)+x^3*diff(f(u,x),x)+8*x^2*f(u,x)*(1-f(u,x)^2);
ic:={f(u,0) = 1, f(u,1) = 0,f(0,x)=g};
ans:=pdsolve(pde,ic,numeric,compile=true,time=u,range=0..1,'spacestep'=0.005);
ans:-plot(u=3)
end proc:
K1(1+x^2-2*x^3);

It works just fine; I get a plot of f(u,x) for u =3.  (Note that unlike dsolve there is no complaint about the global variable g in the initial conditions.)
Now I want to see a plot of diff(f(u,x) for u=3.
K2:=proc(g)
uses PDEtools,plots:
local pde, ic,ans;
pde:=-4*x*diff(f(u,x),u,x)+4*diff(f(u,x),u)=x^4*diff(f(u,x),x,x)+x^3*diff(f(u,x),x)+8*x^2*f(u,x)*(1-f(u,x)^2);
ic:={f(u,0) = 1, f(u,1) = 0,f(0,x)=g};
ans:=pdsolve(pde,ic,numeric,compile=true,time=u,range=0..1,'spacestep'=0.005);
ans:-plot([diff(f(u,x),x,u),color=cyan],u=3)
end proc:
K2(1+x^2-2*x^3);

That does not work.

I try to introduce a new variable h(u,x) = diff(f(u,x),x) so that I can plot h(u,x).
K3:=proc(g)
uses PDEtools,plots:
local pde, ic,ans;
pde:={h(u,x)=diff(f(u,x),x),
-4*x*diff(h(u,x),u)+4*diff(f(u,x),u)=x^4*diff(h(u,x),x)+x^3*h(u,x)+8*x^2*f(u,x)*(1-f(u,x)^2)};
ic:={f(u,0) = 1,f(u,1) = 0,f(0,x)=g};
ans:=pdsolve(pde,ic,numeric,compile=true,time=u,range=0..1,'spacestep'=0.005);
ans:-plot(h(u,x),u=3)
end proc:

K3(1-x^2);
Error, (in pdsolve/numeric/par_hyp) Incorrect number of initial conditions, expected 2, got 1

I have no idea what Maple is referring to; there are 3 initial conditions, not 1 or 2.

Anybody know what is going on? Any idea how to get what I need?

One more comment. I have never knowingly used a module in all the years I have been using and teaching Maple. I am sure there are good reasons for the construct but I think it would be difficult to teach. For ode's the result of dsolve is a procedure and it is relatively easy to teach because procedures are the bread and butter of using Maple. Why does pdsolve return a module?  I spent a good deal of time figuring out the use of pdsolve and would not like to force my students to do the same. I get them up to speed solving ode's using dsolve and DETools in a one hour lab. I wonder how much time it would take to do pdsolve.

 

Beware!

In Maple 2019 we get the strange value

cos((Pi/2) -1e-12);
                                                  -10
                       -2.051033808 10   

 



In Maple 2020 we get the correct answer

cos(Pi/2-1e-12);
                                                                      -13
                9.999999999996916397514419 10   

That error in Maple 2019 certainly messed up quite a few of my calcualtions!

 

 

 I want to compute a function W for certain values of x < π/2. W is a ratio of 2 positive values -they are squares-computed using dsolve and that ratio seems to be negative when evalf is applied to the answer.!!!  The true answer (without the evalf) are positive. Also, applying evalf to the correct answers does not produce those silly negative answers. Any suggestions? I would prefer uplaod my file but do not know how>

Here is the file:

This worksheet has a system of ode's ( a second order and a first order), a power series solution near 0 to use for inital conditions, and a function W of the vairables that I want to compute for certain values of x < π/2. W is a ratio of 2 positive values and that ratio seems to be negative when evalf is applied to the answer.!!! The true answer (without the evalf) are positive. Also, applying evalf to the correct answers does not produce those silly negative answers.

  • >  restart;

  • >  alias(B=b(x));alias(Bp=diff(b(x),x));alias(f=F(x));alias(fp=diff(F (x),x));alias(fpp=diff(F(x),x,x));

    B B, Bp

    B, Bp, f B, Bp, f, fp

    B, Bp, f, fp, fpp

  • >  eq1 := sin(x)*(1+B*cos(x)^2)*fpp-(2*((f^2-2*B)*cos(x)^2-f^2+3*B* (1/2)-1))*cos(x)*fp+2*sin(x)*((f^2-3*B*(1/2))*cos(x)^2-f^2+(1/2)* B-1/2)*f = 0;eq2 := (-B*cos(x)^6+(B-1)*cos(x)^4+cos(x)^2)*fp^2+2*f* cos(x)*sin(x)*(cos(x)-1)*(cos(x)+1)*(1+B*cos(x)^2)*fp+cos(x)*sin(x) *Bp+B*cos(x)^6*f^2-(2*(B-1/2))*f^2*cos(x)^4+B*cos(x)^2*f^2-f^2+B = 0;

    eq1 sinx 1 Bcosx2fpp 2 f2 2Bcosx2 f2 3B 1cosxfp 2

    2sinx f2 3B cosx2 f2 B 1 f=0 222

    eq2 Bcos x 6 B 1 cos x 4 cos x 2 fp2 2fcos x sin x cos x
    1 cosx 1 1 Bcosx2 fp cosx sinx Bp Bcosx6f2 2 B

    1 2

(1)

f2cos x 4 Bcos x 2f2 f2 B=0 > f2p:=solve(eq1,fpp);

f2p

(2)

(3)

1 2sin x f3cos x 2 sin x 1 Bcos x 2

2cos x 3fpf2
3sinx fBcosx2 4cosx3fpB 2sinx f3 2cosx fpf2 sinx fB

3cosx fpB sinx f 2cosx fp

  • >  fs:=x^8*(127/604800*C+653/17010*(C^5)+2/81*(C^7)+773/1020600*(C^3)) +x^6*(17/5670*(C^3)-4/81*(C^5)+31/15120*C)+x^4*((1/9)*C^3+7/360*C)+ (1/6)*x^2*C+C:

  • >  Bs:=x^6*(20/189*(C^4)+4/315*(C^2))+4*x^4*C^2*(1/45)+2*x^2*C^2*(1/3) :

  • >  Digits:=15:

  • >  ic:=(c)->{F(1e-5)=subs([x=1e-5,C=c],fs),D(F)(1e-5)=subs([x=1e-5,C= c],diff(fs,x)),b(1e-5)=subs([x=1e-5,C=c],Bs)}:

> nans:=dsolve({eq1,eq2} union ic(c),{f,B},numeric,stiff=true,

(4)

> parameters=[c]);

nans proc x_rosenbrock ... end proc

(4)

(5) (6)

> W:=fp^2*cos(x)/f^2;

W fp2 cos x f2

> Wp:=simplify(subs(fpp=f2p,diff(W,x)));

cosxsinx 1 Bcosx2fp2 f27Bcosx4 f25B3cosx2fpcosxf2

1

1
Wp f3sin x 1 Bcos x 2 4fp 2 f 4

444

3B cosx2 f2 B 1 f2sinx 222

  • >  k:='k': for k from 4 to 5 do nans(parameters=[k]); evalf(eval([W, Wp], nans(Pi/2-1e-10)),5); end do;

    c = 4.
    482.73, 1.3965 10
    8

    c = 5.
    5.6838 10
    6, 1.4948 1013

  • >  k:='k': for k from 4 to 5 do nans(parameters=[k]); eval([W,Wp],

    nans(Pi/2-1e-10)); end do;

    c = 4. 0.0131412243081803, 1.31416436948280 108

    c = 5.
    154.729383663460, 1.54702786932958 10
    12

  • >  evalf([0.0131412243081803, -1.31416436948280*10^8],5);

    0.013141, 1.3142 108

(7)

(8) (9)

 

The dsolve numeric events syntax requires the use of If(a,b,c) rather than the usual if then else syntax. Also, the possible action parts of an event are truly mysterious as are discrete variables. Has anyone plaed around with this much? For example, can the If's be nested? I know I can test that in a toy situation but there are many such questions that arise and I don't want to reinvent the wheel.

I frequently title my plots to identify what is being plotted. Very often that means specifying a parameter. For example, I might want the title to read;  Exponential when the power is c.

In the above I want to replace c with a real number. For example, my command might read

> for c from 1 to 10 do
p||c := plot( x^c, x= -1..1, title= the power is c )
end do:

I can then display the sequence of plots nicely labelled.

That does not work.

 

I cannot find adequate  info about what follows title =  in the help pages or the manual so I end up creating a worksheet and experimenting for quite a while until I find something that works.
(The Help page says: “The value t can be an arbitrary expression.” That’s it. One can go to the typesetting page to get more info about captions which is probably relevant but it begins to feel like learning about sex by looking up words in the dictionary.


BTW, I have been using Maple for 18+ years so I should have a cheat sheet somewhere to remind me of the correct syntax but I am suggesting that Maple would be much more user friendly if this info was in the help pages.

It would be very nice to have a fuller explanation with more examples.

Here is what works:


c:=3;  # special case

 

plot(x^c, x=-1..1,title=`power is `|| c);  Why back quotes?

or

cc:=convert(c,string);
plot(x^c,x=-1..1,title=[`power is `||cc]);   why barckets?

or not as nice
plot(x^c,x=-1..1,title=power.is.cc);  why dots?

or if you get rid of the is
plot(x^c,x=-1..1,title=[power = c]);  why noy use is?

 

not as nice
plot(x^c,x=-1..1,title=[power = cc]);  ugly quote marks

 

Here is a list of failures in this very simple case:

 

c:=3;

 

plot(x^c,x=-1..1,title="power is c");

 

plot(x^c,x=-1..1,title=power is c);

 

 

cc:="c";plot(x^c,x=-1..1,title="power is cc");
or

plot(x^c,x=-1..1,title=power is cc);


plot(x^c,x=-1..1,title=power.is.cc);

 

cc:=convert(c,string);plot(x^c,x=-1..1,title="power is cc");

 

cc:=convert(c,string);plot(x^c,x=-1..1,title="power is cc");

 

plot(x^c,x=-1..1,title='power is cc');

 

plot(x^c,x=-1..1,title=[power, is, cc]);

 

plot(x^c,x=-1..1,title='power = cc');

 

plot(x^c,x=-1..1,title=power = cc); but plot(x^2,x=-1..1,title=[power = cc]);is acceptable

another couple of failures:

plot(x^c,x=-1..1,title=[`power is c`]);

 

plot(x^c,x=-1..1,title=[`power is cc`]);

 

 

1 2 3 4 5 6 7 Last Page 2 of 10