acer

32313 Reputation

29 Badges

19 years, 315 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

Another way is to use an initializer.

Eg,
        Vector(10, (i) -> 2+(6-2)*(i-1)/(10-1));

        Vector(N, (i) -> a+(b-a)*(i-1)/(N-1));

And naturally any of these techniques can be conveniently provided as terser functionality, by creating a custom re-usable procedure that accepts the relevant parameters.

When you finish manually rotating a 3D plot within a Plot Component you can get at the orientation angles by computation from the PROJECTION substructure. But you have to stop manual rotation, and then manually interact, to start that computation. (The angles can be recovered numerically from the 3x3 rotation matrix, stored in the first 9 entries of that substructure.)

But there is, alas, no "Action when Rotated" Property of Plot Components, akin to the Drag action Properties of 2D plots in Components. So you cannot get on-the-fly programmatic action as you rotate continuously.

I have requested that Property for Plot Components, some years ago. It might help if someone else who wanted it were to also submit the request.

It is missing possible simplification involving exp(x/2) and exp(x), eg. factoring, within the radical.

Here are two workarounds. The second is unfortunately more ad hoc.

restart;
ode:=diff(y(x),x)-y(x) = x*y(x)^(1/2):
ic:=y(0)=4:
sol:=dsolve([ode, ic],y(x)):

check:=odetest(sol,ode);

        4*x*exp(1/2*x)-2*x-x^2
        -x*(16*exp(x)-8*x*exp(1/2*x)+x^2-16*exp(1/2*x)+4*x+4)^(1/2)

simplify(eval(check,x=2*t)) assuming t>0;

                0

simplify(simplify(check, {exp(x)=exp(x/2)^2})) assuming x>0;

                0

Doing that last one in two steps shows an idea -- that the inside of the radical can be factored into a perfect square (and the rest from there it can handle).

simplify(check, {exp(x)=exp(x/2)^2});

    -x*(((x - 4*exp(1/2*x) + 2)^2)^(1/2) + x - 4*exp(1/2*x) + 2)

simplify(%) assuming x>0;

                0

If you mean the Embedded Component named TextArea then after insertion into your document you can change the number of visible rows and character-width in either of the following two ways:

1) Use the mouse-pointer, right-click and select "Component Properties" in the pop-up menu, and then adjust the two relevant properties: "Visible Character Width" and "Visible Rows".

2) By commands,  eg.
       DocumentTools:-SetProperty("TextArea0", ':-visibleCharacterWidth', 23);
       DocumentTools:-SetProperty("TextArea0", ':-visibleRows', 3);

See the Help page for more detail.

Note that the character-width relates to a fixed-width font, which cannot be directly changed. (Also, on Linux a variable-width font is used here, and so the component is always wider than designated by the Property.)

If you instead mean the Maplets element named TextBox then see its Help page.
 

