Preben Alsholm

13613 Reputation

22 Badges

19 years, 231 days

MaplePrimes Activity


These are replies submitted by Preben Alsholm

@mmcdara I agree.

Next to returning a correct answer is returning unevaluated and after that any error.
#############
In view of this result:
dsolve(edo);
y(x) = RootOf(_Z^2 - exp(RootOf(x^2*(tanh(sqrt(_C1^2 + 4)*(2*_C2 + _Z + 2*ln(x))/(2*_C1))^2*_C1^2 + 4*tanh(sqrt(_C1^2 + 4)*(2*_C2 + _Z + 2*ln(x))/(2*_C1))^2 - _C1^2 - 4*exp(_Z) - 4))) - 1 + _Z*_C1)*x

it isn't surprising that the initial value problem fails.

@vv One solution to the double quote problem could be to use Find/Replace from the Edit menu replace " with ` (accent grave) on the faulty procedure (or on a copy of it).
Then apply Carl's procedure to that.
Actually this replacement wouldn't spoil printf or error statements, or descriptions.

The (very) old releases of Maple didn't have real strings but used accent grave (back quote).

@Carl Love Thank you Carl.

@a_simsim You are surely right about the serious lack of examples of all the many options for events.

Your initial use of the trigger t = [2000,500] in events made me make an example of a trigger of that type adapted to your situation by simply modifying EVTS.
The first version EVTS2 doesn't work right because that type of trigger fires for t = 2000+n*500, for any integer n not only positive ones.
Therefore I used a conditional action in EVTS3, where there is no action if t is not large enough.
This extension EVTS3 may not be relevant to your application, but was just meant to give one further example of using events.
MaplePrimes20-12-08_FlowProblem_EVENTSII.mw

@vv Maple apparently doesn't recognize diff(sin(x)*u(x,t),x) as a derivative when the execution of the integral is done because it is evaluated as  cos(x)*u(x, t) + sin(x)*diff(u(x, t), x).
So we have to prevent that evaluation. This could be done by using Diff instead of diff:
 

A:=int(Diff(sin(x)*u(x,t),x),x=-infinity..infinity, continuous);

The result returned is 'undefined'. Not an unreasonable respons, but not correct either.
Integrating from -R to R is a better idea:

A:=int(Diff(sin(x)*u(x,t),x),x=-R..R, continuous);
limit(A,R=infinity);

Then we run into the problem that simplify/side relations doesn't work even for this simpler looking version:

limit(sin(R)*u(R),R=infinity);
simplify(%,{limit(u(R),R=infinity)=0}); 


 

@BrettKnoss You can do that in this way:
 

restart;

f:= 2/(3-x);

s:=convert(f,FormalPowerSeries);

term__k:=simplify(op(1,s)); 

subs(x=abs(x),term__k);
ratio:=subs(k=k+1,%)/%;
limit(ratio,k=infinity);  # answer abs(x)/3

Thus the radius of convergence is 3.

@nm I tried your original worksheet again in Maple 2020.2, Maple 2019.2, and Maple 2015.2.
The first two gave the simple answer twice in two runs.

Maple 2015.2 gave in two runs: (1) simple, not so simple and (2) not so simple, not so simple.

@nm I updated my Physics package.
Still no difference between warnlevel = 3 and warnlevel = 0.

@gasmiboubeker I cannot reproduce the problem in Maple 18.02 nor in Maple 2018.2.

I used the code as written by Tom Leslie.

My Physics version at the time of my first (and so far only) run on your worksheet is 879, whereas yours is the most recent i.e. 884.
With my version the result looked exactly the same in the two cases. The answer looked like the second of yours, i.e. with warnlevel = 3 (the default).
I ran the worksheet again with the same result.
I hesitate to update my Physics because of this. At least I shall wait a few hours.

`Standard Worksheet Interface, Maple 2020.2, Windows 10, November 11 2020 Build ID 1502365`

`The "Physics Updates" version in the MapleCloud is 884. The version installed in this computer is 879 created 2020, November 19, 20:10 hours Pacific Time, found in the directory C:\\Users\\Bruger\\maple\\toolbox\\2020\\Physics Updates\\lib\\`

@Carl Love When I copied your code I got a syntax error. There are more left parentheses than right.
So it should be:
 

ode2:= -v+mu*diff(r*diff(u(r), r), r)/r = 0;

 

@nm The statement in the help that you quote:

"In some cases, the execution may not abort at exactly the time limit imposed, but will abort as soon as it can do so safely"

seems to be contradicted in this example by the fact that the user can stop the computation by pressing the red icon on top.
That is not always the case though.

Why is your title :"Maple write differential equation from Lotka-Volterra Model" ?

This has absolutely nothing to do with Lotka-Volterra.

@mmcdara Classical methods in dsolve (like method=classical[rk4]) use fixed stepsize and has no error control. That allows us to use your original piecewise version mentioned in your original question.
Results appear good with stepsize = 1e-4.
 

