Preben Alsholm

MaplePrimes Activity


These are answers submitted by Preben Alsholm

Add this as the last argument to polarplot:
coordinateview = [0 .. 1, default]

You could do either one of these instead.  (a third and better way at bottom).
 

restart;
eq:=P=A+(z+x/2/z);
(rhs=lhs)(-(isolate(eq,A)-P));
restart;
eq2:=P=A+``(z+x/2/z); # Notice `` 
isolate(eq2,``(z+x/2/z));
expand(%);

PS. Notice that the help page for isolate indeed does say:

"The procedure isolate attempts to isolate the second argument expr in the first argument eqn and solves eqn for expr."
here expr is "any algebraic expression".
That is rather vague.
But look at the examples on the help page. In all cases expr is an actual operand of one of the sides of the equation.
In your case (z+x/2/z) is not an operand of P=A+(z+x/2/z).
Notice the output when you define the equation: The panthesis is gone:
 

restart;
eq:=P=A+(z+x/2/z);
op(rhs(eq));

Answer: A, z, 1/2*x/z.
Thus a third way around this would be:
 

isolate(eq,x/z/2) + z;

 

I made a few changes. The main one is that I don't in fact ever assign to S.
In any case you should wait with that until the symbolic computations are over.

I make 'solution' into a procedure, but that is just for ease of comparison of results for the exact 1 and the float 1., which is the point of all this.

restart;
Digits:=15:
#S:=1; # Don't assign to S
F:=add((q^i)*f[i](eta),i=0..16);

eqa:=simplify(diff(F,eta,eta,eta)+(q*g*((F*diff(F,eta,eta))-((diff(F,eta))*(diff(F,eta)))-(S*diff(F,eta))-(((S*eta)/2)*diff(F,eta,eta))))):
f[0](eta):=(alpha/2)*eta^2+eta:

for m from 1 to 8 do eq[m]:=coeff(eqa,q^m) end do:
for m from 1 to 8 do (simplify(int(int(int(((-1)*eq[m]),eta),eta),eta)+f[m](eta))):f[m](eta):=simplify(%) end do:

a1:=simplify(add(f[n](eta),n=0..8)):
b1:=simplify(subs(eta=1,a1))=(S/2):b2:=simplify(subs(eta=1,diff(a1,eta,eta)))=0:
sys:={b1,b2}:

solution:=s->fsolve(eval(sys,S=s));

AG_vals:=[solution(1),solution(1.)]; # (Almost) exactly the same
c1E:=eval(a1,AG_vals[1] union {S=1});
c1F:=eval(a1,AG_vals[2] union {S=1.});
simplify(c1E-c1F);
c2E:=diff(c1E,eta,eta): c3E:=subs(eta=0,c2E);
c2F:=diff(c1F,eta,eta): c3F:=subs(eta=0,c2F);
c3E-c3F; # -2.*10^(-14)

You will see that the difference between c3E and c3F is definitely acceptable since Digits = 15.
If you also try this:
 

fnormal(simplify(c1E-c1F));

you will find 0. fnormal removes small terms. See the help for fnormal.

Try this:
 

plots:-implicitplot(S_TEV-S_P=0,E = 0 .. 500000, T = 0 .. 15);

@RLessard Thanks for the screenshot. That convinces me that indeed it was looking as you want it.

That I couldn't remember seeing that ever can be explained as a combination of my old age and the fact that I almost never used Greek letters as formal arguments: They are too long and what is the point?
Anyway, try this in your more recent Maple versions:
 

p:=(alpha,beta)->alpha+beta;

I'm using Maple 2021.2 on this computer and the printing of the procedure p uses Greek characters.
Because of the options operator,arrow the following is printed exactly the same:

q:=proc(alpha,beta) option operator,arrow;  alpha+beta;  end proc;

In Maple 2021.2 (at least) also these versions having a local work: as you want
 

q1:=proc(alpha,beta) option operator,arrow; local b;
   b:=7;
    b*(alpha+beta);  
end proc;
q1(1,2);
q2:=(alpha,beta)-> local b:=7; b*(alpha+beta);
q2(1,2);

In Maple 12 q2 doesn't work. It may not work in your versions because the syntax
(alpha,beta)-> local b:=7; b*(alpha+beta);
was introduced in a rather recent release.

PS. Somewhat late I paid attention to your point about saving the worksheet and opening it again.
If you save with output (I very rarely do) then indeed the Greek characters are there.

You most likely don't really like to see the steps Maple is actually taking. Take a look at this:
 

int(2/(1-x^p)^(1/p), x=0..1,method=_RETURNVERBOSE);

