acer

32722 Reputation

29 Badges

20 years, 86 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

The effect you're seeing is the effect of uniquification by the Maple kernel. It's not just about the display of the expression; it's about how Maple stores its unique structural representation in memory.

The effect you're seeing is the fundamental storing and unique representation that the Maple kernel does for the  Directed Acyclic Graph (DAG) representations of expressions it has a session. It stores the DAGs in a hashed data structure. That structure is sometimes called the "simpl" table.

Yes, this is to ensure that all equivalent expressions are stored only once in memory. But it is not a table in the usual sense for the Maple language, and there is no general purpose, direct access mechanism to it for the user.

It is not a "remember table", which is a feature of PROC DAGs. Those are accessible as a table. It is not that. There is no remember table to forget.

The sort command allows for some in-place replacement of the representation of an object in that internal "simpl" table. If the unique representation is changed, then it appears changed anywhere else where that very same DAG is accessed/pointed-to, or in any new created DAG that contains it. But the sort command only allows one to sort with respect to certain kinds of expression.

If your use of eval returns an expression whose DAG contains an already existing/simpl'd DAG then the new instance of the (sub)expression will be the same as what was already simpl'd.

Some examples,

restart;

foo := x^2 + y^2 + z^2 + 3:

bar := foo = 31:

foo;
bar;

x^2+y^2+z^2+3

x^2+y^2+z^2+3 = 31

sort( foo, order=plex(y,x,z) );

y^2+x^2+z^2+3

# the sorted foo is the same wherever it
# "exists" identically. So bar has also changed.
foo;
bar;

y^2+x^2+z^2+3

y^2+x^2+z^2+3 = 31

sort( foo, order=plex(z,y,x) );

z^2+y^2+x^2+3

foo;
bar;

z^2+y^2+x^2+3

z^2+y^2+x^2+3 = 31

goo := (z-3)^2 + (y+4)^2 + (x-1)^2 - 56 = 0;

(z-3)^2+(y+4)^2+(x-1)^2-56 = 0

# We can see that the sorting affects the SUMs which
# are polynomial in the specified variables.
# The operands of the `^` calls are such, here, but the
# lhs of goo itself is not.
sort( goo, order=plex(x,y,z), ascending );

(-3+z)^2+(4+y)^2+(-1+x)^2-56 = 0

sort( goo, order=plex(x,y,z) );

(z-3)^2+(y+4)^2+(x-1)^2-56 = 0

# we cannot specify these are the plex order.
sort( goo, order=plex( (x-1)^2), (y+4)^2, (z-3)^2 );

Error, invalid arguments to sort

woo := F((z-3)^2) + F((y+4)^2) + F((x-1)^2) - 56 = 0;

F((z-3)^2)+F((y+4)^2)+F((x-1)^2)-56 = 0

# ...but we can specify these function calls as the plex order.
sort( woo, order=plex( F((x-1)^2), F((y+4)^2), F((z-3)^2) ) );

F((x-1)^2)+F((y+4)^2)+F((z-3)^2)-56 = 0

# So now we could just make the calls to F print
# like its bare arguments.
# See earlier instance of this same question.


Download sort_fun_2.mw


You can't get around the uniquification just by recreating the
expression (including by substitution or by 2-argument eval).

restart;

(z-3)^2 + (y+4)^2 + (x-1)^2 - 56 = 0;

(z-3)^2+(y+4)^2+(x-1)^2-56 = 0

eval( A+B+C-56, [A=(x-1)^2,B=(y+4)^2,C=(z-3)^2] );

(z-3)^2+(y+4)^2+(x-1)^2-56

restart;

(x-1)^2 + (y+4)^2 + (z-3)^2 - 56 = 0;

(x-1)^2+(y+4)^2+(z-3)^2-56 = 0

eval( A+B+C-56, [A=(z-3)^2,B=(y+4)^2,C=(x-1)^2] );

(x-1)^2+(y+4)^2+(z-3)^2-56

# The following SUM DAG already appears in the EQUATION DAG later
# below, and is itself stored in the simpl table.
# Also, attempting to recreate an equivalent of that SUM with
# reordered addends will result in unification that produces
# the already stored DAG.

dismantle( (z-3)^2 + (y+4)^2 + (x-1)^2 - 56 );


