Preben Alsholm

MaplePrimes Activity


These are answers submitted by Preben Alsholm

Here are two ways:
 

restart;
X:=<$0..20>;
Y:=sin~(X);
X1:=<seq(i,i=0..10,0.5)>;
Y1:=cos~(X1);
p:=plot(X,Y); 
p1:=plot(X1,Y1,color=blue); 
plots:-display(p,p1);
## An attractive alternative:
plot([<X|Y>,<X1|Y1>],color=["DarkRed","DarkGreen"],thickness=3,linestyle=[1,3]);

 

You could use subsop:
 

## Notice first the structure:
lprint(expr);
## Physics:-`*`(sigma__y,sigma__x,rho)-Physics:-`*`(sigma__y,rho,sigma__x)
## So
res:=subsop([1,1]=H,[1,2]=1,expr);
lprint(res);
## Result: Physics:-`*`(H,rho)-Physics:-`*`(sigma__y,rho,sigma__x)

 

An alternative to DEplot is odeplot as used here.
I do use DEplot for the direction field though.
MaplePrimes21-10-22_ode_phseplot.mw

One of the images:

plots:-implicitplot(abs(x+2)+abs(y)=3,x=-5..1,y=-3..3);
plots:-implicitplot(abs(y)-abs(x)=2,x=-3..3,y=-5..5);

 

Since this integral appears numerically nontrivial I tried using dsolve/numeric instead of evalf/int.
The result for the real part found below is -0.0513608600887187 (too many digits surely).

MaplePrimes21-10-19_int_by_dsolve.mw
 

restart;

Digits:=15:  #

W := -16*(x - 1/2)*x*(t + 2*w)*(ln((m^2 + w*x*(-1 + x))/m^2)*ln(-1/(w*(t + w)*x^2 - w*(t + w)*x + m^2*t)) + ln(-x*w^2*(-1 + x))*ln((x^2 - x)*w + m^2) + ln(1/m^2)*ln((t + w)*(-1 + x)) + ln(-1/(x*w))*ln(m^2) + dilog(x*w^2*(-1 + x)/(w*(t + w)*x^2 - w*(t + w)*x + m^2*t)) - dilog(x*w*(-1 + x)*(t + w)/(w*(t + w)*x^2 - w*(t + w)*x + m^2*t)))/t^3 + 8*(x - 1/2)*((t + w)*x - t/2)*(-t*(w*x^2 + m^2 - w*x)*(t + w)*ln((x^2 - x)*w + m^2) + w*(x*w*(-1 + x)*(t + w)*ln((t + w)/w) + m^2*t*ln(m^2)))*(2*w*x + t)/(w*(t + w)*(w*(t + w)*x^2 - w*(t + w)*x + m^2*t)*t^3*x) + (16*x^2 - 8*x)/(t*w*(-1 + x)) + (2*t*x + 2*w*x - t - 2*w)*(2*w*x + t - 2*w)*(1 - 2*x)*ln((t*x + (-1 + x)*w)/((-1 + x)*w))/(((-1 + x)^2*w^2 + w*t*x*(-1 + x) + m^2*t)*t^2) + (-1 + 2*x)*(2*m^2 + w*x - w)*(2*w*x^2 + 2*m^2 - 3*w*x + w)*ln(m^2/(m^2 + w*x*(-1 + x)))/(w^2*(-1 + x)^2*((-1 + x)^2*w^2 + w*t*x*(-1 + x) + m^2*t)) + (-1 + 2*x)*(2*m^2 + w*x - w)*(2*w*x^2 + 2*m^2 - 3*w*x + w)*ln(m^2/(m^2 + w*x*(-1 + x)))/(w^2*(-1 + x)^2*(w*(t + w)*x^2 - w*(t + w)*x + m^2*t)) + (2*w*x + t)*((t + w)*x - t/2)*(x - 1/2)*ln(w^4/(t + w)^4)/(t^2*(w*(t + w)*x^2 - w*(t + w)*x + m^2*t)) - 8*(x - 1/2)*((-2 + 2*x)*w + t)*((-1 + x)*w + (x - 1/2)*t)*((t*x + (-1 + x)*w)*w^2*(-1 + x)^2*ln((t*x + (-1 + x)*w)/((-1 + x)*w)) + (-(t*x + (-1 + x)*w)*((x^2 - x)*w + m^2)*ln((x^2 - x)*w + m^2) + ln(m^2)*m^2*w*(-1 + x))*t)/((t*x + (-1 + x)*w)*w*(-1 + x)*t^3*((-1 + x)^2*w^2 + w*t*x*(-1 + x) + m^2*t)) + 16*(x - 1/2)*(ln(1/m^2)*ln((t*x + (-1 + x)*w)*(-1 + x)*w/((-1 + x)^2*w^2 + w*t*x*(-1 + x) + m^2*t)) + ln((x^2 - x)*w + m^2)*ln(1/((-1 + x)^2*w^2 + w*t*x*(-1 + x) + m^2*t)) + ln((-1 + x)^2*w^2)*ln((x^2 - x)*w + m^2) - dilog((t*x + (-1 + x)*w)*(-1 + x)*w/((-1 + x)^2*w^2 + w*t*x*(-1 + x) + m^2*t)) + dilog((-1 + x)^2*w^2/((-1 + x)^2*w^2 + w*t*x*(-1 + x) + m^2*t)))*(t*x + 2*(-1 + x)*w)/t^3:

