acer

32787 Reputation

29 Badges

20 years, 127 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

The Help-page for topic procedure is describing technical aspects of a fundamental programming component of the Maple language, and the use of the word variable there is intentional jargon related to the Computer Science context of programming languages.

In contrast, in many mathematical contexts (for example, differential equations, integration, optimization, etc) the word variable has quite another set of connotations. And several other Maple's Help-pages reflect that, so as to be more broadly and readily understandable.

So, a word like "variable" can sometimes be used in a technical C.S. way when describing part of the Maple programming language, and can sometimes be used in a mathematical or general way.

One way is to use assumptions on t.
 

with(Statistics)

x := RandomVariable(Uniform(1, 2))

y := RandomVariable(Uniform(2, 3))

`assuming`([PDF(x*y, t)], [t >= 2, t <= 6])

piecewise(t <= 3, -ln(2)+ln(t), t <= 4, ln(3)-ln(2), 4 < t, ln(3)-ln(t)+ln(2))

`assuming`([PDF(x*y, t)], [t >= 2])

piecewise(t <= 3, -ln(2)+ln(t), t <= 4, ln(3)-ln(2), t <= 6, ln(3)-ln(t)+ln(2), 6 < t, 0)

`assuming`([PDF(x*y, t)], [t >= 0])

piecewise(t <= 2, 0, t <= 3, -ln(2)+ln(t), t <= 4, ln(3)-ln(2), t <= 6, ln(3)-ln(t)+ln(2), 6 < t, 0)

Download MultiplyPDFFunctions_ac.mw

So, you must be using 2D Input mode (the default), for which (if done first),

   f(x) := foo

gets parsed as an operator assignment, ie, just as if it had been entered as,

   f := x-> foo

In 1D Maple notation the syntax f(x):=foo is interpreted always as an
assignment to the remember table of the operator/procedure.

Internally, the system does subsequent 2D Input interpretations according
to whichever syntax you've used first (after restart). If you first use the
syntax f:=x->foo in 2D Input mode then subsequently the syntax
f(x):=foo gets interpreted as a remember table assignment.

Many releases ago the syntax f(x):=foo would elicit a disambiguation
popup dialog box, asking the user to specify which interpretation was
intended. Nowadays it tries to to distinguish according to which syntax
was already/first used.

restart

"f(x):=2*x"

proc (x) options operator, arrow, function_assign; 2*x end proc

eval(f)

proc (x) options operator, arrow, function_assign; 2*x end proc


The 2D parser now "knows" that you are using the syntax to mean
operator-assignment, and will also interpret additonal instances to
be operator-assignment (unless you restart).

"f(x):=sin(x) "

proc (x) options operator, arrow, function_assign; sin(x) end proc

eval(f)

proc (x) options operator, arrow, function_assign; sin(x) end proc

f(16)

sin(16)

f(x)

sin(x)

restart

f := proc (x) options operator, arrow; 2*x end proc

proc (x) options operator, arrow; 2*x end proc


The 2D parser will now interpret the following as an assignment
to the remember table of the operator assigned to f. (It'll stop doing
that if you restart.)

"f(x):=sin(x) "

sin(x)


But the body of the operator remains the same.

eval(f)

proc (x) options operator, arrow; table( [( x ) = sin(x) ] ) 2*x end proc


If you pass something else (that is not exactly the name x) then
the formula in the operator will get used to compute the result.

f(y)

2*y

f(8)

16

The following is done by looking up the entry for the name x in the
remember table of f. The result is obtained via lookup, not by using
the formula in the operator assigned to f.

f(x)

sin(x)


We can even examine the remember table of the operator/procedure.

op(4, eval(f))

table( [( x ) = sin(x) ] )

Here, plot receives sin(x) after f(x) gets evaluated
plot(f(x), size = [300, 200])

Here, plot receives 2*y after f(y) gets evaluated
plot(f(y), size = [300, 200])

 

 

Download 2d_oper_assignment.mw

restart;