SUM(9)
   PROD(3)
      SUM(5)
         NAME(4): x
         INTPOS(2): 1
         INTNEG(2): -1
         INTPOS(2): 1
      INTPOS(2): 2
   INTPOS(2): 1
   PROD(3)
      SUM(5)
         NAME(4): y
         INTPOS(2): 1
         INTPOS(2): 4
         INTPOS(2): 1
      INTPOS(2): 2
   INTPOS(2): 1
   PROD(3)
      SUM(5)
         NAME(4): z
         INTPOS(2): 1
         INTNEG(2): -3
         INTPOS(2): 1
      INTPOS(2): 2
   INTPOS(2): 1
   INTNEG(2): -56
   INTPOS(2): 1
 

dismantle((x-1)^2 + (y+4)^2 + (z-3)^2 - 56 = 0);


EQUATION(3)
   SUM(9)
      PROD(3)
         SUM(5)
            NAME(4): x
            INTPOS(2): 1
            INTNEG(2): -1
            INTPOS(2): 1
         INTPOS(2): 2
      INTPOS(2): 1
      PROD(3)
         SUM(5)
            NAME(4): y
            INTPOS(2): 1
            INTPOS(2): 4
            INTPOS(2): 1
         INTPOS(2): 2
      INTPOS(2): 1
      PROD(3)
         SUM(5)
            NAME(4): z
            INTPOS(2): 1
            INTNEG(2): -3
            INTPOS(2): 1
         INTPOS(2): 2
      INTPOS(2): 1
      INTNEG(2): -56
      INTPOS(2): 1
   INTPOS(2): 0
 

Download sort_fun_3.mw

restart;

kernelopts(version);

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

ode := diff(y(x),x) +cos(1/exp(2*x))*y(x) = sin(1/exp(x)):

IC := a*D(y)(x0)+ c*y(x0) = b*y0:

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

y(x) = (Int(sin(exp(-_z1))*exp(-(1/2)*Ci(exp(-2*_z1))), _z1 = x0 .. x)+(sin(cosh(x0)-sinh(x0))*a-b*y0)/(cos(cosh(2*x0)-sinh(2*x0))*cosh((1/2)*Ci(cosh(2*x0)-sinh(2*x0)))*a+cos(cosh(2*x0)-sinh(2*x0))*sinh((1/2)*Ci(cosh(2*x0)-sinh(2*x0)))*a-c*cosh((1/2)*Ci(cosh(2*x0)-sinh(2*x0)))-c*sinh((1/2)*Ci(cosh(2*x0)-sinh(2*x0)))))*exp((1/2)*Ci(exp(-2*x)))

the_residue:=odetest(maple_sol,[ode,IC]);

[0, -exp((1/2)*Ci(exp(-2*x0)))*(-y(x0)*cos(exp(-2*x0))*a+sin(cosh(x0)-sinh(x0))*a+c*y(x0)-b*y0)/((cosh((1/2)*Ci(cosh(2*x0)-sinh(2*x0)))+sinh((1/2)*Ci(cosh(2*x0)-sinh(2*x0))))*(cos(cosh(2*x0)-sinh(2*x0))*a-c))]


There is y(x0) in the_residue.

 

So cannot we utilize maple_sol with x=x0 to replace that y(x0)?

simplify(eval(the_residue, eval(maple_sol, x=x0)));

[0, 0]


Alternatively, could we utilize eval(maple_sol, x=x0) to
substitute into the IC?

odetest(maple_sol, [ode, simplify(eval(IC, y=unapply(rhs(maple_sol),x)))]);

[0, exp((1/2)*Ci(exp(-2*x0)))*b*y0*(cos(exp(-2*x0))*a-c)/((cosh((1/2)*Ci(cosh(2*x0)-sinh(2*x0)))+sinh((1/2)*Ci(cosh(2*x0)-sinh(2*x0))))*(cos(cosh(2*x0)-sinh(2*x0))*a-c))-b*y0]

simplify(%);

[0, 0]


Note,

odetest(maple_sol, ode);

0


Note, under maple_sol, the IC also simplify to just this,

 

simplify( convert(eval(IC, y=unapply(rhs(maple_sol),x)),exp) )

b*y0 = b*y0

Download nm_ode_ex1.mw

You could try the option,

    obsrange=false


