acer

32562 Reputation

29 Badges

20 years, 24 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

You need to be careful about which command it is to which you're passing the annotation option.

Here are a few alternatives.

restart; plots:-setoptions(size=[300,300]);

trplot:=plottools:-transform((x,y)->[y,x]):

 

Be careful about your bracketing. Your original problematic attempt
passed the annotation option to the trplot transformer.

 

You can instead pass the annotation option to the actual plot
command, or apply it after transformation by passing it to a
wrapping plots:-display call.

 

trplot(plot((x-120)^2,x=115..130,
            annotation=typeset('xcoordinate'," s, ",
                               'ycoordinate'," % V/Hz")
           )
      );
 

plots:-display(trplot(plot((x-120)^2,x=115..130)),
               annotation=typeset('xcoordinate'," s, ",
                                  'ycoordinate'," % V/Hz")
              );
 


I can't tell whether your trplot transformation was intended
as just a toy example.

Note that you can get the flipped plot directly by using a
parametric calling-sequence of the plot command.
 

plot([(x-120)^2, x, x=115..130],
     annotation=typeset('xcoordinate'," s, ",
                        'ycoordinate'," % V/Hz"));
 

Download plot_annotation.mw

@C_R It was an old (very old) design idea of Typesetting to have the mo (operator) and mi (identifier) be used to denote things intended to be pretty-printed in upright or italics, respectively.

But quite a short while after its original implementation (itself now over 20 years ago) some operators began being pretty-printed in upright, even if forcibly put into an "mi" construct. I recall asking about it (15+ years ago...) and not getting far.

You can see also similar treatment (done purely by the GUI, for rendering) of names sin, cos, ln, etc.

The rendering done by the GUI overrides/disregards the "mi", whether in the form,
   `#mi("sin");`
or,
    Typesetting:-mi(sin)


nb. You can force the output by using the function-call form, with options, eg.

    Typesetting:-mi("D",mathvariant="italic")

but the compact name-form doesn't support all such options (mathcolor being an exception). I suspect that this is similar to how right-click conversion to Atomic Identifier doesn't do the reverse action either, ie. it ignores italic characters interspersed in a name.

The first of these can be made more programmatic (if an example's scales differ from this, etc).

restart;

with( DynamicSystems ):

sys := TransferFunction( 1/(s-10) ):

plots:-dualaxisplot(
   plots:-display(BodePlot(sys,output=phaseplot,
                           labels = ["\nFreq [rad/s]", "Phase [deg]\n"]),
                  plots:-polygonplot([[1000,-180],[1000,-90],
                                      [10^5,-90],[10^5,-180]],
                                     color=white,style=surface)),
   plots:-display(
      plottools:-transform((x,y)->[x*10^6,y])(BodePlot(sys,output=magnitudeplot,
                                                       color=blue)),
      labels = ["\nFreq [rad/s]", "\nMagnitude [dB]"],
      labeldirections=[horizontal,vertical]),
   axis[1]=[tickmarks=[seq(10^i=10.^i, i=[-1,0,1,2,3]),
                       seq(10^6*10^i=10.^i, i=[-1,0,1,2,3])],
            gridlines=[seq(10^i=10.^i, i=[-1,0,1,2,3]),
                       seq(10^6*10^i=10.^i, i=[-1,0,1,2,3])]],
   view=[0.1..10^9,default], size=[800,400]);
 

plots:-dualaxisplot(
 BodePlot(sys,output=phaseplot,
          axis[2]=[color="Burgundy"]),
 BodePlot(sys,output=magnitudeplot,color=blue,
          axis[2]=[color=blue]),
 axis[1]=[tickmarks=[seq(10^i=10.^i, i=[-1,0,1,2,3])]],
 size=[700,400])

 

 

Download bode_fun.mw

Why not directly pass in the extra inequalities, as part of the set of conditions, rather than supplying them as assumptions?

It's possible that if you specify, say, R__1 < R[c] as an assumption then the result might tacitly include/imply that. (I didn't see clarification on that aspect in documentation.)

restart;

kernelopts(version);

`Maple 2015.2, X86 64 LINUX, Dec 20 2015, Build ID 1097895`

V := r -> Pi*R[c]^2*(2*r) - 4/3*Pi*r^3:

'V'(R__1) - 'V'(R__2) = factor(V(R__1) - V(R__2));

V(R__1)-V(R__2) = -(2/3)*Pi*(R__1-R__2)*(2*R__1^2+2*R__1*R__2+2*R__2^2-3*R[c]^2)

F := op(-1, rhs(%));

2*R__1^2+2*R__1*R__2+2*R__2^2-3*R[c]^2

solve({F=0, R__2 >= 0, R__2 <= R[c],
       R[c] > 0, R__1 > 0, R__1 < R[c]}, R__2,
      'parametric'='full', parameters={R[c], R__1});

piecewise(And(0 < R[c], R__1 = -(1/2)*R[c]+(1/2)*sqrt(3)*sqrt(R[c]^2)), [[`#msub(mi("R"),mi("2"))` = R[c]]], And(0 < R[c], -(1/2)*R[c]+(1/2)*sqrt(3)*sqrt(R[c]^2) < R__1, R__1 < R[c]), [[`#msub(mi("R"),mi("2"))` = -(1/2)*`#msub(mi("R"),mi("1"))`+(1/2)*sqrt(-3*`#msub(mi("R"),mi("1"))`^2+6*R[c]^2)]], [])


Download PlotsInequal_vs_SolveParametric_ac2015.mw

You could create a Paragraph Style Set (adjusted to use your choice for text and 2D Input, say), and then use that as your default.

You could also make those adjustments be the default for a new (otherwise empty) Document/Worksheet, and set that as your default Start Page when opening a New Document/Worksheet.

Several entities can be inserted typeset for 2D Input by using command-completion, even if they are not directly available already in any of the Palettes.

restart

 

After typing a, in 2d Input mode, type
   nsube
and then hit the Escape key to get the command-completion
popup menu. Use the mouse to select  the desired symbol.
Then enter a space, and then type b, say.

 

`&nsube;`(a, b)

`&nsube;`(a, b)

lprint(%)

`&nsube;`(a,b)

 

After typing a, in 2d Input mode, type
   nsub
and then hit the Escape key to get the command-completion
popup menu. Use the mouse to select  the desired symbol.
Then enter a space, and then type b, say.

 

`&nsub;`(a, b)

`&nsub;`(a, b)

lprint(%)

`&nsub;`(a,b)

 

After typing a, in 2d Input mode, type
   cong
and then hit the Escape key to get the command-completion
popup menu. Use the mouse to select  the desired symbol.
Then enter a space, and then type b, say.

 

`&cong;`(a, b)

`&cong;`(a, b)

lprint(%);

`&cong;`(a,b)

 

After typing a, in 2d Input mode, type
   rarr
and then hit the Escape key to get the command-completion
popup menu. Use the mouse to select  the desired symbol.
(Or get it directly from the Arrows palette in left sidebar.)
Then enter a space, and then type b, say.

 

proc (a) options operator, arrow; b end proc

proc (a) options operator, arrow; b end proc


Download cmd_cmpl_ex.mw

In addition, you could produce just the `&cong;` as 2D-Input, and then select it with the left mouse-button, then use the right-click menu to convert it to "Atomic Variable", and then hit Enter so as to get that as output. The output could then be selected with the mouse and dragged into the Favorites palette. You could also do this for other entities, such as `&rarr;`, etc. And you just wanted to add them to the Favorites palette then you could also enter them in that plaintext input form, and drag their outputs similarly. You can find lists of HTML entities in several places, by web search.

There was a time when some of the names used for structured types were not protected. Ie, you could assign values to them, in which case type-checks involving them would break if you didn't prevent evauation with uneval-quotes (single right-ticks).

So it was commonplace to use 'specfunc', etc, quoted.

Some people like quoting the whole call, eg, 'specfunc(blah, foo)' even when it's not necessary and 'specfunc'(blah,foo) would do fine.

I dislike the first of those, because it's not carefully targeted. Your example is one where it goes awry, because it prevents the reference to the assigned local name y from evaluating.

I wish that the Help pages were more discriminating/targeted in use of quotes, vs merely blanket quoting.

restart;

foo:=proc(func::function(name),IC::`=`)
    local y::symbol:=op(0,func);
    indets(IC,'specfunc'(anything,y));