T := table([([-.687272727272727, -.687272727272727, 1.], [2.25818181818182, 2.258181\
81818182, 1.])=COLOR(RGB,.63529412,.60392157,.60000000),([-2.47, -1.47, 2.], [.\
53, 1.53, 2.])=COLOR(RGB,.60784314,.47450980,.46274510),([.245, -2.755, -2.], [
2.745, -.255, -2.])=COLOR(RGB,.44705882,.52549020,.67058824),([-2.6, -.6, 3.],
[.379, 2.379, 3.])=COLOR(RGB,.57647059,.34509804,.32549020),([2.659, -1.341, -3\
.], [4.652, .652000000000001, -3.])=COLOR(RGB,.34901961,.46666667,.70980392),([
-3.178, .822000000000001, 5.], [-1.185, 2.815, 5.])=COLOR(RGB,.47058824,0.,.\
54901961e-1),([.672727272727271e-1, -.932727272727273, 0.], [3.06181818181818,
2.06181818181818, 0.])=COLOR(RGB,.62352941,.63529412,.65490196),([2.8895, -2.11\
05, -4.], [4.3895, -.6105, -4.])=COLOR(RGB,.22745098,.40392157,.78039216),([1.0\
1, -.99, -1.], [4.02571428571429, 2.02571428571429, -1.])=COLOR(RGB,.53725490,.\
57647059,.65490196),([-3.63, -.63, 4.], [-1.13875, 1.86125, 4.])=COLOR(RGB,.537\
25490,.20392157,.18823529)]);

table( [( [-2.47, -1.47, 2.], [.53, 1.53, 2.] ) = COLOR(RGB, .60784314, .47450980, .46274510), ( [.245, -2.755, -2.], [2.745, -.255, -2.] ) = COLOR(RGB, .44705882, .52549020, .67058824), ( [-.687272727272727, -.687272727272727, 1.], [2.25818181818182, 2.25818181818182, 1.] ) = COLOR(RGB, .63529412, .60392157, .60000000), ( [-3.178, .822000000000001, 5.], [-1.185, 2.815, 5.] ) = COLOR(RGB, .47058824, 0., 0.54901961e-1), ( [-2.6, -.6, 3.], [.379, 2.379, 3.] ) = COLOR(RGB, .57647059, .34509804, .32549020), ( [2.659, -1.341, -3.], [4.652, .652000000000001, -3.] ) = COLOR(RGB, .34901961, .46666667, .70980392), ( [-3.63, -.63, 4.], [-1.13875, 1.86125, 4.] ) = COLOR(RGB, .53725490, .20392157, .18823529), ( [1.01, -.99, -1.], [4.02571428571429, 2.02571428571429, -1.] ) = COLOR(RGB, .53725490, .57647059, .65490196), ( [2.8895, -2.1105, -4.], [4.3895, -.6105, -4.] ) = COLOR(RGB, .22745098, .40392157, .78039216), ( [0.672727272727271e-1, -.932727272727273, 0.], [3.06181818181818, 2.06181818181818, 0.] ) = COLOR(RGB, .62352941, .63529412, .65490196) ] )

new := table([map(tt->tt[1]=T[tt[]],[indices(T)])[]]);

table( [( [-3.178, .822000000000001, 5.] ) = COLOR(RGB, .47058824, 0., 0.54901961e-1), ( [0.672727272727271e-1, -.932727272727273, 0.] ) = COLOR(RGB, .62352941, .63529412, .65490196), ( [2.8895, -2.1105, -4.] ) = COLOR(RGB, .22745098, .40392157, .78039216), ( [1.01, -.99, -1.] ) = COLOR(RGB, .53725490, .57647059, .65490196), ( [-.687272727272727, -.687272727272727, 1.] ) = COLOR(RGB, .63529412, .60392157, .60000000), ( [-2.47, -1.47, 2.] ) = COLOR(RGB, .60784314, .47450980, .46274510), ( [.245, -2.755, -2.] ) = COLOR(RGB, .44705882, .52549020, .67058824), ( [-3.63, -.63, 4.] ) = COLOR(RGB, .53725490, .20392157, .18823529), ( [-2.6, -.6, 3.] ) = COLOR(RGB, .57647059, .34509804, .32549020), ( [2.659, -1.341, -3.] ) = COLOR(RGB, .34901961, .46666667, .70980392) ] )

map(print,sort([indices(T)])):

[[-3.63, -.63, 4.], [-1.13875, 1.86125, 4.]]

[[-3.178, .822000000000001, 5.], [-1.185, 2.815, 5.]]

[[-2.6, -.6, 3.], [.379, 2.379, 3.]]