Is there a reason that you don't use plots:-odeplot instead, or allow for any adjustments to control the error?

The enlargement of the y-range that allows this particular example to work as you expected (without obsrange=false) seems much smaller than 10% which you used.

Also, you haven't supplied an example in which you need the y-range. You've claimed that you sometimes run into issue without it, but haven't provided examples.

ps. Is there a specific reason for all that `op` and `originalview` stuff, as opposed to, say, using plottools:-getdata with its rangesonly option?

Some years ago the so-called "typesetting rule" for some special functions (like the Bessel family) was changed from true to false by default.

That Help page you've cited appears to not have been updated accordingly.

But you can still enable it using:

  Typesetting:-EnableTypesetRule("BesselJ")

(or, I suspect, by using the RuleAssistant dialog from that same package).

restart;

with(Typesetting)

interface(typesetting = extended)

H1 := Typeset(BesselJ(v, x))

Typesetting:-mrow(Typesetting:-mi("BesselJ", fontstyle = "normal"), Typesetting:-mo("⁡"), Typesetting:-mfenced(Typesetting:-mi("v"), Typesetting:-mi("x")))

lprint(H1)

Typesetting:-mrow(Typesetting:-mi("BesselJ",fontstyle = "normal"),Typesetting:-
mo("⁡"),Typesetting:-mfenced(Typesetting:-mi("v"),Typesetting:-mi
("x")))

NULL

BesselJ(v, x)

BesselJ(v, x)

QueryTypesetRule("BesselJ")

{"BesselJ" = false}

EnableTypesetRule("BesselJ")

QueryTypesetRule("BesselJ")

{"BesselJ" = true}

BesselJ(v, x)

BesselJ(v, x)

H2 := Typeset(BesselJ(v, x))

Typesetting:-mrow(Typesetting:-msub(Typesetting:-mi("J", fontstyle = "normal", Typesetting:-msemantics = "BesselJ"), Typesetting:-mi("v")), Typesetting:-mo("⁡"), Typesetting:-mfenced(Typesetting:-mi("x")))

lprint(H2)

Typesetting:-mrow(Typesetting:-msub(Typesetting:-mi("J",fontstyle = "normal",
Typesetting:-msemantics = "BesselJ"),Typesetting:-mi("v")),Typesetting:-mo(
"⁡"),Typesetting:-mfenced(Typesetting:-mi("x")))

NULL


Download Typeset_ac.mw

Those errors all occur in Maple 2024.2

But in Maple 2023.2.1 they get solved (and they solutions satisfy the equations).

Here's another shot at the integral, with a check, if we consider tau to be real-valued.

The result is attained in that first line of computation.

The result prints reasonably nicer in the actual Maple GUI, and computation is overall reasonably quick.

restart;

kernelopts(version);

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

integrand:=-3*(Pi-2*arcsin(tau))
           *(tau+1)^(1/2)*(tau+(tau^2-1)^(1/2))^(2*(tau^2-1)^(1/2)/(tau-1)^(1/2)/(tau+1)^(1/2))*(tau-1)^(1/2)
           *(-16/3*tau^2+Pi-2*arcsin(tau)+8/3)/(4*tau^2-4):

 

ans := piecewise(
  tau<-1, (simplify(int(expand(evala(combine(simplify(integrand)))),tau)) assuming tau<-1),
  tau>-1, (simplify(int(expand(evala(combine(simplify(integrand)))),tau)) assuming tau>-1));