The answer is:
[meijerg = 2*Pi/(p*sin(Pi/p)), FAILS = (distribution, piecewise, series, o, polynomial, ln, lookup, cook, ratpoly, elliptic, elliptictrig, meijergspecial, improper, asymptotic, ftoc, ftocms, contour)]
which means that the only successful method open to int is method = meijerg.

You need 3 members in your scene. Use DEplot3d.
 

restart;
mu := 1/(365*80);
alpha := 20;
psi := 100;
varphi := 2;
K := 100;
theta := 0.5;
sigma := 0.001;

with(DEtools):
with(PDEtools):
beta := 0.3;
des := diff(S(t), t) = (psi + mu)*K - beta*S(t)*In(t) - (mu + varphi + psi)*S(t) + (theta - psi)*V(t) - psi*In(t), diff(V(t), t) = varphi*S(t) - sigma*beta*In(t)*V(t) - (mu + theta)*V(t), diff(In(t), t) = beta*S(t)*In(t) + sigma*beta*In(t)*V(t) - (mu + alpha)*In(t);

#scene = [S(t),V(t), In(t)]:
DEplot3d([des], [S(t), V(t), In(t)], t = 0 .. 100, [[S(0) = 70, V(0) = 0, In(0) = 30]], V = 0 .. 100, In = 0 .. 100, stepsize = 0.05, arrows = medium, scene = [S(t),V(t), In(t)], linecolour = sin(t*Pi/2));

 

The output from the first is L. I think you want NULL, because you are just making a global change on L:

f:=proc(Z)
   global L;  
   #do some processing on Z, then collect it into list L
   L:=[ op(L), Z^2];
   #print("op(L) = ",op(L)," Z=",Z); 
   NULL;  
end proc;

I removed the question. It clearly appeared to be a repost and was even titled as such. Therefore I deleted the question.

Further questions to a given thread should be given in that thread, not in a new one.

I believe that only the editor of MaplePrimes can restore that question.
Indeed, in your present question you yourself realized that it was a repost of:
https://www.mapleprimes.com/questions/233262-How-Do-I-Solve-Error-in-Dsolvenumericbvpconvertsys

I prefer using dsolve combined with odeplot as shown in the code:

restart;
#k^2*alpha+omega = kao
#K^2*(gamma+alpha)= Kga
f:=(u,z)->z;
g:=(u,z)->kao*u/Kga-beta*u^3/Kga; # You had a wrong sign on the second term
E:=solve({f(u,z)=0,g(u,z)=0},{u,z},explicit);
e1,e2,e3:=op(map(subs,[E],[u,z]));
sys:=diff(u(xi),xi)=f(u(xi),z(xi)), diff(z(xi),xi)=g(u(xi),z(xi));
res:=dsolve({sys,u(0)=u0,z(0)=z0},numeric,parameters=[u0,z0,kao,Kga,beta]);
res(parameters=[0,0.01,.1,.2,1]);
eval([e2,e3],{kao=0.1,Kga=.2,beta=1});
plots:-odeplot(res,[u(xi),z(xi)],0..40,numpoints=10000);
res(parameters=[0,0.1,-.1,-.2,1]);
eval([e2,e3],{kao=-0.1,Kga=-.2,beta=1});
plots:-odeplot(res,[u(xi),z(xi)],-3..3,numpoints=10000); p1:=%:
res(parameters=[0,-0.1,-.1,-.2,1]);
plots:-odeplot(res,[u(xi),z(xi)],-3..3,numpoints=10000,color=blue); p2:=%:
plots:-display(p1,p2);

The first plot:

You may want to have a look at your system etc. again, though.

I corrected several things. Feel free to ask questions about the solution.
Besides technical matters (Maple matters) I found it reasonable to replace de1 by ode1 as seen below.
 

restart;

de1 := (1 - p)*(diff(x(t), t $ 1) - r*x(t)) + p*(diff(x(t), t $ 1) - r*(1 - (x(t) + y(t))/K) + al*x(t)*v(t));

de2 := (1 - p)*(diff(y(t), t $ 1) + m*y(t)+u*y(t)) + p*(diff(y(t), t $ 1) - al*x(t)*v(t) + m*y(t)+u*y(t));

de3 := (1 - p)*(diff(v(t), t $ 1) + eta*v(t)) + p*(diff(v(t), t $ 1) - B*y(t) + eta*v(t));

ibvc := x(0) = 0.005, y(0) = 0.0007, v(0) = 2;