[[-2.47, -1.47, 2.], [.53, 1.53, 2.]]

[[-.687272727272727, -.687272727272727, 1.], [2.25818181818182, 2.25818181818182, 1.]]

[[0.672727272727271e-1, -.932727272727273, 0.], [3.06181818181818, 2.06181818181818, 0.]]

[[.245, -2.755, -2.], [2.745, -.255, -2.]]

[[1.01, -.99, -1.], [4.02571428571429, 2.02571428571429, -1.]]

[[2.659, -1.341, -3.], [4.652, .652000000000001, -3.]]

[[2.8895, -2.1105, -4.], [4.3895, -.6105, -4.]]

map(print,sort([indices(new)])):

[[-3.63, -.63, 4.]]

[[-3.178, .822000000000001, 5.]]

[[-2.6, -.6, 3.]]

[[-2.47, -1.47, 2.]]

[[-.687272727272727, -.687272727272727, 1.]]

[[0.672727272727271e-1, -.932727272727273, 0.]]

[[.245, -2.755, -2.]]

[[1.01, -.99, -1.]]

[[2.659, -1.341, -3.]]

[[2.8895, -2.1105, -4.]]


Download nm_table_q1.mw

Maple uses a extension mechanism for some kernel builtin commands like expand. This recognizes procedures with a name in a pattern like `expand/f` to be the thing to use when asked to expand a call to f.

There is a default Library procedure assigned to `expand/Sum`. That is a somewhat complicated procedure that tries a bit to respect the notion that expanding (splitting) a Sum is not always mathematically valid.