[edited] I wrote this before the Question was edited to state that the OP stil wanted to manipulate the expressions. Why cannot the original form be manipulated and used for computation, while still handled by a special display command when needed? Does subsequent computation need to be able to distinguish structurally/programmatically between 1/expr and the desired expr^(-1) form, for each possible expr in the class? (If so, then better to have stated that too. If not, then what's wrong with a separate printing facility, used only on when showing output is needed?)

Try the following,

H:=e->subsindets(e,anything^negint,
                 u->InertForm:-Display(`%^`(op(u)),
                                       ':-inert'=false)):

raw := ztrans(beta*5^n*(n^2+3*n+1),n,z);
H(raw);

rat_poly_neg_pow.mw

You could also adjust that type, anything^negint. Are there non-polynomial symbolic denominators that you want to exclude from this treatment? The anything could be tightened up or amended.

Do you need the integer in the denominator to be handled in some way? (Eg, 1/5 typeset as a separate multiplicative factor, or as 5^(-1), etc...)

If, as you have stated in followup remarks, abs(n,...) terms will not occur in your expressions then this is short and direct, and doesn't require adding a new type.

  evalindets(expr,'specfunc'(ln),evalindets,'specfunc'(abs),op)

For example,

restart;

H:=(e,r,s)->evalindets(e,'specfunc'(r),
                       evalindets,'specfunc'(s),op):

expr:=sin(x)+ln(abs(x))+ln(x+abs(y)/sqrt(abs(x+3)))
      +ln(x^3)+cos(abs(x)):

H(expr, ln, abs);

  sin(x)+ln(x)+ln(x+y/(x+3)^(1/2))+ln(x^3)+cos(abs(x))

H(expr, {ln,cos}, abs);

    sin(x)+ln(x)+ln(x+y/(x+3)^(1/2))+ln(x^3)+cos(x)

Here is some ideas, depending on the interpretation of your Question.

restart;
H := ee -> indets(ee,'anyfunc(satisfies(u->hastype(u,function)))'):

expr:=sin(x)+ln(abs(x))+ln(x+1/sqrt(abs(x+3)))+ln(x^3):

H(expr);

    {ln(x+1/abs(x+3)^(1/2)), ln(abs(x))}

expr2:=sin(x)+sin(abs(x))+ln(abs(x))
       +ln(x+1/sqrt(abs(x+3)))+ln(x^3)+abs(x)+abs(cos(x)):

H(expr2);

    {abs(cos(x)), ln(x+1/abs(x+3)^(1/2)), ln(abs(x)), sin(abs(x))}

The wording in your first sentence is unclear. What do you mean by "in it"? Your use of indets means that it will recurse. Is that what you really want? What do you want returned for, say, ln(abs(ln(abs(x))) ?

[edit] It's also unclear what you mean by "another function" at the end of your first sentence. You might mean a call to any function, which is what I guessed above as the interpretation, and for which the above code pertains.

But instead you might have meant a call to some specific command(s) that you have in mind, ie. something of type specfunc in the technical Maple sense. So here is an alternative, in which you also specify the inner function(s), as a set.

restart;

H:=(ee,s)->indets(ee,
                  'anyfunc'(satisfies(u->hastype(u,specfunc(s))))):

expr:=sin(x)+ln(abs(x))+ln(x+1/sqrt(abs(x+3)))+ln(x^3):

H(expr, {abs});

   {ln(x+1/abs(x+3)^(1/2)), ln(abs(x))}

expr3:=sin(x)+sin(abs(x))+ln(abs(x))
       +ln(x+1/sqrt(abs(x+3)))+ln(x^3)
       +abs(ln(x))+abs(cos(x)):

H(expr3, {abs});

   {ln(x+1/abs(x+3)^(1/2)), ln(abs(x)), sin(abs(x))}

H(expr3, {cos});

        {abs(cos(x))}

H(expr3, {ln});

         {abs(ln(x))}

H(expr3, {abs, cos});

    {abs(cos(x)), ln(x+1/abs(x+3)^(1/2)),
     ln(abs(x)), sin(abs(x))}

Here is another possibility, in which you specify both the outer and inner function types.

restart;

H:=(ee,r,s)->indets(ee,
                    'specfunc'(satisfies(u->hastype(u,specfunc(s))),r)):

expr:=sin(x)+ln(abs(x))+ln(x+1/sqrt(abs(x+3)))+ln(x^3):

H(expr, {ln}, {abs});

    {ln(x+1/abs(x+3)^(1/2)), ln(abs(x))}

expr4:=sin(x)+sin(abs(x))+ln(abs(x))
       +ln(x+1/sqrt(abs(x+3)))+ln(x^3)
       +abs(ln(x))+abs(cos(x)):

H(expr4, {ln, sin}, {abs});

    {ln(x+1/abs(x+3)^(1/2)), ln(abs(x)), sin(abs(x))}

H(expr4, {abs}, {cos});

         {abs(cos(x))}

Ambiguity like this often comes from providing overly simple examples. Note that all three interpretations above produce the same result for the same first example.

Ambiguity also comes from not distinguishing between common words (eg. "function", mathametically or programmatically in general) and technical terms (eg. function, a kind of Maple type).

I am using the correction to the r1 instance typo that you mentioned to Rouben.

I am also using (x+d1)^2 in the relevant formula (rather than (x-d1)^2 as Rouben used) to match the corresponding image. If that was another typo then you can simply edit the code below and in the attachment.

Using your revised value of C=200,

restart;

eq:=(m1+m2)*(x^2+y^2)+2*m1/r1+2*m2/r2=c:

new:=eval(eval(eq, [r1=sqrt((x+d1)^2+y^2+z^2),
                    r2=sqrt((x-d2)^2+y^2+z^2)]),
          [d1=0.6, d2=0.4, m1=10, m2=2, z=0]):

plots:-implicitplot(eval(new,c=200), x=-4.5..4.5, y=-4.5..4.5,
                    grid=[51,51], gridrefine=2,
                    axes=box, rangeasview, gridlines);

Naturally, you can adjust the options (eg, remove gridlines, adjust the ranges, etc).

You can also create plot the contours, for various c values. You can do this using a sequence of implicitplot calls, or a single contourplot call.

plots:-contourplot(lhs(new), x=-4.1..4.1, y=-4.1..4.1,
                   grid=[101,101], coloring=["Orange","Blue"],
                   filledregions,
                   contours=[30,31,35,45,65,100,150,200]);

Again, adjust the options as wanted.

plots:-display(
  plots:-contourplot(lhs(new),x=-4.1..4.1, y=-4.1..4.1,
                     grid=[101,101], coloring=["Orange","SteelBlue"],
                     legend=true, legendstyle=[location=right], thickness=3,
                     contours=[30,31,35,45,65,100,150,200]),
  plots:-contourplot(lhs(new),x=-4.1..4.1, y=-4.1..4.1,
                     grid=[101,101], coloring=["Orange","SteelBlue"],
                     filledregions,
                     contours=[30,31,35,45,65,100,150,200]),
  size=[550,450]);

You can also Explore it, for a range of c values (see attachment).

impl_plot.mw

This alone causes a crash in my Maple 2020.1.

restart;
evalf(LaguerreL(5, HFloat(4.1001001001001e258)));

And that kind of call is done during the DirectSearch example.

I will submit a bug report.  (I'm pretty sure I've seen another example very similar, but I will submit regardless.)

The crash might be occuring during the next gc (garbage collection) following the computation. I am not sure. In the CommandLine Interface (CLI),

restart;
evalf(LaguerreL(5, 4.1001001001001e258));
                             1246
             -0.9793474754 10

gc();
GC Thread signalAbort 0x7f67e0a3c700 Execution stopped: Stack limit reached.
maple: fatal error, lost connection to kernel

Deeper down,

restart; printlevel:=999:
`evalf/hypergeom/kernel`([-5.], [1.], .4100100100e259): gc():
GC Thread signalAbort 0x7f71b1d70700 Execution stopped: Stack limit reached.
maple: fatal error, lost connection to kernel

And `evalf/hypergeom/kernel` is a kernel builtin.

In a related way, for a different input sometimes I can get this effect (without gc),

restart; hypergeom([-3],[1],1e350):
gmp: overflow in mpz type
maple: fatal error, lost connection to kernel
It seems (so far) these were ok in Maple 2015.2 or earlier.

In your example A the arguments being passed to PDEtools:-Solve are 0=0, x~  (where x~ is the replacement name for x, with assumptions placed on it).

You can easily see this by using the trace command.

restart;
ode:=(x+1)*diff(y(x),x)+y(x)^(1/2) = 0;
ic:=y(0) = 1;
sol:=dsolve([ode,ic],y(x));
check:=odetest(sol,ode);
trace(PDEtools:-Solve):
PDEtools:-Solve(check=0,x) assuming x>-1,x<6;
untrace(PDEtools:-Solve):

That is similar to doing this:

PDEtools:-Solve(0=0,x) assuming x>-1,x<6;                                          
Error, (in assuming) when calling 'PDEtools:-Solve'.
Received: 'not a system with respect to the unknowns {x}'

When you call,
    PDEtools:-Solve(check=0,x) assuming x>-1,x<6;
the assumptions are used to replace all instances of name x present in the main expression, including those within check. Then check is evaluated up front (normal evaluation rules, innermost to outermost) when passed as argument to PDEtools:-Solve. After the assumed name x~ replaces x within check then check evaluates to just zero. Eg,

check assuming x>-1,x<6;

                 0

Using Maple 2020.1,

restart;

Expr:=arctan((1-tan(20*Pi/180))/(1-tan(25*Pi/180))):

simplify(convert(Expr,exp));

                   5    
                   -- Pi
                   18   

In Maple versions 16.02, 17.02, 18.02, 2015.2, 2016.2, 2017.2, 2018.2 and 2019.2, you could do the following, though the timing varies,

simplify(expand(convert(Expr,exp)));

Here are two polar density plots, from the given data (with my understanding so far), using this attached worksheet:

  polar_densityplot.mw

As you can see, one displays with rectangular coordinate axes, and the other polar.

The ranges on the rectangular case is restricted since I didn't set up the interpolation to nicely extrapolate outside r=0..1, but that might be adjusted reasonably if needed I think.

The choices of coloring gradients (colorscheme) can be adjusted quite easily.

There are a few ways to include a colorbar, but none is quite perfect. Please state whether that is a requirement, and whether you need to export the result to a single image file (it makes a difference to which approach works best.)

(If the ranges -200..200 and 0..0.6 from your posted image are supposed to relate then please explain.)

In the first case you are also calling odetest (and not just simplify) under the assumption.

And that produces zero (in my Maple 2020.1 at least) even before simplify is called.

Here it is, with both called separately and under the assumption.

restart;
mysol:= exp(sqrt( y(x)^2/x^2+1)) = _C1*x:

ode:=diff(y(x),x) = (y(x)^2+(x^2+y(x)^2)^(1/2)*x)/x/y(x):

  diff(y(x),x) = (y(x)^2+(y(x)^2+x^2)^(1/2)*x)/x/y(x)

simplify(odetest(mysol,ode)) assuming x>0;

                      0

res:=odetest(mysol,ode) assuming x>0;

                   res := 0

simplify(res) assuming x>0;

                      0

In your second example you only used the assumption in the call to simplify, but not the initial call to odetest. Thus you made your two examples different.

What made the difference was not that you were "putting an intermediate result in a variable". What made the difference was that you were no longer calling odetest under the assumption.

Before anything else, you should fix your syntax, by including explicit multiplication symbols as needed.

Your example contained both GoHo (with not even any space) as well as Go Ho (with a space). It looks as if you may have intended Go*Ho, in which case that is the best way to write it, and in which case GoHo is a typo mistake.

I am supposing that your goal is an approach that will let you substitute some variables (eg. Uo,Go,Ho) with dimensionless variables (eg. Fr and likely others), into one or more expressions -- according to one or more given equivalency rules.

Your given example is, unfortunately, overly simple. That's a bit of a problem since there are very many ways to produce the result. Many of those will be quite ad hoc, and won't generalize well (if at all) to similar but more involved examples. This also makes it more difficult to generalize the approach, since we don't know what dificulties will be presented by more involved examples.

Here is one idea. (Pay attention to the syntax, if typos and syntax is a common issue.) One point is that it doesn't require you to discriminate between Uo, Go, and Ho, if those are indeed the variables you wish to eliminate. This is not the only possible general approach, but it can be systematically extended to examples involving more equations and "dimensionaless" variables.

restart;

eq1 := Uo/sqrt(Go*Ho)=Fr:
new1 := targ1 = Go*Ho/Uo^2:

eval(targ1,
     [solve({new1,eq1}, {targ1,Go,Ho,Uo})][1]);

That produces the following in my Maple 2020.1,

                    1
                   ---
                     2
                   Fr

One natural way to extend this to cases of several equations and additional dimensionless variables would be to augment the sets in a single call to solve made as above.

Note that additional equations would further constrain the variables (if all are to hold at once). That might mean that eliminate could be necessary instead of solve, since the non-eliminated variables might not be wholly free in which case solve would return NULL. Another possibility here is a pair of eliminate calls (dealing with the nondimenionless variables and the introduced names for the target expressions separately).

And so another possibility is to eliminate the nondimensionless variables from the supplied equations, and then substitute those results into the target expressions (and possibly simplify, as it might get messy).

Again, be careful about syntax errors. Be careful about accidentally suppressing output by using full colons instead of semicolons as statement terminators. (But you can terminate will full colons, even for intermediate terms, as that may help you learn what Maple is doing.)

If you have additional, more involved examples, then you should provide them as soon as possible. (Better would be to have provided them up front, in your Question.) Note that it's possible that results may not be uniquely determined.

If your Maple version is older than Maple 2020 then you should indicate that in your query. You can mark your Question's Product in its header.

[edit] Here is an example, using a larger system of equations, and a pair of target expressions, and one of my alternate suggested approaches. Notice how the inclusion of eq5 changes the representation of the first target expression (but still in terms of the new, dimensionless variables). You should decide how you'd want to handle such ambiguity.

restart;

eq1 :=  Uo/(sqrt(Go*Ho)) = Fr:
eq2 := (rho*Go*Ho^2)/sigma = W:
eq3 := St = (To*Uo)/Ho:
eq4 := Ca = (mu*Uo)/sigma:
eq5 := mu/sqrt(rho*sigma*Ho) = Oh:

dvars := {Go,Ho,To,Uo}:

new1 := targ1 = Go*Ho/Uo^2:
new2 := targ2 = mu/To*Ho:

SS1 := eliminate({eq1,eq2,eq3,eq4}, dvars)[1]:

eval(targ1, new1) = eval(eval(targ1, new1), SS1);

                          Go Ho    1 
                          ----- = ---
                             2      2
                           Uo     Fr 

eval(targ2, new2) = eval(eval(targ2, new2), SS1);

                        mu Ho   Ca sigma
                        ----- = --------
                         To        St   

SS2 := eliminate({eq1,eq2,eq3,eq4,eq5}, dvars)[1]:

eval(targ1, new1) = eval(eval(targ1, new1), SS2);

                                     2
                         Go Ho   W Oh 
                         ----- = -----
                            2       2 
                          Uo      Ca  

eval(targ2, new2) = eval(eval(targ2, new2), SS2);

                        mu Ho   Ca sigma
                        ----- = --------
                         To        St   

elimination_dim_vars2.mw

For now (until I get time to write more, or someone else does), you could compare the 2D Output of the following.

I think that it does not look best when subscripts appear in the same font size as the main characters. I think that the rendering gets even more awkward as the subscripting is nested.

restart;
kernelopts(version);

R1 := `#msub(mi("x"),msub(mi("i"),mi("j")));`:
S1 := `#msub(mi("X"),msub(mi("G"),mi("H")));`:
use Typesetting in
  R2 := msub(mi("x",size="12"), msub(mi("i",size="10"), mi("j",size="8")));
  S2 := msub(mi("X",size="12"), msub(mi("G",size="10"), mi("H",size="8")));
end use:

R1, x[i[j]], x__i__j, R2;
S1, X[G[H]], X__G__H, S2;

nested_subscripts_sized.mw

You may already know this, but the lprint command can be useful in having a look at the structures (whether XML-style names, or Typesetting export function calls, or TypeMK or whatever you'd like to call them).

First 95 96 97 98 99 100 101 Last Page 97 of 336