sys1:=eval([de1,de2,de3],p=1);
sys0:=eval~(sys1,[{y=0,v=0},{x=0,v=0},{x=0,y=0}]);
sys_p:=(1-p)*~sys0+~p*~sys1;
ode1,ode2,ode3:=seq(sys_p[j],j=1..3);
ode1; # replaces de1
de1;
ode2; # = de2
de2;
ode3; # = de3
de3;
r:=0.005; al:=0.002; m:=0.0001; K:=0.0138; B:=0.2; eta:=0.006; u:=0.0001;
n := 4;
############First using dsolve directly (numerically)
res:=dsolve({ode1,ode2,ode3,ibvc},numeric,parameters=[p]);
Q:=proc(p,{scene::list:=[t,x(t)],range::range:=0..100}) if not p::realcons then return 'procname(_passed)' end if;
   res(parameters=[p]);
   plots:-odeplot(res,scene,range,_rest)
end proc;
Q(0.5,color=blue);
Q(0.5,scene=[x(t),y(t),v(t)]);
plots:-animate(Q,[p,range=0..50],p=0..1,trace=24);
plots:-animate(Q,[p,range=0..30,scene=[x(t),y(t),v(t)]],p=0..1,trace=24);
############### Now perturbation:
X := unapply(add(g[k](t)*p^k, k = 0 .. n), t);

Y := unapply(add(h[k](t)*p^k, k = 0 .. n), t);

V := unapply(add(i[k](t)*p^k, k = 0 .. n),t);


DE1 := series(eval(ode1, {x = X,y=Y,v=V}), p = 0, n + 1);

DE2 := series(eval(ode2, {x = X,y=Y,v=V}), p = 0, n + 1);

DE3 := series(eval(ode3, {x = X,y=Y,v=V}), p = 0, n + 1);


##### Initial conditions:
M:=eval(([ibvc]), {x(0) = X(0),y(0)=Y(0),v(0)=V(0)});
M0:=eval(M,p=0);
M1,M2,M3,M4:=seq([g[j],h[j],i[j]](0)=~0,j=1..n);  # n=4
ICS:=M0,M1,M2,M3,M4;
###### Now the loop:
g:='g': h:='h': i:='i': # if you do the loop below again you need this. Do it in any case.
for k from 0 to n do

    IBVC1 := select(has,ICS[k+1],g[k]);

    IBVC2 := select(has,ICS[k+1],h[k]);

    IBVC3 := select(has,ICS[k+1],i[k]);

    s1 := dsolve({coeff(DE1, p, k), op(IBVC1)});

    s2 := dsolve({coeff(DE2, p, k), op(IBVC2)});

    s3 := dsolve({coeff(DE3, p, k), op(IBVC3)});

    g[k] := unapply(value(rhs(s1)), t); # value is used because an inert interval may appear

    h[k] := unapply(value(rhs(s2)), t);

    i[k] := unapply(value(rhs(s3)), t);

end do:


'X(t)' = X(t) + O(p^(n + 1));

'Y(t)' = Y(t) + O(p^(n + 1));

'V(t)' = V(t) + O(p^(n + 1));
######## plot tests:
plot(eval(X(t),p=1),t=0..100);
plots:-display(plot(eval(X(t),p=1),t=0..100),Q(1,color=blue,linestyle=3));
Q(1,scene=[t,x(t)-eval(X(t),p=1)],caption="The difference between X(t) and the numerically computed result");
# Do similarly for Y and V

MaplePrimes2021-11-24_perturbation_homotopy.mw

Use unapply instead to define y:
 

restart;
with(inttrans):
y := unapply(invlaplace(exp(-s)/s, s, t),t);
y(t-1);
y(t-1.1);

 

In order to get an answer from your first use of dsolve, where d1,d2,d3,d4, and d5 are not yet assigned, you need assumptions:
 

restart;
eq := diff(Uy(x), x, x) - piecewise(x < d1, 12*F*x/(E*b*h^3), d1 < x and x < d2, 12*((F + F1)*x - F1*d1)/(E*b*h^3), d2 < x and x < d3, 12*((F + F1 + F2)*x - F1*d1 - F2*d2)/(E*b*h^3), d3 < x and x < d4, 12*((F5 + F4 - F)*x + F*L - F5*d5 - F4*d4)/(E*b*h^3), d4 < x and x < d5, 12*((F5 - F)*x + F*L - F5*d5)/(E*b*h^3), 12*F*(L - x)/(E*b*h^3));
sol:=dsolve({eq, Uy(0) = 0, Uy(L) = 0}) assuming d1<d2,d2<d3,d3<d4,d4<d5;
sol:=value(sol) assuming d1<d2,d2<d3,d3<d4,d4<d5;

 

I also use Windows 10. I got the error both times though. No result.
But then I tried replacing integrand with

integrand2:=simplify(integrand);
and I got
ln(x)/x - 1/3*(9*exp(2)*x - 30*x^2 + 18*exp(2) - 236*x - 450)/((-25 + exp(2) - 5*x)*(x + 3)*x)

both times.

 

interface(version);