When you load a command from the old student package (using with, like you've done) Maple does some initialization of the package and redefines some things. In particular, it redefines `expand/Sum`.

It actually redefines it as a call to readlib of the new, replacement procedure. That's not key. What's key is that the initialization assigns another, simpler procedure to `expand/Sum`. That new procedure turns a Sum call of an addition of terms into an addition of Sum calls, regardless of the fact that is not always right. I suspect that the rationale was the students would find the functionality useful, and were less likely to be working with divergent sums (infinite series), etc, or that the benefit of the functionality outweighed the danger.

You can compare these:

restart;
interface(verboseproc=3):
with(student,changevar);
showstat(eval(`expand/Sum`));

restart;
interface(verboseproc=3):
showstat(`expand/Sum`);

Here are various corrections and adjustments, including:

- Utilize the nolines option to plots:-inequal, to get rid of dotted line demarking part of one strict inequality.
- Utilize InertForm:-Display for (right tick) unevaluation-quoted expressions used in the plots. Otherwise, subsequent re-use or evaluation of the created plots will cause those nicely formatted names in inequalities to evaluate to lengthy expressions. NB. the typeset option does not(!) prevent that. You can test this worked by just assigning the plot to a name, and then printing that after the fact; it's working properly if the inlined math in the plot survives.
- Get rid of some unnecessary quotes.
- Pass gridrefine=4 on to implicitplot, called from plots:-inequal, to get smoother edges of polygon regions.

restart

with(Optimization); with(plots); with(Student[VectorCalculus]); with(LinearAlgebra)

DATA := [delta = .9, a = 0.1e-1, g = .25, c = 0.5e-1, sigma = 0.8e-1, Cn = .4, Crm = .1, Cr = 0.1e-1, Pr = .35, t = 0.5e-1, alpha = .95, s = 0.1e-1, upsilon = .95, rho0 = .4, b = .5]

`&pi;_WD` := (((alpha*((-g*i2 + a)*Cr + 2*Crm + 2*c - 2*Pr)*Cr*b + ((g*i2 - a)*Cr - 2*Crm - 2*c + 2*Pr)*alpha - (-g*i2 + a)*Cr)*d + alpha*((-g*i2 + a)*Cr + 2*Crm + 2*c - 2*Pr)*b + 2*g*i2 - 2*a)*rho0 + 2*((Cr*b - 1)*d + b)*(delta + Cn - Pr - 1))^2*b*d/(8*(Cr*b*d + b - d)^2*(((Cr*alpha*b - alpha + 1)*d + alpha*b)*rho0^2 - 2*b*d*(delta - 1))):

`&pi;_D` := b*(Cr*rho0*t*(Cr*alpha*b-alpha-1)*d^2+((alpha*((-g*i2+a)*Cr+2*Crm+2*c+3*t-2*Pr)*Cr*b+((g*i2-a)*Cr-2*Crm-2*c-2*t+2*Pr)*alpha+(g*i2-a)*Cr-2*t)*rho0+(2*(Cr*b-1))*(sigma*t+Cn-Pr+delta-1))*d+(alpha*((-g*i2+a)*Cr+2*Crm+2*c+2*t-2*Pr)*b+2*g*i2-2*a)*rho0+2*b*(sigma*t+Cn-Pr+delta-1))^2*d/(8*((Cr*b-1)*d+b)^2*(((Cr*alpha*b-alpha+1)*rho0^2-2*b*(delta-1))*d+alpha*b*rho0^2))

`&pi;R` := subs(DATA, `&pi;_WD`)

`&pi;D` := subs(DATA, `&pi;_D`)

Di := `&pi;R`-`&pi;D`

# Step 1: try to figure out the scales of the domain where to use plots:-inequal
(*
simplify(`&pi;R`-`&pi;D`);
S := solve(%=0, Ce):

eval([S], i2=0.01);
eval(`&pi;R`-`&pi;D`, {i2=0.01, d=0.8});
eval(`&pi;R`-`&pi;D`, {i2=0.01, d=0.3});

eval([S], i2=0.09);
eval(`&pi;R`-`&pi;D`, {i2=0.09, d=0.8});
eval(`&pi;R`-`&pi;D`, {i2=0.09, d=0.3});
*)

LX := 0.09: LY := 0.8:

# Plot region where πR > πD
p := plots:-display(
  plots:-inequal(`&pi;R` > `&pi;D`, i2 = 0 .. LX,
                 d = 0 .. LY, ':-color' = "Chartreuse",
                 ':-nolines', ':-optionsimplicit'=[':-gridrefine'=4]),
  axes=boxed):

display(p,plot(x, x=0..0.06, color="Chartreuse", thickness=10,
               legend=InertForm:-Display('`&pi;R`' > '`&pi;D`'),
        view = [0 .. LX, 0 .. LY],labels = ['i2', 'd']));

eps  := 0.001:

OneHatch := display(plottools:-polygon(
                [[-2*LX, -2*LX-eps], [2*LX, 2*LX-eps], [2*LX, 2*LX+eps],
                 [-2*LX, -2*LX-eps], [-2*LX, -2*LX-eps]],
                color=gray, style=line)):

Tr := plottools:-transform((x, y) -> [x, y*LY/LX]):

back := display(seq(plottools:-translate(Tr(OneHatch), 0, h),
                    h=-2*LY..2*LY, LY/10),
                view=[-LX..LX, -LY..LY], axes=framed):

display(p
  , back
  , plot(x, x = -LX .. -(1/2)*LX, color = "Chartreuse", thickness = 10,
         legend = InertForm:-Display('`&pi;R` > `&pi;D`'))
  , title=typeset("Hatched region =   ", InertForm:-Display('`&pi;R`' < '`&pi;D`'))
  , view = [0 .. LX, 0.3 .. LY]);

display(plottools:-rectangle([0.01, 0.65], [0.03, 0.7], color=white)
  , textplot([0.02, 0.675, Pi[m]^WD > Pi[m]^:-D], font=[Times, bold, 10])
  , p
  , back
  , plottools:-rectangle([0.01, 0.4], [0.03, 0.45], color=white),
    textplot([0.02, 0.435, InertForm:-Display('`&pi;WD` < `&pi;D`')]
  , font=[Times, bold, 10])
  , view = [0 .. LX, 0.3 .. LY]);

 

 

Download Question_1_regional_ac.mw

Here is a further revision of Carl's revision of Kitonum's procedure.

The main point of this revision is to allow the same kinds of color functionality (for the curves and the text contour labels) as contourplot has for its curves.

(Aside: If you have an old version which does not support the colorbar option -- on densityplot or contourplot -- then you could just remove those from the code. The code below references it just to disable it.)

[edit] The code immediately below has been re-edited and corrected/improved, related to Replies below this Answer.

restart;

kernelopts(version);

`Maple 2024.2, X86 64 LINUX, Oct 29 2024, Build ID 1872373`

ContoursWithLabels := proc(
     Expr::algebraic,
     Range1::(name=range(realcons)), Range2::(name=range(realcons)),
     {contours::{posint, {list}(realcons)}:=8},
     {GraphicOptions::{list,set}({name, name= anything}):= NULL},
     {ImplicitplotOptions::{list,set}({name, name=anything}):=NULL},
     {TextOptions::{list,set}({name, name=anything}):=NULL},
     {ContourOptions::{list,set}({name, name=anything}):=NULL},
     {DensityOptions::{list,set}({name, name=anything}):=NULL} )
   local r1,r2,f,L1,h,S1,P,r,M,C,T,p,p1,m,n,i,G,GL,mm,PO,data,
         x:=lhs(Range1),y:=lhs(Range2);
     f := unapply(Expr,(x,y));
     if contours::posint then
          r1 := rand(convert(rhs(Range1), float));
          r2 := rand(convert(rhs(Range2), float));
          L1 := select(type,(f@op)~({seq([r1,r2](),i=1..205)}),realcons);
          h := (L1[-6]-L1[1])/contours;
          S1 := [seq(L1[1]+h/2+h*(n-1), n=1..contours)]
     else #contours::{set,list}(realcons)
          S1 := [contours[]]
     end if;
     userinfo(1, ContoursWithLabels, print('Contours' = evalf[2](S1)), `\n`);
     r := k-> rand(20..k-20);
     G := plots:-contourplot(Expr,Range1,Range2,':-contours'=S1, ':-grid'=[5,5],
                             ':-contourlabels'=false,':-colorbar'=false,ContourOptions[]);
     GL := ListTools:-Reverse(select(u->type(u,specfunc(CURVES)) and nops(u)>0,[op(G)]));
     for C from 1 to nops(S1) do
          P := plots:-implicitplot(Expr = S1[C], Range1, Range2,
                                   gridrefine=3, ImplicitplotOptions[]);
          PO := select(type,[op(GL[C])],specfunc({COLOR,COLOUR}))[-1];
          data := [plottools:-getdata(P)];
          if data = [] then next; end if;
          for p in data do
               p1 := convert(p[3], listlist); n := nops(p1);
               if n < 500 then
                    m := `if`(40 < n, r(n)(), round(n/2));
                    M[`if`(40 < n, [p1[1..m-11], p1[m+11..n]], [p1])[]] := PO;
                    T[[p1[m][], evalf[2](S1[C])]] := PO;
               else
                    h := trunc(n/2); m := r(h)();
                    M[p1[1..m-11], p1[m+11..m+h-11], p1[m+h+11..n]] := PO;
                    T[[p1[m][], evalf[2](S1[C])], [p1[m+h][], evalf[2](S1[C])]] := PO;
               end if;
          end do;
     end do;
     `if`( ( (not M::table) or nops([indices(M)])=0 )
           and ( (not T::table) or nops([indices(T)])=0 )
           and DensityOptions=NULL,
          PLOT(),
          plots:-display([
          `if`(DensityOptions = NULL,NULL,
               plots:-densityplot(Expr, Range1, Range2, ':-colorbar'=false,
                                  ':-style'=':-surface', DensityOptions[])),
           `if`(M::table,seq(plot(mm,':-color'=M[mm[]], GraphicOptions[]),mm=[indices(M)]),NULL),
           `if`(T::table,seq(plots:-textplot(mm,':-color'=T[mm[]], TextOptions[]),mm=[indices(T)]),NULL)
                    ], 'axes'=':-box', 'gridlines'=false, _rest)
        );
end proc:

 

ff := (11-x-y)^2+(1+x+10*y-x*y)^2;

(11-x-y)^2+(-x*y+x+10*y+1)^2

ContoursWithLabels(
     ff, x=0..20, y=0..15, contours=11,
     TextOptions = [font=[HELVETICA,BOLD,8], color="DarkBlue"],
     ContourOptions = [colorscheme="DivergeRainbow"],
     ImplicitplotOptions = [gridrefine=4],
     size = [900,500], labels=[x,y]);

ContoursWithLabels(
     ff, x=0..20, y=0..15, contours=[seq(50+i*50,i=0..10),seq(1000+i*1100,i=0..8)],
     TextOptions = [font=[HELVETICA,BOLD,8]],
     ContourOptions = [colorscheme="DivergeRainbow"],
     ImplicitplotOptions = [gridrefine=3],
     size = [900,500], labels=[x,y]);

PP := 0.3800179925e-3*exp(-0.6065722618e-3*(x-29.51704536)^2
      +(0.6650093594e-3*(x-29.51704536))*(a-12.94061928)-0.1106850312e-2*(a-12.94061928)^2);

0.3800179925e-3*exp(-0.6065722618e-3*(x-29.51704536)^2+0.6650093594e-3*(x-29.51704536)*(a-12.94061928)-0.1106850312e-2*(a-12.94061928)^2)

ContoursWithLabels(
     PP, x=-20..20, a=-20..20, contours=[seq(1e-4..4e-4,5e-5)],
     TextOptions = [font=[HELVETICA,BOLD,8]],
     ContourOptions = [colorscheme="DivergeRainbow"],
     labelfont = [TIMES,BOLDITALIC,12], axesfont = [HELVETICA,10],
     size = [500,500]);

ContoursWithLabels(
     PP, x=-20..20, a=-20..20, contours=[seq(1e-4..4e-4,5e-5)],
     TextOptions = [font=[HELVETICA,8]],
     ContourOptions = [color=black],
     GraphicOptions = [thickness=0.5],
     labelfont = [TIMES,BOLDITALIC,12], axesfont = [HELVETICA,10],
     size = [500,500]);

ContoursWithLabels(
     PP, x=-20..20, a=-20..20, contours=[seq(1e-4..4e-4,5e-5)]);

ContoursWithLabels(
     PP, x=-20..20, a=-20..20, contours=[seq(1e-4..4e-4,5e-5)],
     DensityOptions = [colorscheme="DivergeRainbow", style=surface],
     TextOptions = [font=[HELVETICA,BOLD,8]],
     ImplicitplotOptions = [gridrefine=2],
     ContourOptions = [color=black],
     labelfont = [TIMES,BOLDITALIC,12], axesfont = [HELVETICA,10],
     size = [500,500]);

ContoursWithLabels(
     PP, x=-20..20, a=-20..20, contours=[seq(1e-4..4e-4,5e-5)],
     DensityOptions = [colorscheme=["zgradient",["Purple","LightBlue","Orange"]],colorbar=true],
     TextOptions = [font=[HELVETICA,BOLD,9],color="#303030"],
     ContourOptions = [color="#303030"],
     labelfont = [TIMES,BOLDITALIC,12], axesfont = [HELVETICA,10],
     size = [700,400]);

ContoursWithLabels(
     PP, x=-20..20, a=-20..20, contours=[seq(1e-4..4e-4,5e-5)],
     DensityOptions = [colorscheme=[black,white]],
     TextOptions = [font=[HELVETICA,BOLD,10]],
     ContourOptions = [colorscheme=[white,"LightGray",black]],
     GraphicOptions = [thickness=0.5],
     labelfont = [TIMES,BOLDITALIC,12], axesfont = [HELVETICA,10],
     size = [700,400]);

ContoursWithLabels(
     y^2+x-1, x=-10..10, y=-10..10, contours=[$-1 .. 5],
     TextOptions = [font=[HELVETICA,BOLD,7], color="DarkBlue"],
     ContourOptions = [colorscheme="DivergeRainbow"]);

ContoursWithLabels(
     y^2+x-1, x=-10..10, y=-10..10, contours=[$-1 .. 5],
     TextOptions = [font=[HELVETICA,BOLD,10]],
     ContourOptions = [colorscheme="DivergeRainbow"]);

Download CPL05a.mw

ps. I notice that my M2024.2 has trouble rendering the minus sign in a textplot numeral/float, when the font size is 8 or 9. Not central to this code, but I'll report it.

I'm not suggesting that this is a good choice of template function. It's merely an illustration, a bit like you had.

Not also that NonlinearFit might do local optimization, so quality of the fit can depend on the choice of initialvalues. See also the DirectSearch v.2 package on the Application Center, which can do similar kinds of fitting but doing global optimization over supplied parameter ranges.

notes:
- The randomize() call makes it get a different L after each restart.
- The float range -5.0..5.0 makes it produce floats in the range. A range -5..5 would just produce integer values in the range.

restart;

randomize():

with(plots):

setoptions(size=[500,200]);

N := 10:

L:=LinearAlgebra:-RandomVector(N,generator=-5.0..5.0):

listplot(L);

F1 := Statistics:-NonlinearFit( a*cos(e*x+d)+b*x+c, <$1..N>, L, x
                                , parameterranges=[a=-5..5, d=-Pi..Pi]
                                , initialvalues=[e=ceil(1/2*N/Pi)]
                              );

HFloat(2.946500373957529)*cos(HFloat(1.660098536783793)*x+HFloat(1.972035777846103))+HFloat(0.03533616937042544)*x-HFloat(0.4678613378149076)

display(listplot(L), plot(F1,x=1..N));

Download Mma_trans_01.mw

Your original example can be handled like so:

f:=x^2 - y^2+Pi;

               2    2     
         f := x  - y  + Pi

indets(f,And(name,Not(constant)));

              {x, y}

A variant, to disregard "dummy" variables (or integration, summation, say),

f := int(h(s),s=1..t) + x^2 - y^2 + Pi + gamma + Catalan;

int(h(s), s = 1 .. t)+x^2-y^2+Pi+gamma+Catalan

indets(f,name);

{Catalan, Pi, gamma, s, t, x, y}

indets(f,And(name,Not(constant)));

{s, t, x, y}

indets(f,And(name,Not(constant),
             satisfies(u->depends(f,u))));

{t, x, y}

Download indets_name_1.mw

The DEplot command is solving the ode numerically. That incurs small numeric error, which is not unexpected.

But if the approximated solution of y(t) goes even slightly outside of your forced restricted range y=-1..1 then the numeric solving (and, here, DEplot which calls it) halts.

Try it without the enforced range on y.

ode := diff(y(t), t$2) + y(t)=0;
DEtools:-DEplot(ode, y(t), t=0 .. 3*Pi,
                [[y(0)=1,D(y)(0)=0]],linecolor=blue);

Or, you could use the option obsrange=false.

DEtools:-DEplot(ode, y(t), t=0 .. 3*Pi,
                y=-1..1,
                obsrange=false,
                [[y(0)=1,D(y)(0)=0]],linecolor=blue);

This is the same underlying issue as in your Question of Dec 14, 2025.

ps. In this later example, the fact that it happens to work with t=0..round(3*Pi) is somewhat of a fluke -- the sampled points just happen to not stray just outside your supplied strict y-range.
pps. I am not sure why your previous example didn't motivate you to use obsrange=false if you are going to supply a forced, tight y-range.

Another possibility for programatically stacking items/lines that appear at the bottom is to use the caption option.

IIRC stacked items can also be justified or aligned (by the colored lines, or even the equal-signs), possibly using an html-ish mtable, but I'd have to search old notes for how I did that programatically.
 

restart;

Mf := proc(e::uneval,c) uses Typesetting;
  mrow(mn(cat(" "," "$42," "),':-mathbackground'=c,':-size'=3),
       mn("  "), eval('Typeset'('e'=eval(e)))); end proc:

 

plots:-setoptions(captionfont=[TIMES,4], font=[TIMES,16], labelfont=[TIMES,18]):

 

f := x -> x^3-x^2+1:
g := x -> 6-2*x-x^2:

 

plot([f(x),g(x)],x=-5..5,
     'gridlines', 'color'=['red','blue'],
     'caption'=typeset("\n", Mf(f(x),red), "\n", Mf(g(x),blue) ),
     'captionfont'=[TIMES,13],
     'title'="\nPlot of f(x) and g(x)\n", 'scaling'='unconstrained');


Download caption_for_legend.mw


ps. This comes out of old idea to use caption for getting legend effects
on 3D plots.
pps. On a side note, does captionfont work with setoptions? I'll check, and submit an scr if needed. 

The left-quotes are not necessary.

The 2D Input can be done just be using a single right-quote (apostrophe) for the prime.

One can even change a setting so that the derivatives appear in prime-notation in 2D Output.

restart


Prime notation can be used directly in 2D Input mode, without
needing any single left-ticks (aka name-quotes).

It parses this as containing derivatves, by default.

diff(y(x), x, x) = diff(y(x), x)+y(x)+sin(x)

diff(diff(y(x), x), x) = diff(y(x), x)+y(x)+sin(x)


The independent variable is presumed on the y-prime.

But, see above, we can also write the application to "x"
explicitly, without getting an unwanted double application.

diff(f(x), x, x)+diff(g(x), x)

diff(diff(f(x), x), x)+diff(g(x), x)

Typesetting:-Settings(prime)

x

Typesetting:-Settings(prime = s)

diff(f(x), x, x)+diff(g(x), x)

diff(diff(f(s), s), s)+diff(g(s), s)

restart


We can also change a setting so that the prime notation gets
used for pretty-printing, ie. 2D Output.

Typesetting:-Settings(typesetprime = true)

diff(y(x), x, x) = diff(y(x), x)+sin(x)

diff(diff(y(x), x), x) = diff(y(x), x)+sin(x)

lprint(%)

diff(diff(y(x),x),x) = diff(y(x),x)+sin(x)

dsolve([%, y(0) = 0, (D(y))(0) = 0])

y(x) = (1/2)*exp(x)-(1/2)*sin(x)+(1/2)*cos(x)-1

restart


The reason it works by default for input is because of this default setting.

If we turn it off then it doesn't parse this as derivatives.

Typesetting:-Settings(useprime)

true

Typesetting:-Settings(useprime = false)

diff(y(x), x, x) = diff(y(x), x)+y(x)+sin(x)

`y''`(x) = `y'`(x)+y(x)+sin(x)

lprint(%)

`y''`(x) = `y'`(x)+y(x)+sin(x)


Download typeset_prime_2D.mw

Yes, when simplify manipulates an active (non-inert) limit call then transformations it makes produce new active limit calls -- which evaluate as usual.

That's not unusual. It happens (sometimes very productively) for active int calls as well.

Here limit might not be able to handle an expression with, say, tan&sec forms. That's a limit weakness more than it is a dsolve weakness. Your phrase, "...since dsolve could not find limit..." suggests that you're blaming dsolve for limit's weakness -- which would be a mistake.

If you convert this sol result to sincos, and then evaluate that, then limit can compute that the limit is undefined. Eg,
     eval(convert(sol,sincos))
There's no completely general reason for simplify not to attempt that kind of transformation, and in doing so allow limit to attain an explicit result that it couldn't get for the original form.

Ideally, limit itself could have found that result (including when dsolve calls it to do that task).

The following code may illustrate limit's failure (under dsolve) and then later its success when simplify forces transformations (which limit itself might ideally have tried originally, etc):

ode:=4*x*diff(y(x),x$2)+2*diff(y(x),x)+y(x)=(6+x)/x^2;
IC:=y(infinity)=0;

trace(limit);

sol:=dsolve([ode,IC],y(x));

simplify(sol);

Now, it can happen that MultiSeries:-limit can find an explicit undefined result directly from the expression containing the tan form. If a limit call would return that then dsolve could return NULL. (Again, this is about weakness in what :-limit may FAIL on, more than what dsolve's doing here.)

restart;
ode:=4*x*diff(y(x),x$2)+2*diff(y(x),x)+y(x)=(6+x)/x^2;
IC:=y(infinity)=0;

unprotect(limit):
limit:=MultiSeries:-limit:
protect(limit):
trace(limit):

sol:=[dsolve([ode,IC],y(x))];

That seems weird. I think you could submit a bug report on that.

ps. consider y(x) = exp(-x)  (which I got by looking at it...)

ode:=diff(y(x),x$2)-2*diff(y(x),x)+y(x)=4*exp(-x);

diff(diff(y(x), x), x)-2*(diff(y(x), x))+y(x) = 4*exp(-x)

IC:=y(infinity)=0;

y(infinity) = 0

odetest( y(x)=exp(-x), [ode,IC] );

[0, 0]

Download de_inf_ex.mw

Do you mean this one?

proc(f,x,y,ndata,nvars)
   local G,init,nparams,k;
   nparams := nops(f);
   init := `if`(type(x, 'Vector'), (i,j)->evalf(f[j](x[i])),
                  (i,j)->evalf(f[j](seq(x[i,k], k=1..nvars))));
   G := Matrix(ndata, nparams, 'datatype'=float, init);
   LinearFitting:-LinearLS(y, G, ndata, nparams, args[6..-1]);
end proc;

I think that it might be a local of an unnamed(?) module which also contains an overloaded LinearFit (to which the export LinearFit of Statistics:-Regression somehow refers...).

You can enter it, in a debugger run of a LinearFit call, and list its contents.

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