ans := piecewise(tau < -1, (((6+4*I-12*tau^2)*arcsin(tau)^2+(12*Pi*tau^2-2-(6+4*I)*Pi)*arcsin(tau)+(16*tau^4-(16+12*I)*tau^2+6*I)*arccos(tau)+(4*I)*tau^4+(-3*Pi^2+6-4*I)*tau^2+(3/2+I)*Pi^2-3+I*(1/2))*sqrt(tau^2-1)-(4*(tau+1))*(-3*arcsin(tau)^2+3*Pi*arcsin(tau)+(4*tau^2-2-3*I)*arccos(tau)+I*tau^2-3*Pi^2*(1/4)+3/2-I*(1/2))*(tau-1)*tau)/(4*sqrt(tau^2-1)), -1 < tau, -(3*((1/6+(1/3)*(4*(tau^2-3*arccos(tau)-1/2))*tau*sqrt(tau^2-1)+4*arcsin(tau)^2*(1/3)-4*Pi*arcsin(tau)*(1/3)+(2*(-2*tau^2+1))*arccos(tau)+4*tau^4*(1/3)-4*tau^2*(1/3)+(1/3)*Pi^2)*sqrt(-tau^2+1)+((2*(2*tau^2-1))*arcsin(tau)^2+(2*(1/3-2*Pi*tau^2+Pi))*arcsin(tau)+(1/3)*(16*(-tau^4+tau^2))*arccos(tau)+(tau^2-1/2)*(Pi^2-2))*sqrt(tau^2-1)+(tau+1)*(tau-1)*(-16*arccos(tau)*tau^2*(1/3)+Pi^2-4*Pi*arcsin(tau)+4*arcsin(tau)^2+8*arccos(tau)*(1/3)-2)*tau))/(4*sqrt(tau^2-1)))

simplify(combine(integrand - diff(ans,tau))) assuming tau < -1

0

simplify(combine(integrand - diff(ans,tau))) assuming tau > -1

0

Download nm_int.mw

There are some variants, trading off, say, continuity at (some) points versus compactness, according to piecewise constants for the three regions obtainable by splits at tau=-1 and tau=1.

The reason you didn't see the effect on your plot3d result is that none of the input points has alpha in that same problematic range as has your plot result.

Your plot3d result has a range of 0..15 for alpha. And the default grid size is 49x49. However, none of these 49 generated values for alpha in that special range just below 0.1.

seq(0 .. 15.0, numelems = 49);

   0, 0.3125000000, 0.6250000000, 0.9375000000, 1.250000000, 
     1.562500000, 1.875000000, 2.187500000, 2.500000000, 
     2.812500000, 3.125000000, 3.437500000, 3.750000000, 
     4.062500000, 4.375000000, 4.687500000, 5.000000000, 
     5.312500000, 5.625000000, 5.937500000, 6.250000000, 
     6.562500000, 6.875000000, 7.187500000, 7.500000000, 
     7.812500000, 8.125000000, 8.437500000, 8.750000000, 
     9.062500000, 9.375000000, 9.687500000, 10.00000000, 
     10.31250000, 10.62500000, 10.93750000, 11.25000000, 
     11.56250000, 11.87500000, 12.18750000, 12.50000000, 
     12.81250000, 13.12500000, 13.43750000, 13.75000000, 
     14.06250000, 14.37500000, 14.68750000, 15.00000000

Note that your RootOf expression contains no information that would indicate to fsolve (which is called by `evalf/RootOf`) which root is desired, or what range to compute over or take initial values from, etc.

But you could add a range descriptor to the RootOf. In this example it happens that we can figure out that the roots are either negative or positive, for your range of alpha. So that helps.

Note that in your original example fsolve gets called (for each numeric alpha value) without any specified range. But in the edit below it gets called with the range 0.0..infinity, and only the positive roots get found.

restart

a := RootOf(JacobiCN(sqrt(2)*sqrt(alpha), (1/2)*sqrt(2)*_Z)^2*_Z^2+_Z^2-2, 0. .. infinity)

plot(a, alpha = 0 .. .5)

NULL

Download plot_of_RootOf_ac.mw

You can verify my explanation by setting trace(fsolve) and then calling it like the following (for your original RootOf without range descriptor, and also for my edit that has it),
    plot(a, alpha=0..0.5, adaptive=false, numpoints=7)

And you can verify my comments about plot3d in a variety of ways (including specifying the very same alpha range, or increasing the grid, etc).

Here attached are a few approaches. But first a few notes:

I don't yet see a nice+easy+sensible+robust way to "simplify" more general things like,
    2 - cos(x)^2 - cos(y)^2
into,
    sin(x)^2 + sin(y)^2
without also clobbering standalone terms like cos(v)^2 into becoming 1-sin(v)^2 undesirably.

Part of that relates to the fact that simplify doesn't use directly measured expression size and comparison as its main/only aspect for all mathematical simplification (trig, radicals, etc). The purer size compression & comparison focus is more for arithmetic/polynomial restructuring (ie, `simplfy/size` which it now does as a finishing/polishing step).