Wf:=unapply(W,m,s,t,w): # W as a function of (m,s,t,w), not x

singular(Wf(1,3,-2,-1),0..1);

# With f(x) = Wf(1,3,-2,-1) we split:

IntegrationTools:-Split(Int(f(x),x=0..1),[1/10,1/3,2/3]);

ode:=diff(u(x),x)=Re(Wf(1,3,-2,-1)):

# Using nonsingular initial points x0 = 1/10 and x0 = 2/3

res:=dsolve({ode,u(x0)=0},numeric,parameters=[x0],abserr=1e-15,relerr=5e-10);

# In res Int(f(x),x=x0..x) is computed.

res(parameters=[1/10]);  # setting initial point x0=1/10

v1:=subs(res(1/3),u(x)); # Int(f(x), x = 1/10 .. 1/3)

v2:=subs(res(0),u(x));   # -Int(f(x), x = 0 .. 1/10)

res(parameters=[2/3]);   # setting initial point x0=2/3

v3:=subs(res(1),u(x));   # Int(f(x), x = 2/3 .. 1)

v4:=subs(res(1/3),u(x)); # -Int(f(x), x = 1/3 .. 2/3)

val:=v1-v2+v3-v4;        # -0.0513608600887187

Int(f(x),x=0..1) = val;

 


 

Download MaplePrimes21-10-19_int_by_dsolve.mw

 

It appears that the fact that a is assigned to 1.4 makes a difference to seq. Try using another index:
 

seq([g(i, x[0], y[0])], i = 0 .. 3); # i instead of a

P.S.

The real reason is that the index 'a' also appears in the definition of f:
 

f := (n, m) -> (-n^2 + b*m + a, n);

It is OK that a is assigned as far as seq is concerned, but that 'a' appears in f is the problem.

Since your piecewise expression begins with
 

piecewise(t < t1, kmax, t1 <= t, -kmax, ...)

and since we must either have t < t1 or t1 <= t, the rest of the expression is never used.
P.S. Before thinking about integrating you should try plotting your expression.
Just pick kmax to be e.g. 1 and try different values of t1. Then you will be able to see if you are getting the step function you intended.

A little experimentation:
 

k := piecewise(t < t1, kmax, t1 <= t, -kmax, 2*t1 + sqrt(2)*t1 <= t, kmax, 3*t1 + 2*sqrt(2)*t1 <= t, -kmax, 4*t1 + 2*sqrt(2)*t1 <= t, 0);
plot(eval(k,{kmax=1,t1=2}),t=-10..10);
plots:-animate(plot,[eval(k,{kmax=1}),t=-10..10],t1=-5..5);
## Maybe this is the ordering that you want (?):
k2 := piecewise(2*t1 + sqrt(2)*t1 <= t, kmax, 3*t1 + 2*sqrt(2)*t1 <= t, -kmax, 4*t1 + 2*sqrt(2)*t1 <= t, 0,t < t1, kmax, t1 <= t, -kmax);
plot(eval(k2,{kmax=1,t1=2}),t=-10..10);
plots:-animate(plot,[eval(k2,{kmax=1}),t=-20..20],t1=-5..5,frames=100);

