Preben Alsholm

11719 Reputation

22 Badges

15 years, 255 days

MaplePrimes Activity


These are replies submitted by Preben Alsholm

Here is a variant where T is defined as a procedure with option remember and returning unevaluated if t is 0 or just the global name t..

restart;

ode2 := diff(varphi(t), t, t) + omega^2*sin(varphi(t));
p0 := evalf(10/180*Pi);
te:=6:
event2 := [[diff(varphi(t), t), T(t)=t]];
##
T:=proc(t) option remember; 
  if t::identical(':-t') or t=0 then 
    'T(t)' 
  else
     subs(ld2(t),T(':-t')) 
  end if
end proc;
##
ld2 := dsolve([eval(ode2, omega = 2*Pi), varphi(0) = p0, D(varphi)(0) = 0,T(0)=0], numeric,
               discrete_variables=[T(t)::float], events = event2,abserr=1e-12,relerr=1e-9);

op(4,eval(T)); # So far the only members of the remember table
plot(T(t),t=0..te); # Creates many members
{entries(op(4,eval(T)),nolist)} minus {T(0),T(t)};

The last line returns
{0., 0.5009535940730963, 1.0019071881466945, 1.5028607822207958, 2.0038143762954004, 2.504767970370508, 3.0057215644461186, 3.506675158522232, 4.0076287525988485, 4.508582346675968, 5.009535940753591, 5.510489534831716}

This one works as is in Maple 12 too.

I ran your interesting worksheet in Maple 2020.1.

It produced an error when coming to the statement

global liste_triangles:
The error was:

Error, global declaration unexpected outside procedure or module

Trying in a fresh worksheet in Maple 2015.2 and in Maple 2020.1 the followingt:
 

restart;
global liste_triangles;

I get the output _global(liste_triangles) in Maple 2015.2, but the error shown above in Maple 2020.1.

Just commenting out this attempt to declare liste_triangles makes your worksheet work fine in Maple 2020.1.

 

@brian bovril Since by gamma you most likely don't mean Euler's constant, you should either replace it by some other name or start your session with local gamma;  after restart.
Secondly, just replace gamma by beta or vice versa.
 

restart;
local gamma;
ode := x^2*diff(z(x), x, x) + (1 + gamma + beta)*x*diff(z(x), x) + gamma*beta*z(x) - cos(ln(x));
ode1:=eval(ode,gamma=beta);
sol:=dsolve({ode1, z(1) = 1, D(z)(1) = -1});
evalc(sol);

If x is known to be positive then this will shorten the answer considerably:
simplify(evalc(sol)) assuming x>0;

@Hnx I strongly recommend using worksheet mode and 1D math input (aka Maple input):

Go to Tools/Options/Display/Input display: Choose Maple Notation.

After that and without leaving the window that is open go to the menu Interface/Default format for new worksheets: Choose Worksheet.
Then press the button at the bottom labelled Apply Globally. Don't worry about the word "Globally"; these changes can just as easily be reverted.
Any new worksheet that you open will use the chosen format. Old worksheets or worksheets from other people won't change if brought into your copy of Maple.

Personally I never use 2D math input or document mode. I find it frustrating to work with as it seems to be for you.
Here is your code slightly modified (irrelevant though) in 1d-input and worksheet mode (and no equation labels: my personal preference).

MaplePrimes20-06-10_1D_worksheet.mw

@acer The difference in your procedures is seen before the call if they are assigned to a name:
 

restart;
M:=module() option package;
  export e,f,g,h;
  e := overload([
         proc(x::positive) option overload; x^2; end proc,
         proc(x::negative) option overload; x; end proc ]);
  f := overload([
         proc(x::positive) option overload; x^2; end proc,
         proc(x::negative) x; end proc ]);
  g := overload([
         proc(x::positive) option overload; x^2; end proc ]);
  h := overload([
         proc(x::positive) option overload; x^2; end proc,
         proc(x::odd) option overload; x^3; end proc,
         proc(x::negative) x; end proc ]);
end module:
with(M):
pe:=proc() uses M; e(3); end proc;

pf:=proc() uses M; f(3); end proc;

pg:=proc() uses M; g(3); end proc;

ph:=proc() uses M; h(3); end proc;

We see from the printed ouput that inside the procedures pf and ph f and h are replaced by M:-f and M:-h, respectively.

This doesn't happen with pe and pg.
If with(M) is placed after the definitions of the procedures pe,pf,pg, and pg then there is no problem.
Thus if one's own package makes use of 'uses LinearAlgebra' and that package is loaded before using with(LinearAlgebra) in a worksheet, there should be no problem.

Note: After M is defined and after with(M)  then eval(e) returns just:
overload([e = M:-e])
which doesn't make any sense to me (although e works).
To get the print above use standard typesetting, otherwise the output prints as overload([e = e]) (!!)