I wonder whether the procedure K below might be more generally useful to the OP than the other approaches attached. That just allows simplify to do its thing, then patches up that csgn split, after-the-fact.

So, fwiw,

restart;

H := proc(expr) local a,b;
       applyrule(b::anything*cos(a::anything)^2-b::anything=-b*sin(a)^2,
                 applyrule(b::anything-b::anything*cos(a::anything)^2=b*sin(a)^2,
                 expr)); end proc:

 

K := proc(expr) local a;
       applyrule(csgn(a::anything)*a::anything=(a^2)^(1/2),simplify(expr)); end proc:

 

R := expr->simplify(expr,(u->1-cos(u)^2=sin(u)^2)~(op~(indets(expr,specfunc(name,cos))))):

 

ee := sqrt( 1 + sqrt(-cos(s)^2 + 1) - cos(t)^2 + cos(v)^2 );

(1+(-cos(s)^2+1)^(1/2)-cos(t)^2+cos(v)^2)^(1/2)

simplify(ee, trig);

(cos(v)^2+csgn(sin(s))*sin(s)+sin(t)^2)^(1/2)

R(ee);

(sin(t)^2-sin(v)^2+(sin(s)^2)^(1/2)+1)^(1/2)

H(ee);

(sin(t)^2+(sin(s)^2)^(1/2)+cos(v)^2)^(1/2)

K(ee);

(sin(t)^2+(sin(s)^2)^(1/2)+cos(v)^2)^(1/2)

 

ff := sqrt( P + sqrt(-cos(z)^2 + 1)*q - P*cos(x)^2
            +  sqrt(cos(y)^2 + W - 1) +  cos(v)^2);

(P+(-cos(z)^2+1)^(1/2)*q-P*cos(x)^2+(cos(y)^2+W-1)^(1/2)+cos(v)^2)^(1/2)

simplify(ff, trig);

(csgn(sin(z))*sin(z)*q+sin(x)^2*P+cos(v)^2+(-sin(y)^2+W)^(1/2))^(1/2)

R(ff);

(sin(x)^2*P+(sin(z)^2)^(1/2)*q-sin(v)^2+(-sin(y)^2+W)^(1/2)+1)^(1/2)

H(ff);

(sin(x)^2*P+(-sin(y)^2+W)^(1/2)+cos(v)^2+(sin(z)^2)^(1/2)*q)^(1/2)

K(ff);

(sin(x)^2*P+(-sin(y)^2+W)^(1/2)+cos(v)^2+(sin(z)^2)^(1/2)*q)^(1/2)

Download simp_trig_ex9.mw

In the Maple 2025 ribbon, choose,

    Edit -> Editing -> User Profile

and in the pop-up dialog that appears choose "Engineering Notation" from the drop-menu.

Then close that with Apply And Set As Default

After that, in newly opened sheets you should get it by default.

There are several approaches that won't work, and some that will.

Which you choose might depend on whatever else your code might do.

restart;

max( 2*Unit(kg), 3.1*Unit(kg) );

max(2*Units:-Unit(kg), 3.1*Units:-Unit(kg))

restart;

max( 2*kg, 3.1*kg );

max(2*kg, 3.1*kg)

restart;

with(Units:-Simple):

max( 2*kg, 3.1*kg );

max(2*kg, 3.1*kg)

 

restart;

with(Units:-Simple):

max( 2*Unit(kg), 3.1*Unit(kg) );

3.1*Units:-Unit(kg)

restart;

Units:-Simple:-max( 2*Unit(kg), 3.1*Unit(kg) );

3.1*Units:-Unit(kg)

Download max_units.mw

As the error message indicates, the intersection command expects the first argument to be a name.

Note that the passed name H gets assigned a value, during the first call to intersection.

Then, in your problematic second attempt, intersection receives the value assigned to H rather than the unevaluated name H. That's due to Maple's usual rules for up-front evaluation of arguments passed to procedure calls

You could instead pass 'H', within unevaluation quotes (ie. single right-ticks), if you want to re-use that name.

restart

with(geometry)

line(l1, x = 0, [x, y]), line(l2, x+y = 1, [x, y])

circle(c, x^2+y^2 = 1, [x, y])

intersection(G, l1, l2)

G

intersection(H, l2, c, [M, N])

[M, N]

detail(H)