`Standard Worksheet Interface, Maple 2021.1, Windows 10, May 19 2021 Build ID 1539851`

Physics:-Version();

`The "Physics Updates" version in the MapleCloud is 1112. The version installed in this computer is 1069 created 2021, September 26, 10:58 hours Pacific Time, found in the directory C:\Users\pkals\maple\toolbox\2021\Physics Updates\lib\`

restart;

integrand:=(((-3*x^2-18*x-27)*exp(2)^2+(30*x^3+330*x^2+1170*x+1350)*exp(2)-75*x^4-1200*x^3-7050*x^2-18000*x-16875)*ln(x)+(12*x^2+54*x+81)*exp(2)^2+(-120*x^3-1106*x^2-3510*x-4050)*exp(2)+225*x^4+3560*x^3+20990*x^2+54000*x+50625)/((3*x^4+18*x^3+27*x^2)*exp(2)^2+(-30*x^5-330*x^4-1170*x^3-1350*x^2)*exp(2)+75*x^6+1200*x^5+7050*x^4+18000*x^3+16875*x^2);

(((-3*x^2-18*x-27)*(exp(2))^2+(30*x^3+330*x^2+1170*x+1350)*exp(2)-75*x^4-1200*x^3-7050*x^2-18000*x-16875)*ln(x)+(12*x^2+54*x+81)*(exp(2))^2+(-120*x^3-1106*x^2-3510*x-4050)*exp(2)+225*x^4+3560*x^3+20990*x^2+54000*x+50625)/((3*x^4+18*x^3+27*x^2)*(exp(2))^2+(-30*x^5-330*x^4-1170*x^3-1350*x^2)*exp(2)+75*x^6+1200*x^5+7050*x^4+18000*x^3+16875*x^2)

integrand2:=simplify(integrand);

(1/75)*(-75*(x+3)^2*((-(2/5)*x-2)*exp(2)+x^2+10*x+(1/25)*exp(4)+25)*ln(x)+(-120*x^3-1106*x^2-3510*x-4050)*exp(2)+(12*x^2+54*x+81)*exp(4)+225*x^4+3560*x^3+20990*x^2+54000*x+50625)/((x+3)^2*((-(2/5)*x-2)*exp(2)+x^2+10*x+(1/25)*exp(4)+25)*x^2)

print("First time");
int(integrand2,x);

print("second time");
int(integrand2,x);
 

"First time"

ln(x)/x-(1/3)*(9*exp(2)*x-30*x^2+18*exp(2)-236*x-450)/((-25+exp(2)-5*x)*(x+3)*x)

"second time"

ln(x)/x-(1/3)*(9*exp(2)*x-30*x^2+18*exp(2)-236*x-450)/((-25+exp(2)-5*x)*(x+3)*x)

 


 

Download issue_int_nov_11_2021_by_nm.mw

I can add that if I continue after the computation above with integrand instead of integrand2 then I get no errors either time. The answer using integrand has a different form though:
ln(x)/x + 1/x + (15*x^2 + (-4*exp(2) + 356/3)*x - 9*exp(2) + 225)/(x*(x + 3)*(-25 + exp(2) - 5*x))
But the difference between the two answers simplies to 0.

Note: In my original answer I used the two arguments for numboccur in the wrong order. I mistakenly used the same order as used by ListTools:-Occurrences. This was pointed out by Carl Love.
So my answer below has been edited accordingly.
####

Using ListTools:-Occurrences on a list L, a vector V (rtable), and a set all having floating point elements can give quite different results.
I use the example by vv: L:=[1., HFloat(1.), 1., 0., 0.].
The results for the set should of course be expected to differ from the results for the list and the vector.

restart;
#showstat(ListTools:-Occurrences);
L:=[1., HFloat(1.), 1., 0., 0.];
V:=Vector(L);
S:={L[]};
ListTools:-Occurrences~(1.,[L,V,S]);                          #[2, 3, 1]
ListTools:-Occurrences~(HFloat(1.),[L,V,S]);                  #[1, 3, 1]
ListTools:-Occurrences~(1,[L,V,S]);                           #[0, 3, 0]
ListTools:-Occurrences~(1.,[L,V,S],evalb@`=`);                #[3, 2, 2]
ListTools:-Occurrences~(HFloat(1.),[L,V,S],evalb@`=`);        #[3, 2, 2]
ListTools:-Occurrences~(1,[L,V,S],evalb@`=`);                 #[3, 2, 2]
numboccur~([L,V,S],1.);              #[2, 2, 1]
numboccur~([L,V,S],HFloat(1.));      #[1, 1, 1]
numboccur~([L,V,S],1);               #[0, 0, 0]
First 6 7 8 9 10 11 12 Last Page 8 of 160