You may also try this:
 

int(eval(k,t1=2), [t = 0 .. t, t = 0 .. t, t = 0 .. t, t = 0 .. t]);
int(eval(k2,t1=2), [t = 0 .. t, t = 0 .. t, t = 0 .. t, t = 0 .. t]);

And finally this:
 

int(k2, [t = 0 .. t, t = 0 .. t, t = 0 .. t, t = 0 .. t]) assuming t1>0,t>0;

 

Would this be OK:

 

Explore(plot(a*x^2+b*x^3,x=-2..2,caption=typeset("a^2+b^2 = ",a^2+b^2)),
parameters = [a = -1.00..1.00, b=-1.00..1.00],placement=right );

 

You need a new license for each new version of Maple. Updates to a given version are characterised by decimal points as in "Maple 2021.1", which is the first update of "Maple 2021". Updates are free, new versions are not. Somebody, you or e.g. your university must pay for it.

If you get an error running a worksheet made for a later version than yours, you could post the worksheet here, then someone will most likely be able to help.

Use the fat green uparrow in the editor to attach the worksheet.

If you specify theta then you can in some cases get a formula for the solution as also vv is pointing out.

restart;
# Let A=-P-beta*S+alpha1-alpha2  and N1 = N+1 for simplicity.
ic1 := q(T) = 0;
ode1 := diff(q(t), t) + theta*q(t)/(N1 - t) = A - beta2*q(t);
sol1:=dsolve({ode1,ic1});
# Example:
eval(sol1,theta=1);
value(%) assuming t<N1,T<t;
# Making it easier to input other values of theta:
R:=proc(theta1) local val:=eval(sol1,theta=theta1);
   value(val) assuming t>T, t<N1;
end proc;
R(1/2);
R(1);
R(3/2);
R(2);
R(-1);
R(-1/2);

In unsuccessful cases you can solve numerically, either the integral or by using dsolve/numeric (the latter preferable in my view)

You will need an extra tilde:
 

10^~(pH-~pK);

PS. You don't need a tilde when multiplying a vector by a scalar. You can just use the ordinary multiplication * as in

pCO2*0.03;

 

I checked with one much older version Maple 12 as well as with Maple 2021.1.

As far as the display of the leading minus is concerned the behavior is the same.
Observe the output from this code:
 

restart;
t__FET_TurnOff := solve(-C__iss2*V__gs_th2 + Q__total = i__GateDriveN*t__off, t__off);

numer(t__FET_TurnOff);
denom(t__FET_TurnOff);
%%/%;
(numer/denom)(t__FET_TurnOff); 

 

To show numerical evidence of convergence of solutions to a single (periodic) solution try this:
 

restart;
ode:=diff(x(t),t)=-(1+1/10*sin(10*t))*x(t)+1;
res:=dsolve({ode,x(t0)=x0},numeric,parameters=[t0,x0]);
res(parameters=[0,1]); #setting parameters
plots:-odeplot(res,[t,x(t)],t=0..20,size=[1200,default],numpoints=5000); p1:=%:
res(parameters=[0,2]);
plots:-odeplot(res,[t,x(t)],t=0..20,size=[1200,default],numpoints=5000,color=blue,view=0.9..1.1); p2:=%:
plots:-display(p1,p2);
res(parameters=[0,-1]);
plots:-odeplot(res,[t,x(t)],t=0..20,size=[1200,default],numpoints=5000,color=cyan,view=0.9..1.1); p3:=%:
plots:-display(p1,p2,p3);
res(parameters=[2,-1]);
plots:-odeplot(res,[t,x(t)],t=0..20,size=[1200,default],numpoints=5000,color="Green",view=0.9..1.1); p4:=%:
plots:-display(p1,p2,p3,p4);
plots:-display(p1,plot(sin(10*t+1.7)/100+1,t=0..20,color=blue));
Q:=proc(t0,x0,{range::range:=0..10,numpoints::posint:=5000,size::[posint,posint]:=[1200,default]}) if not [t0,x0]::list(realcons) then return 'procname'(_passed) end if;
   res(parameters=[t0,x0]);
   plots:-odeplot(res,[t,x(t)],range,:-numpoints=numpoints,:-size=size,_rest)