[GeometryDetail(["name of the object", M], ["form of the object", point2d], ["coordinates of the point", [0, 1]]), GeometryDetail(["name of the object", N], ["form of the object", point2d], ["coordinates of the point", [1, 0]])]

line(l2, x+y = 1.1, [x, y])

l2

intersection(H, l2, c, [M, N])

Error, (in geometry:-intersection) the first argument is expected of type name

H

[M, N]

intersection('H', l2, c, [M, N])

[M, N]

detail(H)

[GeometryDetail(["name of the object", M], ["form of the object", point2d], ["coordinates of the point", [.1055902790, .9944097210]]), GeometryDetail(["name of the object", N], ["form of the object", point2d], ["coordinates of the point", [.9944097208, .1055902792]])]

NULL

Download Test_intersection_ac.mw

The result from detail don't print properly when the worksheet is inlined on this forum, but in the actual Maple GUI the updated data is shown.

This technique of quoting a name -- to protect it from unwanted evaluation -- also arises for other commands that act on a supplied name with the side-effect of assigning some value. For example,

restart;

coeffs(x^2 - 17*x - 3, x, s);

1, -17, -3

s;

x^2, x, 1

coeffs(x^3 - x^2 + 4, x, s);

Error, invalid input: coeffs expects between 1 and 3 arguments, but received 5

coeffs(x^3 - x^2 + 4, x, 's');

1, -1, 4

s

x^3, x^2, 1

Download side_effect.mw

Here is a Maple sheet that illustrates a pitfall, and a couple of alternatives.

Let us know if aspects are still unclear.
 

restart

eq3 := M[a] + M[8] = 2.109e7:

eq4 := M[a] = 1e7:

raw := solve([eq3,eq4],{M[8],M[a]})

{M[8] = 11090000., M[a] = 10000000.}

raw[1];

M[8] = 11090000.


This is analogous to what went wrong in your Maple Flow sheet.
You were attempting to assign to name M[8] an equation that
actually contains M[8]. That'd lead to an infinite recursion error.

 

M[8] := raw[1]

Error, recursive assignment

M[8] := M[8] = 1.1090000*10^7

Error, recursive assignment

 


Here is one way to pick off the value for M[8] in the solution
returned by solve. This could be used programatically. So,
one alternative is to not do any actual assignment to M[8].

(I usually prefer this approach, since I can evaluate any compound
formula using the solved values. But I can also still look at the equations
without the substitution.)

eval(M[8], raw)

11090000.


Now, on to doing the assignment:

As a first way, you could write out the assignment, as an explicit statement.

Note that this is much better than indexing raw[1] which is not robust.
Positional reference like that is weaker than picking off the value via eval,
because if your variable names were ever changed then the relative
positions might change too (breaking the fragile code).

M[8] := eval(M[8], raw)

11090000.

M[8]

11090000.

M[a]

M[a]


Or, as a second way, you could get both the equations in raw to be
used for assignment.

assign(eval(raw,1)[])


Now both variables have been assigned.

That second way would have worked even without the first, explicit, assignment statement

M[a]

10000000.

M[8]

11090000.


Download solve_asn_rec.mw

 

ps. At the risk of partly repeating myself...
    M[8] := eval(M[8], raw);        # OK
    M[8] := rhs(raw[1]));             # poor

[edit]
Maple guards against a recursive assignment, as shown above. If you trick/force it, and then evaluate, you can see a similar error message to what you had from Maple Flow. I mention this just to illustrate the similarity. Eg,

restart

assign(M[8], M[8] = 1.1090000*10^7);

M[8];

Error, too many levels of recursion

Is this the kind of thing you're after, for the,
   MinMachineNumber
   MaxMachineNumber

restart;

kernelopts(version);

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

 

L:=[FLT_RADIX,DBL_MANT_DIG,DBL_DIG,DBL_EPSILON,DBL_MIN_EXP,DBL_MIN,
    DBL_MIN_10_EXP,DBL_MAX_EXP,DBL_MAX,DBL_MAX_10_EXP,LNMAXFLOAT]:

 

seq(lprint(nm=evalhf(nm)),nm=L);

