## 13653 Reputation

19 years, 287 days

## Polynomials involved maybe...

If a univariate polynomial has a multiple root then that root is given as many times as its multiplicity.

I suppose that if in the solving process for you equation a univariate polynomial turns up this could create the situation you describe.

Try solving with infolevel[solve]:=3.
In the lines you will see polynomials mentioned. At the end a confusing message saying:
Main: Exiting solver returning 1 solution

## Maple version...

@ogunmiloro Which Maple release/version are you using?
More importantly, what is your response to mmcdara's question about the fact that C__f has 110 members and 'times'  has only 20? Should the members in C__f be grouped in 20 groups of varying size and so how?

## The workings of _pexports...

I haven't as yet found a description of the meaning of the procedure _pexports.

But it appears to be short for package exports and works this way:

```M:=module() option package; export _pexports,a,b,c;
_pexports:=proc()
[op({exports(M)} minus {':-c', ':-_pexports'})]
end proc;
a:=proc(x) 8*x end proc;
b:=proc(x) x^2 end proc;
c:=proc(x) sin(x) end proc;
end module;
##########
with(M); # Notice that only [a,b] is returned
a(7);
b(s);
c(8); # unevaluated
M:-c(8); # the long form works.

```

It most likely goes back to the introduction of modules in Maple (Maple 6 I believe). The code above certainly works in Maple 8 and later versions.
A neat facility which makes it possible to make a useful but "nerdy" procedure available to the programmer in other contexts than within M. I'm somewhat embarrassed that I haven't noticed this before (or maybe I have, but forgot).

## Maple version...

@dharr Yes, this extra semicolon is allowed in Maple 2019 and 2020, but not before.
Trying in those two Maple versions:
p:=proc(x); local y; y:=x; y end proc;
we notice that the parser removes the semicolon.

## A somewhat odd variant of using discrete...

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.

## global issue...

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.

## gamma...

@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;

## Use worksheet mode and 1D input...

@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

## Assigning the procedure...

@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;
proc(x::positive) option overload; x^2; end proc,
proc(x::negative) option overload; x; end proc ]);
proc(x::positive) option overload; x^2; end proc,
proc(x::negative) x; end proc ]);
proc(x::positive) option overload; x^2; end proc ]);
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:
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.

## Warning, not error...

@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);

## maxfun=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.

## events...

@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);
```

## Yes...

@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.

## x_rkf45...

@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.

## diff with []...

@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]));

 First 27 28 29 30 31 32 33 Last Page 29 of 229
﻿