end proc;
Q(0,2,range=0..20,view=0.9..1.1);
plots:-animate(Q,[0,x0],x0=-2..3,trace=24,view=0.9..1.1,size=[1200,400]);

The animation at the end:

Your ode is very similar to the one in https://mapleprimes.com/questions/232633-How-To-Solve-Nonlinear-Ode-With-Numeric-Method

to which I responded. Your ode can similarly be integrated once to result in
 

ode := delta*diff(u(y), y)^3 + diff(u(y), y) = p*y

where use of D(u)(0) = 0 has already been done. Proceeding as in the link in this case leads first to 3 odes, but 2 of these can be eliminated since they don't satisfy D(u)(0) = 0 ( assuming delta>0).
The remaining is

diff(u(y), y) = 1/6*12^(1/3)*((9*p*y*sqrt(delta) + sqrt(27*delta*p^2*y^2 + 4)*sqrt(3))^(2/3) - 12^(1/3))/(sqrt(delta)*(9*p*y*sqrt(delta) + sqrt(27*delta*p^2*y^2 + 4)*sqrt(3))^(1/3))

Which leads to the solution by direct integration using that u(k) =1:
 

u(y) = Int(1/6*(2*18^(1/3)*((9*p*_z1*sqrt(delta) + sqrt(81*_z1^2*delta*p^2 + 12))^2)^(1/3) - 12)/(sqrt(delta)*(108*p*_z1*sqrt(delta) + 12*sqrt(81*_z1^2*delta*p^2 + 12))^(1/3)), _z1 = k .. y) + 1

Unfortunately this integral cannot be done symbolically unlike the case considered in the link.

I know you want ode solved numerically and also by a shooting method.

Here though, I shall point out that your ode bvp can be solved exactly.

## Your worksheet has a syntactical error in bc:  You have D*u(0) where it should be D(u)(0).

restart;
#p:=2:
ode := diff(u(y), y, y) + beta*diff(diff(u(y), y)^2, y) = p;
bcs:=D(u)(0)=0,u(h)=1;
odeC:=map(int,ode,y)+(0=C);
eval[recurse](convert(odeC,D),{bcs[1],y=0});
ode1:=eval(odeC,C=0);
solve(ode1,{diff(u(y),y)});
odes:=op~([%]);
eval[recurse](convert(odes,D),{y=0,bcs[1]});
# So only odes[1] satisfies bcs[1]
sol1:=dsolve({odes[1],u(h)=1});
# Dealing with the original second order ode:
sol:=dsolve({ode,bcs});
simplify(sol-sol1); # OK

For a numerical solution you also need to provide a numerial value for h.

I don't see how you can do shooting on the first order ode (odes[1])  which already satisfies D(u)(0)=0.
But obviously you can use a numerical method as in the following:
 

p:=2;
res:=dsolve({odes[1],u(h)=1},numeric,parameters=[beta,h],abserr=1e-12,relerr=1e-9);
res(parameters=[beta=1/8,h=3]);
plots:-odeplot(res,[y,u(y)],0..3);
plots:-odeplot(res,[y,u(y)-eval(rhs(sol1),{beta=1/8,h=3})],0..3);#plot of error

Very good agreement between the exact and numerical solutions for h=3, beta=1/8.

######### In a reply below I have added a link to an expanded version of the code above.

It includes conversion of the given ode to a traditional system of 2 odes and has also been solved by shooting for that system.

First 7 8 9 10 11 12 13 Last Page 9 of 160