FLT_RADIX = 2.
DBL_MANT_DIG = 53.
DBL_DIG = 15.
DBL_EPSILON = .222044604925031308e-15
DBL_MIN_EXP = -1021.
DBL_MIN = .100000010000000008e-306
DBL_MIN_10_EXP = -307.
DBL_MAX_EXP = 1024.
DBL_MAX = .99999999000000001e308
DBL_MAX_10_EXP = 308.
LNMAXFLOAT = 706.893000000000029

Download evalhf_const.mw

See the ?evalhf,constant Help page.

And for the "software" float case, you could look at the ?Maple_floats Help page. (But MAX_FLOAT divided by MIN_FLOAT would produce Float(infinity) in that context... as would DBL_MAX/DBL_MIN under evalhf.)

The union command merges sets.

In this example, you don't need union at all. You can just use {C4, C44} .

If C3 and C4 were themselves sets, then you could use {C4} union {C44} (and which would also work here).

restart

C1 := (Cr*Pr*d*rho0-Cr*d*delta*rho0+Ce*d*delta+Cr*d*rho0-c*d*delta+d*delta*w-delta*g*i2-Ce*d+2*Pr*rho0+a*delta+c*d-d*w-2*delta*rho0+g*i2-a+2*rho0)/(rho0*(Cr*d+2)) <= Pn; C11 := Pn <= (Cr*Pr*d*upsilon-Cr*d*delta*upsilon+Ce*d*delta+Cr*d*upsilon-c*d*delta+d*delta*w-delta*g*i2-Ce*d+2*Pr*upsilon+a*delta+c*d-d*w-2*delta*upsilon+g*i2-a+2*upsilon)/(upsilon*(Cr*d+2))

`&Pi;m` := (Pn-Cn)*(1-(Pn-Pr)/(1-delta))+(Pr-w-Crm)*alpha*((((-a+0.4e-1*g)*Cr-c-(-2*a*d*delta+0.6e-1*d^2+0.3e-1*Cr*alpha*d^2*rho0^2+Cn*Cr*d^2*rho0-Cr*Pr*d^2*rho0+Cr*d^2*delta*rho0+2*Crm*alpha*d*rho0^2-2*Pr*alpha*d*rho0^2-2*alpha*c*d*rho0^2+0.8e-1*d*delta*g+2*c*d^2*delta+2*d*delta*rho0+2*alpha*c*rho0^2-0.8e-1*alpha*g*rho0^2+2*Cn*d*rho0+0.6e-1*alpha*d*rho0^2+0.3e-1*Cr*d^2*rho0^2-2*Pr*d*rho0-Cr*d^2*rho0+Cr*Crm*alpha*d^2*rho0^2-Cr*Pr*alpha*d^2*rho0^2-Cr*alpha*c*d^2*rho0^2+Cr*alpha*c*d*rho0^2-0.4e-1*Cr*alpha*d*g*rho0^2+2*a*d-2*c*d^2-0.6e-1*d^2*delta+0.6e-1*d*rho0^2-0.8e-1*d*g-2*d*rho0)/(2*d*(Cr*alpha*d*rho0^2+2*alpha*rho0^2-d*delta+d))+0.3e-1)*d+0.4e-1*g-a)/(Cr*d+2)-0.4e-1*g+a)-(0.3e-1*(((-a+0.4e-1*g)*Cr-c-(-2*a*d*delta+0.6e-1*d^2+0.3e-1*Cr*alpha*d^2*rho0^2+Cn*Cr*d^2*rho0-Cr*Pr*d^2*rho0+Cr*d^2*delta*rho0+2*Crm*alpha*d*rho0^2-2*Pr*alpha*d*rho0^2-2*alpha*c*d*rho0^2+0.8e-1*d*delta*g+2*c*d^2*delta+2*d*delta*rho0+2*alpha*c*rho0^2-0.8e-1*alpha*g*rho0^2+2*Cn*d*rho0+0.6e-1*alpha*d*rho0^2+0.3e-1*Cr*d^2*rho0^2-2*Pr*d*rho0-Cr*d^2*rho0+Cr*Crm*alpha*d^2*rho0^2-Cr*Pr*alpha*d^2*rho0^2-Cr*alpha*c*d^2*rho0^2+Cr*alpha*c*d*rho0^2-0.4e-1*Cr*alpha*d*g*rho0^2+2*a*d-2*c*d^2-0.6e-1*d^2*delta+0.6e-1*d*rho0^2-0.8e-1*d*g-2*d*rho0)/(2*d*(Cr*alpha*d*rho0^2+2*alpha*rho0^2-d*delta+d))+0.3e-1)*d+0.4e-1*g-a))/(Cr*d+2)+0.12e-2*g-0.3e-1*a

