Preben Alsholm

MaplePrimes Activity


These are replies submitted by Preben Alsholm

As Rouben points out, there is nothing wrong.

I can produce the same error by moving the local declaration:

game := proc()
  #local player1, player2, roll;
  roll := rand( 1..6 );
  local player1, player2, roll;
  player1 := roll():
  player2 := roll(2):
  if player1>player2 then "A wins"
  elif player1=player2 then "Tie"
  else "B wins"
  end if;
end proc:

I think you ought to reveal some more of what you are doing. I sure don't understand it.

@patient Changing variable can be done with dchange from the PDEtools package:

SYS:=PDEtools:-dchange({z=x^2*1/t,u(z)=U(x),v(z)=V(x)},sys,[x,U,V]);
#I just check that the DAE method will work:
solve({SYS[1],diff(SYS[2],x)},{diff(V(x),x,x),diff(U(x),x)});
#Remember that the initial conditions have to satisfy this equation:
SYS[2];
ICS:={U(0.1)=1,V(0.1)=1,D(V)(0.1)=0}; #Just an example.
res:=dsolve(SYS union ics, numeric,method=rkf45_dae,parameters=[t]);
res(parameters=[-1]); #Setting paramer t to -1
plots:-odeplot(res,[[x,U(x)],[x,V(x)]],0.001..3);
#Experimenting with animation in t with the given initial conditions:
p:=proc(t) res(parameters=[t]); plots:-odeplot(res,[[x,U(x)],[x,V(x)]],0.001..3) end proc;
plots:-animate(p,[t],t=-1..-0.01);

@emmantop OK. The reason I asked was that D has a very special meaning in Maple (as you know: you used it in your worksheet). So it is better to use some other symbol for the sake of clarity.

@escorpsy There is no difference between diff(A(r),r)^2 and (diff(A(r),r))^2 . In other words, the outer parenthesis in the latter is superfluous.

Your system PDE only has derivatives w.r.t. y, thus it is an ode system.

Your IBCs contains the equation

 (D[1](phi))(R(z)/R[0]) = R[0]*delta/(D*phi[w])

What is (D*phi[w]) meant to be?

@escorpsy Maybe I misunderstood the meaning of your term "test solution". I thought that you knew (or thought) that the functions given in puta made up a solution to your ode.
If puta was a solution then odetest should return {0}.

I fail to see the connection between the original ode and the rest of the code.

Your first order system would be
y'(t) = u(t)
u'(t) = -3*u(t)-2*y(t) + cos(t)

Just one indication of the missing connection: Where is cos(t) in the code?

@surnizai The range was chosen to include the result of fsolve(x*y1,x) which I actually did before I plotted.

From the plot I could see that there was (at least) one more zero and that one was near x=1+I*epsilon. So giving x=1 as a start to fsolve might get us the second roots. It did!

@patient I noticed that you changed both of the equations so you have to think again. I shall be busy with travelling the next few days so won't have time to look at it.

@matmxhu I tried the following. When doing it several times the error was successfully caught some of the time and sometimes not:

restart;
g:=proc() solve(exp(x)=1,x) end proc:
try
 timelimit(0.02, g());
catch "time expired":
 123456789
end try;

I don't know why the error is not caught all the time.
This was done in Maple 2015.
I tried in Maple 15 several times. The error was caught every time I tried.
In Maple 16, 17, and 18 the error was caught sometimes and sometimes not.

With the following code the error was caught all the times I tried in Maple 15, 16, 17, 18, and in 2015.

restart;
f:=proc() local i; for i to 10000 do evalf(exp(i)) end do end proc:
try
 timelimit(0.02, f());
catch "time expired":
 123456789
end try;

@Carl Love Yes, indeed it is faster. By a factor 4 on my machine.

@Carl Love Using the code I gave in my reply "Limiting behavior" I found the following modification of FindSingularity useful.
The purpose is to distinguish between maxfun being exceeded and a singularity.

q:=proc(t) sol(parameters=[t]); sol(-2) end proc;

FindSingularity:= proc(q, t::numeric)
     try q(t)
     catch "cannot evaluate the solution further left of %1, probably a singularity":
          return lastexception[-1];
     catch "cannot evaluate the solution":
     end try;
     FAIL
end proc:

FindSingularity(q,-0.6504); #Testing
# Now trying to narrow down the t-value at which a singularity begins to occur
seq([-0.65-0.00005*i,FindSingularity(q,-0.65-0.00005*i)],i=0..8);
seq([-0.65025-0.00001*i,FindSingularity(q,-0.65025-0.00001*i)],i=0..8);
# Then one could continue with
p2:=proc(t,itvl::range) sol(parameters=[t]); plots:-odeplot(sol,[[z,u(z)],[z,v(z)]],itvl,_rest) end proc;
plots:-animate(p2,[t,-2..0,view=0..2,caption=typeset("t = ",t)],t=-0.65030..-0.65029,paraminfo=false);





@patient Regardless of the relevance of the following, it is interesting (I think) to observe the changes as t passes from -0.6504 to -0.65 and then later the convergence of the curves to the solution to the system evaluated at t=0 (sys0 below).

restart;
mu := 0.1e-2; nu := .1; sigma := 1; k := 1;
ode1:= mu*(diff(u(z),z,z))/t+(z-2*sigma*(diff(1/v(z)^(1/2), z)))*(diff(u(z), z))+(3-2*sigma*(diff(1/v(z)^(1/2),z,z)))*u(z) = 0;
ode2:= nu*diff(v(z),z,z)-z*t*diff(v(z), z)-2*t*v(z)-k*v(z)^(1/2)*u(z)=0;
ics:= u(0)=1, v(0)=1, D(u)(0)=0, D(v)(0)=0:
sol:= dsolve({ode1,ode2,ics}, numeric, parameters=[t]);
p:=proc(t) sol(parameters=[t]); plots:-odeplot(sol,[[z,u(z)],[z,v(z)]],-1..0,_rest) end proc;
p(-1,color=[red,blue]); #Just testing p.
# Various animations in t.
plots:-animate(p,[t,view=0..2],t=-1..-0.3);
plots:-animate(p,[t,view=0..2],t=-0.6504..-0.65);
plots:-animate(p,[t,view=0..2],t=-1..-0.01);
# The system for t=0:
sys0:=diff(u(z),z,z)=0,eval(ode2,t=0);
sol0:=dsolve({sys0,ics},numeric);
plots:-odeplot(sol0,[[z,u(z)],[z,v(z)]],-1..0,thickness=2,linestyle=3,view=0..2); p0:=%:
plots:-animate(p,[t,view=0..2],t=-.001..0,background=p0);


Actually the following is simpler and (I think) better.
The procedure Frem returns unevaluated if it doesn't receive numerical input.
Notice the use of the 'known' option in dsolve.

restart;
Frem:=proc(t,u)
   if not [t,u]::list(numeric) then return 'procname(_passed)' end if;
   frem(t,u)
end proc;

sol:=dsolve({diff(x(t), t)=eval(piecewise(0 <= t and t < 10/3, 60, 10/3 <= t and t < 13/3, 0),t=Frem(t,13/3)),diff(y(t),t)=eval(piecewise(0 <= t and t < 4, 50, 4 <= t and t < 5, 0),t=Frem(t,5)),x(0)=0,y(0)=0},numeric,output=listprocedure,known=[Frem]);
plots:-odeplot(sol,[[t,x(t)],[t,y(t)]],0..50);

First 121 122 123 124 125 126 127 Last Page 123 of 231