In contrast eval(f) evaluates to

overload([proc (x::positive) option overload; x^2 end proc, proc (x::negative) x end proc])
as expected.

 

@Hnx What odeplot does is to issue a warning, but the plot is fine.
If you want to know the value of tmax before the plot you can simply do:
 

phi1_numeric := dsolve({deq_numeric, ics_numeric}, numeric, events = [[phi1(t) = phi1_end, halt]],maxfun=0);
res:=phi1_numeric(0.5); # warning only and expected since you asked for a stop.
tmax:=eval(t,res); 
plots:-odeplot(phi1_numeric,[t,phi1(t)],0..tmax);

If you don't even want to see a warning you can turn warnings off (only do this temporarily, not a good idea in general):
interface(warnlevel=0);

@Hnx I added maxfun=0, which really means maxfun = infinity, i.e. no upper bound for the number of function evaluations.
 

phi1_numeric := dsolve({deq_numeric, ics_numeric}, numeric, events = [[phi1(t) = phi1_end, halt]],abserr = 0.1*10^(-8), relerr = 0.1*10^(-7),maxfun=0);

Then try:
 

t_max := 0.354;
odeplot(phi1_numeric, [t, phi1(t)], t = 0 .. t_max + 0.1);

You will see that the event occurs.

@Hnx You say that you know the point of singularity in the form of a constant. Is that constant the value of t or of y(t) or y'(t) or what?

Here is a very simple example, where we know in advance that the solution y(x) has a singularity at x = 1.
 

restart;
ode:=diff(y(x),x)=y(x)^2;
ic:=y(0)=1;
dsolve({ode,ic});
#Singularity at x = 1.
res:=dsolve({ode,ic},numeric);
res(1.1); # Error message is good
eps:=1e-9: # Value dependent on Digits and abserr/relerr
resE:=dsolve({ode,ic},numeric, events=[[x=1-eps,halt]], abserr=1e-9,relerr=1e-8);
resE(1.1);

 

@Carl Love  Thanks for reminding me of this weird bug.
The bug as reported concerned Maple 2015. It seems that improvements were made in Maple 2016, and the bug seems to be gone in Maple 2017, and also in Maple 2018 - Maple 2020.

@Hnx The name x_rkf45 is just the formal parameter in the procedure resulting from dsolve/numeric with the default method rkf45 as in

restart;
ivp:={diff(x(t),t)=x(t),x(0)=1};
res:=dsolve(ivp,numeric); # formal parameter x_rkf45
##
interface(verboseproc=2);
eval(res);

The reason for not just using plain x instead of x_rkf45 may be to inform the user that the method used is rkf45 (my guess).

You can find code for rkf45 (Runge-Kutta-Fehlberg) on the internet.
See e.g. this link to Douglas Wilhelm Harder:
https://ece.uwaterloo.ca/~dwharder/NumericalAnalysis/14IVPs/rkf45/complete.html

But as Georgios is pointing out you could use the events option in dsolve/numeric to do breaks or whatever it is you want to do. The help page for events isn't easy reading, but you could let us know what you are thinking of doing.

@acer You don't need the if statement which takes i = 0 as a special example.

diff(f(x), [] ) returns f(x). So the if statement can be skipped and in the loop we can just do:
U := 'Typesetting:-Typeset'(diff('f(x)',[x$i]));

@dharr I don't understand your statement that k is used in two versions.
I don't think that k is local to sum nor to Sum:
 

restart;
B[1] := BesselI(k - 1, alpha*(u - y));
sum(B[1],k=1..4);
Sum(B[1],k=1..4);

 

@mthkvv A good question. With interface(warnlevel=0) it still happens (with 2D input).

This behavior is new to Maple 2020 and is clearly intended.

I can only speculate that the warning is meant to help new users. Furthermore turning off warnings in general would not be good even for experienced users.

I use 1D input exclusively so this problem doesn't affect me.

@Kitonum Notice that ArrayTools reverses rows and columns, where ListTools only reverses the outer list.

We can, however achieve the ArrayTools ordering by an additional Reverse (if desired):
 

restart;
A:=[[0, 4], [1, 3], [2, 2], [3, 1], [4, 0], [0, 3], [1, 2], [2, 1], [3, 0], [0, 2], [1, 1], [2, 0], [0, 1], [1, 0], [0, 0]];
A1:=ListTools:-Reverse(A); 
ListTools:-Reverse~(A1); # Elementwise

 

@Grigoriy Yashin You are right: I didn't see that you were not considering the full system in the first solve command.

Please see my correction at the end of my answer. But the linear system sys6 in the variables vars has no solutions.

Thus solve returns NULL for that system.

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