DATA := [delta = .7, a = .2, d = .9, g = .3, c = 0.2e-1, sigma = .5, Cn = .35, Crm = .1, Cr = 0.1e-1, rho0 = .4, Pr = .6, alpha = .9, s = .21, upsilon = .95]

TRC := proc (Pn, w) options operator, arrow; eval(`&Pi;m`, DATA) end proc; C2 := subs(DATA, C1); C22 := subs(DATA, C11)

C3 := isolate(C2, w); C33 := isolate(C22, w)

t := {0.3e-1, 0.5e-1, 0.7e-1, 0.9e-1}; ts := {0.4e-1, 0.8e-1, .12}

M := Matrix(nops(t)*nops(ts), 3); rr := 0; for Ce in t do for i2 in ts do C4 := eval(C3, [Ce = t, i2 = ts]); C44 := eval(C33, [Ce = t, i2 = ts]); s := Optimization:-Maximize(TRC(Pn, w), {C4, C44}, Pn = 0 .. 1, w = 0 .. 1, assume = nonnegative); stemp := s[1]; Pntemp := s[2][1]; wtemp := s[2][2]; rr := rr+1; M[rr, 1 .. 3] := `<|>`(Ce, i2, stemp) end do end do

R := Array(ArrayTools:-Reshape(M,[3,4,3]),datatype=float[8]):

func := Interpolation:-SplineInterpolation([[0.04, 0.08, 0.12],[0.03, 0.05, 0.07, 0.09]],R[..,..,3]):

conts := [seq(min(R[..,..,3])..max(R[..,..,3]),(max(R[..,..,3])-min(R[..,..,3]))/8)]:

ContoursWithLabels:= proc(

ContoursWithLabels(func(x, y), x = 0.3e-1 .. .15, y = 0.2e-1 .. .1, contours = conts, decplaces = 4, Coloring = [colorstyle = HUE, colorscheme = ["Blue", "Gold"], style = surface], TextOptions = [font = [HELVETICA, BOLD, 9], color = black], GraphicOptions = [thickness = 0], ImplicitplotOptions = [gridrefine = 3], size = [700, 600], labels = [':-C__e', ':-i__2'], size = [350, 350])

 

 

Download Q_Constraint_error_ac.mw

Here are two ways of doing it, each showing both the difference and the ratio, in side-by-side plots.

restart; with(plots): setoptions(size=[500,200],style=pointline,labels=[x,""]);


First way, calling dsolve just once, and using a procedure to set the parameter value. Calling the dsolve-return at each x-value in the
target Vector.
 

de := diff(f(x),x,x) = -sin(a*x):

dsol:=dsolve({de,f(0)=1,D(f)(0)=1},numeric,parameters=[a],output=listprocedure):
Y := eval(f(x),dsol):

F := proc(aa::numeric) dsol(parameters=[aa]); Y~(A); end proc:

A := Array([seq(0..3,0.1)],datatype=float[8]):

display(Array([
  plot(A, F(7.1)-F(7.0), title=y[7.1](x)-y[7.0](x)),
  plot(A, F(7.1)/~F(7.0), title=y[7.1](x)/y[7.0](x), color="Navy") ]));

 

 

restart; with(plots): setoptions(size=[500,200],style=pointline,labels=[x,""]);


Second way, calling dsolve for each parameter value, and specifying the output option to the target Array of x-points.
 

de := diff(f(x),x,x) = -sin(a*x):

G := aa -> dsolve(eval({de,f(0)=1,D(f)(0)=1},':-a'=aa),numeric,output=A)[2,1][..,2]:

A := Array([seq(0..3,0.1)],datatype=float[8]):

display(Array([
  plot(A, G(7.1)-G(7.0), title=y[7.1](x)-y[7.0](x)),
  plot(A, G(7.1)/~G(7.0), title=y[7.1](x)/y[7.0](x), color="Navy") ]));

 

 

Download de_V.mw


There are even more ways of accomplishing this. I don't know whether you'd rather focus on simplicity, or flexibility, or performance.

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