# Using P_DATA100 the system is: 
sys100 := {10*diff(v(t), t) = 900*t - 1000 - 10000*x(t) - 100*piecewise(0 < v(t), 1, v(t) < 0, -1, 0), diff(x(t), t) = v(t), v(10/9) = 0, x(10/9) = 0};
#Now using Runge-Kutta 4:
res:=dsolve(sys100,numeric,method=classical[rk4],stepsize=0.0001);
odeplot(res,[t,x(t)],T__0..2);

@mmcdara I have attached a successful events version.
I will say, however, that the classical approach is simpler and real fast with stiff=true (i.e. rosenbrock).
The discrete variable f(t) used here is of type float and will take on 3 values: -1, 0, or 1.
Events are triggered by v(t) +eps =0, v(t)-eps = 0, and v(t)=0.
For both methods stiff=true is chosen although it probably has no effect in the events case.

 

restart;

with(plots):

# x(t)        body displacement
# v(t)        body velocity
# M__p     body mass
# V__p     body volume
# P__0      pre-stress of the spring
# K           spring stiffness
# C           solid-solid friction coefficient
# rho__h   density of the fluid the body is immersed in
#
# gamma__longi(t) longitudinal acceleration

gamma__longi := t -> A*t;

####################################

# The classical approach:

equationsC := {
               diff(x(t), t) = v(t),
               M__p * diff(v(t), t) = (M__p - V__p*rho__h) * gamma__longi(t)
                                      - (P__0 + K*x(t))
                                      - C*tanh(v(t)/v__0)
            };

 

EVENTS:=[[v(t)+eps,f(t)=-1],[v(t)-eps,f(t)=1],[v(t),f(t)=0]];

equationsE := {
               diff(x(t), t) = v(t),
               M__p * diff(v(t), t) = (M__p - V__p*rho__h) * gamma__longi(t)
                                      - (P__0 + K*x(t))
                                      -f(t)*C
            };

# take-off time
# (obtained by equating to 0 the rhs of the 2nd edo after having set x(t)=v(t)=0 and removed the friction term)


rest_state := eval(equationsC[1], [x(t)=0, v(t)=0]);
T__off     := solve(eval(rest_state, C=0), t);
 

# initial conditions

IC_C := { x(T__off) = 0, v(T__off) = 0};
IC_E := { x(T__off) = 0, v(T__off) = 0, f(T__off) = 0};
# full systems

sysC := equationsC union IC_C;
sysE := equationsE union IC_E;

eps:=1e-4: v__0:=1e-7:

SOL_C:=dsolve(sysC,numeric,parameters=[A, M__p, V__p, rho__h, P__0, K, C],stiff=true); ## stiff
SOL_E:=dsolve(sysE,numeric,parameters=[A, M__p, V__p, rho__h, P__0, K, C],
                   discrete_variables=[f(t)::float],
                   events=EVENTS,maxfun=10^6, stiff=true  #stiff doesn't help much here
                );

P_DATA0 := [
            A      = 100,
            M__p   = 10,
            V__p   = 1,
            rho__h = 1,
            P__0   = 1000,
            K      = 10000,
            C      = 0
          ]:

T__0 := eval(T__off, P_DATA0);
 

SOL_C(parameters=P_DATA0):
Frictionless_C := odeplot(SOL_C, [t, x(t)], t=T__0..2, color=blue);
 

SOL_E(parameters=P_DATA0):
Frictionless_E := odeplot(SOL_E, [t, x(t)], t=T__0..2, color=blue);

P_DATA100 := [
            A      = 100,
            M__p   = 10,
            V__p   = 1,
            rho__h = 1,
            P__0   = 1000,
            K      = 10000,
            C      = 100
          ]:

T__0 := eval(T__off, P_DATA100);
 

SOL_C(parameters=P_DATA100):
t0:=time():
StrongFriction_C := odeplot(SOL_C, [t, x(t)], t=T__0..2, color=red):
time()-t0; # 0.015

display(Frictionless_C, StrongFriction_C); pC:=%:

SOL_E(parameters=P_DATA100):
t0:=time():
StrongFriction_E := odeplot(SOL_E, [t, x(t)], t=T__0..2, color=red):
time()-t0; # 2.250s

display(Frictionless_E, StrongFriction_E); pE:=%:

display(pC,pE);

 


pC and pE look the same and overlap totally in the last display with eps=1e-4.
With eps = 1e-3 computation time is much smaller and overlap is still good.
With eps = 1e-2 computation time is even smaller, but there is clear visual disagreement between pC and pE.
odeplot(SOL_E,[t,f(t)], T__0..2,numpoints=10000) will show you that an enormous amount of events takes place, so no wonder it takes time.

Download MaplePrimes20-11-07_classical_and_event.mw

First 21 22 23 24 25 26 27 Last Page 23 of 229