end proc:

foo(y(x),y(x)=0);

{y(x)}


Download delayed_vs_not.mw

The global name specfunc is protected in current versions (you can't assign to it), and there you don't need to quote it.

Here's a closer analog of your problematic example's issue, but done outside any procedure. You need indets to be able to see the assigned value of s. Note that your two original examples did not have a similar nature, even aside from one being in a procedure. The reason that they behaved differently is that in the procedure example you'd assigned something to the name used within the specfunc call. If you do that kind of similar thing outside of a procedure then it too would fail. (Your procedure's local and the expression's global were both named y, which perhaps made this key aspect about assignment less apparent to you.)

s := y;

            s := y

type( y(x), 'specfunc(s)' );

            false

type( y(x), 'specfunc'(s) );

            true

In your code's comments you wrote "same code fail". But it was not the same. In the failing procedure version you made an assignment and attempted to utilize it within the quoted portion. In your original failing procedure example the local named y could be also named something else, with identical failing behavior. Ie, here, indets does not receive something containing the value assigned to s, due to the overwide quoting. It's equivalent to your failing example.

foo:=proc(func::function(name),IC::`=`)
    local s::symbol:=op(0,func);
    indets(IC,'specfunc(anything,s)');
end proc:

foo(y(x),y(x)=0)

{}


In summary, what made your problematic example fail was not that it was the same code done inside a procedure. It failed because it was not the same code -- the name referenced inside the wide quotes was additionally assigned.


By the way, only some of the special names used for structured types are protected. In Maple 2024.2, for example,

restart;

kernelopts(version);

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

patfunc := 4;

4

specindex := 4;

Error, attempting to assign to `specindex` which is protected.  Try declaring `local specindex`; see ?protect for details.

anyindex := 4;

4

specfunc := 4;

Error, attempting to assign to `specfunc` which is protected.  Try declaring `local specfunc`; see ?protect for details.

Download types_prot.mw

You should (ideally) uneval-quote the ones which are not protected, to avoid problems if any such are ever later assigned. You can pretty much quote them all (and so avoid having to remember which...), if you place quotes around just the name and not some whole bracketed function-call.

An example with some exclusion,

restart;

expr:=y(3)+y(8)+5*(D@@2)(y)(4)+Pi+3*exp(2)+77*D(y)(0)+1/(D@@4)(y)(7);

y(3)+y(8)+5*((D@@2)(y))(4)+Pi+3*exp(2)+77*(D(y))(0)+1/((D@@4)(y))(7)

`type/De`;

And(function, `PDEtools/D`)

De := 11:

indets(expr, ':-De');

{(D(y))(0), ((D@@2)(y))(4), ((D@@4)(y))(7)}

#showstat(`type/PDEtools/D`);

expr2 := expr+D(y)(x)+(D@@2)(y)(x+s);

y(3)+y(8)+5*((D@@2)(y))(4)+Pi+3*exp(2)+77*(D(y))(0)+1/((D@@4)(y))(7)+(D(y))(x)+((D@@2)(y))(x+s)

indets(expr2, ':-De'); # not adequate

{(D(y))(0), (D(y))(x), ((D@@2)(y))(4), ((D@@2)(y))(x+s), ((D@@4)(y))(7)}

indets(expr2, And(':-De',Not(typefunc(Not(constant),anything))));

{(D(y))(0), ((D@@2)(y))(4), ((D@@4)(y))(7)}

indets(expr, And(':-De',Not(typefunc(Not(constant),anything))));

{(D(y))(0), ((D@@2)(y))(4), ((D@@4)(y))(7)}


Download type_D_fun.mw

You could tweak that Not type for the exclusion, but I'm not sure what other examples you might have.

nb. Note the use of the uneval-quotes around ':-De', to avoid a clash if that name has been assigned. And the best way in general is also to reference it with the colon-minus, ie. ':-De' because it might be declared local.

For r=3 you can look at 1-1/r=2/3.

And,

restart;

eq := r = 1 + sqrt(6);

r = 1+6^(1/2)

evalf(eq);

r = 3.449489743

d := (r - 3)*(r + 1);

(r-3)*(r+1)

F1 := eval( (r + 1 + sqrt(d))/(2*r), eq );

(1/2)*(2+6^(1/2)+((-2+6^(1/2))*(2+6^(1/2)))^(1/2))/(1+6^(1/2))

evalf(F1);

.8499377795

F2 := eval( (r + 1 - sqrt(d))/(2*r), eq );

(1/2)*(2+6^(1/2)-((-2+6^(1/2))*(2+6^(1/2)))^(1/2))/(1+6^(1/2))

evalf(F2);

.4399601689


Download lmap_fun.mw

You wrote "output", and it's not clear what you need. The above are exact values.

Are you asking for a reference? You could look at section 2 (or section 4, equation 14) of the PDF file here.

I suppose that there are several ways to get the plot, depending on which coordinate systems you'd rather use.

restart;

# radius and center of cylinder
(r,cx,cy) := 1/4,1/2,0;

1/4, 1/2, 0

plots:-display(
  plot3d(piecewise((x-cx)^2+(y-cy)^2<r^2,undefined,sqrt(1-x^2-y^2)),
       x=-1..1, y=-1..1,
       color=red,style=surface,grid=[200,200],transparency=0.5),
  plots:-spacecurve([r*cos(th)+cx,r*sin(th)+cy,
                     sqrt(1-(r*cos(th)+cx)^2-(r*sin(th)+cy)^2)],
                    th=0..2*Pi,color=yellow,thickness=5),
  plottools:-transform((x,y,z)->[x+cx,y+cy,ifelse(z>sqrt(1-(x+cx)^2-(y+cy)^2),
                                                     undefined,z)])(
    plot3d(r,th=0..2*Pi,z=0..1,grid=[201,201],coords=cylindrical,
           style=surface,color=cyan,transparency=0.5)),
  orientation=[-50,60,0],scaling=constrained,axes=normal,labels=["","",""]);


Download 3dplotfun.mw

The ImageTools:-Preview command uses a 3D plot and puts the image data on a flat plane and shows it oriented head-on, so that it looks like a flat 2D image.

The ImageTools:-Embed command embeds an image (as a GUI construct) into a so-called Task region, which as you've noticed always gets shown after the usual output portion of an Execution Group or Document Block (paragraph).

But since the ImageTools:-Preview command was devised, 2D plots got the ability to use an image with the background option. The resulting file is quite large when saved, but you might be OK with it scaled even smaller than 500 pixels wide.

restart;

with(ImageTools):

img := Read("download.png"):

newimg := Scale(img, 1..500):
(n,m) := (rhs-lhs+1)~([op(2,newimg)[1..2]])[]:

printf("Before image\n"):
plot(background=newimg, size=[m,n],':-axes'=':-none');
printf("After image\n"):

 

Download img_bg.mw

Using only uneval-quotes (ie, single right-ticks) here is not a robust way to prevent evaluation if you need to pass the expression (or a structure containing it) around in additional command/procedure calls.

The subsequent evaluations that occur for arguments of procedure calls will strip off uneval quotes, and produce the effect you're trying to avoid.

Instead, you could use an inert representation of the expression.

restart

with(plots)

f := InertForm:-Display('sqrt(888*s/(x*(3*y^2+1)))', inert = false)

Typesetting:-msqrt(Typesetting:-mfrac(Typesetting:-mrow(Typesetting:-mn("888"), Typesetting:-mo("&InvisibleTimes;"), Typesetting:-mi("s")), Typesetting:-mrow(Typesetting:-mi("x"), Typesetting:-mo("&InvisibleTimes;"), Typesetting:-mfenced(Typesetting:-mrow(Typesetting:-mrow(Typesetting:-mn("3"), Typesetting:-mo("&InvisibleTimes;"), Typesetting:-msup(Typesetting:-mi("y"), Typesetting:-mn("2"))), Typesetting:-mo("&plus;"), Typesetting:-mn("1"))))))

test := textplot([[2, 3, f, 'rotation' = (1/4)*Pi, 'font' = ["times", "roman", 15]]], 'view' = [1 .. 3, 0 .. 4], size = [300, 300])

display(test)

test

NULL

NULL

Download undesired_textplot_format_ac.mw

Is this the kind of effect you're after?

[note: Here I'm starting with the problematic indexed name being present.]

(It could be tweaked/adjusted... I don't know the extent of the kinds of indexes you'd need handled, etc. There are even much simpler/shorter ways, if you only want to handle names indexed by posint, etc.)

restart

Evaluation with `&varphi;`[0] indexed

K := proc (nm::indexed) local v, i, res; v := op(0, nm); i := op(nm); res := Typesetting:-msub(Typesetting:-Typeset(Typesetting:-EV(v)), subs(Typesetting:-mi = Typesetting:-mn, Typesetting:-Typeset(Typesetting:-EV(i)))); nprintf(`#%a;`, res) end proc; Rep := proc () options operator, arrow; subsindets([args], typeindex(algebraic, name), K)[] end proc

K(phi[0])

`#Typesetting:-msub(Typesetting:-mi("&phi;"),Typesetting:-mn("0"));`

K(phi[a, b, c])

`#Typesetting:-msub(Typesetting:-mi("&phi;"),Typesetting:-mrow(Typesetting:-mn("a"),Typesetting:-mo("&comma;"),Typesetting:-mn("b"),Typesetting:-mo("&comma;"),Typesetting:-mn("c")));`

eq := -t(0)+t(`&varphi;`(t)) = Int(1/sqrt(2*C*cos(`&varphi;`)-2*C*cos(`&varphi;`[0])), `&varphi;` = 0 .. `&varphi;`(t), continuous)

-t(0)+t(varphi(t)) = Int(1/(2*C*cos(varphi)-2*C*cos(varphi[0]))^(1/2), varphi = 0 .. varphi(t), continuous)

H := t(0) = 0, `&varphi;`(t) = `&varphi;`[0], t(`&varphi;`[0]) = (1/4)*T

t(0) = 0, varphi(t) = varphi[0], t(varphi[0]) = (1/4)*T

new := subs(H, eq)

(1/4)*T = Int(1/(2*C*cos(varphi)-2*C*cos(varphi[0]))^(1/2), varphi = 0 .. varphi[0], continuous)

cond := C > 0, 0 < `&varphi;`[0] and `&varphi;`[0] < Pi

0 < C, 0 < varphi[0] and varphi[0] < Pi

new2 := Rep(new)

ans := isolate(`assuming`([simplify(value(new2))], [Rep(cond)]), T)

T = 4*InverseJacobiAM((1/2)*`#Typesetting:-msub(Typesetting:-mi("&varphi;"),Typesetting:-mn("0"));`, csc((1/2)*`#Typesetting:-msub(Typesetting:-mi("&varphi;"),Typesetting:-mn("0"));`))*csc((1/2)*`#Typesetting:-msub(Typesetting:-mi("&varphi;"),Typesetting:-mn("0"));`)/C^(1/2)


I don't know whether you want the list of replacements.

With that, you can undo the effect.

You can create such a list to involve just the one indexed name, or any found.
Ie, you can make it as targeted as you want, in case there are other indexed
names that you're prfer lest alone.

S := indets([eq, H], typeindex(algebraic, name))

{varphi[0]}

S := indets([eq, H], specindex(integer, varphi))

{varphi[0]}

L := map(proc (s) options operator, arrow; K(s) = s end proc, {varphi[0]})

{`#Typesetting:-msub(Typesetting:-mi("&varphi;"),Typesetting:-mn("0"));` = varphi[0]}

L := map(proc (s) options operator, arrow; K(s) = s end proc, S)

{`#Typesetting:-msub(Typesetting:-mi("&varphi;"),Typesetting:-mn("0"));` = varphi[0]}

subs(L, ans)

T = 4*InverseJacobiAM((1/2)*varphi[0], csc((1/2)*varphi[0]))*csc((1/2)*varphi[0])/C^(1/2)

lprint(%)

T = 4/C^(1/2)*InverseJacobiAM(1/2*varphi[0],csc(1/2*varphi[0]))*csc(1/2*varphi[
0])


Or you could use such replacement lists instead of procedure Rep.

Lrev := map(proc (s) options operator, arrow; s = K(s) end proc, S)

{varphi[0] = `#Typesetting:-msub(Typesetting:-mi("&varphi;"),Typesetting:-mn("0"));`}

new3 := subs(Lrev, new)

isolate(`assuming`([simplify(value(new3))], [subs(Lrev, [cond])[]]), T)

T = 4*InverseJacobiAM((1/2)*`#Typesetting:-msub(Typesetting:-mi("&varphi;"),Typesetting:-mn("0"));`, csc((1/2)*`#Typesetting:-msub(Typesetting:-mi("&varphi;"),Typesetting:-mn("0"));`))*csc((1/2)*`#Typesetting:-msub(Typesetting:-mi("&varphi;"),Typesetting:-mn("0"));`)/C^(1/2)

NULL

``

Download Evaluation_of_elliptic_integrals_ac.mw

If you just need to handle this one single indexed name, then here is an easier substitution, ie. directly constructed:

L := { varphi[0] = `#msub(mi("varphi"),mn("0"));` }

{varphi[0] = `#msub(mi("varphi"),mn("0"));`}

Of course, if you only needed a single substitution for varphi[0] then you might as well use,

    varphi[0] = varphi__0

which is of course easier still(!) and which you already know to work OK. I wrote you the earlier code so that the approach might be used for more complicated subscripted expressions or situations (for which a mere double-underscore could not suffice), programmatically. I don't know your full scenario(s).

Is this not fundamentally similar to your Question of Sept 2nd?

restart;

ode:=diff(m(t),t) = -k/m(t)^2:
ic:=m(0) = m__0:

simplify([dsolve(ode)])[];

m(t) = (-3*k*t+c__1)^(1/3), m(t) = -(1/2)*(-3*k*t+c__1)^(1/3)*(1+I*3^(1/2)), m(t) = (1/2)*(-3*k*t+c__1)^(1/3)*(-1+I*3^(1/2))

dsolve([ode,ic]) assuming m__0>0;
dsolve([ode,ic]) assuming m__0<0;

m(t) = (m__0^3-3*k*t)^(1/3)

m(t) = (1/2)*(m__0^3-3*k*t)^(1/3)*(-1+I*3^(1/2))


Download why_dsolve_cant_solve_ode_oct_4_2025_maple_ac.mw

I prefer the eval(..,..) way, and the thing you've actually requested is not a great approach IMO.

nb. One way to cause yourself grief is to re-order L, in which case your request can still be done, but in a different way(!) and with consequences that might be awkward for you. IMO this is a hint that it's not a good idea.

restart

with(ScientificConstants)

L := [c, e, m['e'], hbar, epsilon[0], alpha]

[c, e, m[e], hbar, epsilon[0], alpha]

T := Equate(L, `~`[proc (u) options operator, arrow; GetValue(Constant(u))*GetUnit(Constant(u)) end proc](L))

[c = 299792458*Units:-Unit(m/s), e = 0.1602176620e-18*Units:-Unit(C), m[e] = 0.9109383560e-30*Units:-Unit(kg), hbar = 0.1054571800e-33*Units:-Unit(m^2*kg/s), epsilon[0] = (625000/22468879468420441)*Units:-Unit(A^2*s^4/(m^3*kg))/Pi, alpha = 0.7297352566e-2]

``

First, a common way to use the values in expressions involving those names,
but without clobbering those names.

eval(e, T)

0.1602176620e-18*Units:-Unit(C)

expr := c*e

c*e

eval(expr, T)

0.4803204671e-10*Units:-Unit(m/s)*Units:-Unit(C)

Or, if you want...

assign(T)

expr

0.4803204671e-10*Units:-Unit(m/s)*Units:-Unit(C)

c

299792458*Units:-Unit(m/s)

m[e]

0.9109383560e-30*Units:-Unit(kg)

eval(L, 1)

[c, e, m[e], hbar, epsilon[0], alpha]

L

[299792458*Units:-Unit(m/s), 0.1602176620e-18*Units:-Unit(C), 0.9109383560e-30*Units:-Unit(kg), 0.1054571800e-33*Units:-Unit(m^2*kg/s), (625000/22468879468420441)*Units:-Unit(A^2*s^4/(m^3*kg))/Pi, 0.7297352566e-2]

Note:

m[(1.602176620*10^(-19))*Unit('C')]

0.9109383560e-30*Units:-Unit(kg)

NULL

Download Using_the_constants_ac.mw

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