acer

32385 Reputation

29 Badges

19 years, 343 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

You didn't state that it had to have maximal area, so I interpret your question to mean that you want a parametrized solution.

Here is one way to do that, using Explore,

Explore(plots:-display(
    plots:-implicitplot(x^2/a^2+y^2/b^2-2*m*x*y/a/b+m^2=1,
                        x=-a..a,y=-b..b,gridrefine=3,rational),
    plottools:-polygon([[-a,-b],[-a,b],[a,b],[a,-b]],color=white),
    scaling=constrained, size=[500,500]),
  parameters=[[m=-0.99999..0.99999, placement=bottom],
              [ a=1.0..5.0, placement=right, orientation=vertical],
              [ b=1.0..5.0, placement=right, orientation=vertical] ],
  initialvalues=[m=0.0, a=2.0, b=1.0]);

You could also do some algebra and utilize plottools:-ellipse.

ellipse_rectangle.mw

Or, using plots:-animate ,

F := proc(m,a,b)
       plots:-display(
    plots:-implicitplot(x^2/a^2+y^2/b^2-2*m*x*y/a/b+m^2=1,
                        x=-a..a,y=-b..b,gridrefine=3,rational),
    plottools:-polygon([[-a,-b],[-a,b],[a,b],[a,-b]],color=white),
    scaling=constrained);
end proc:

plots:-animate(F, [m,2.0,1.0], m=-0.99999..0.99999,
               frames=50, paraminfo=false);

You might also want to plot the tangent points (using +/- m*a and m*b).

Of course there are other ways to obtain a similar effect (using an angle as parameter, etc).  And in Explore you might use only one of the rectangle sides' lengths as a parameter, or neither.

They are in fact present in your plot, but they are too thin and short to be distinguished, or too dark and close to the x-axis.

You can shorten the x-range (which reduces the overall y-range and thus makes the 0 and 2*x^2 distinguishable from each other). And you can add thickness to make the 0 plot distinguishable from the x-axis. For example,

plot({0, 2*x^2, 2*x^2 - 2*x^3 + 8/3*x^4 - 4*x^5},
     x = -1 .. 1, thickness=4,
     color = ["LightGreen", "CornflowerBlue", "Burgundy"]);

You could also change use the view option to force the visible y-range. For example, using a slightly wider x-range and a forced view,

plot({0, 2*x^2, 2*x^2 - 2*x^3 + 8/3*x^4 - 4*x^5},
     x = -2 .. 2, thickness=4, view=-10..10,
     color = ["LightGreen", "CornflowerBlue", "Burgundy"]);

And here that is with the original x-range and another choice of y-range,

plot({0, 2*x^2, 2*x^2 - 2*x^3 + 8/3*x^4 - 4*x^5},
     x = -10 .. 10, thickness=3, view=-1e3..1e3,
     color = ["LightGreen", "CornflowerBlue", "Burgundy"]);

You can even specify the thicknesses to be different for each curve. For example,

plot([0, 2*x^2, 2*x^2 - 2*x^3 + 8/3*x^4 - 4*x^5], x = -2 .. 2,
     thickness=[4,1,1],
     color = ["LightGreen", "CornflowerBlue", "Burgundy"]);

And you can mix some of those effects.

But it is not reasonable to expect all three of those to stand out visually on a range of x=-10..10, with a full y-range on a non-logarithmic y-axis, and the colors almost as dark as the x-axis. Something could be conceded.

You didn't tell us the original form of u1hat, so I've guessed.

But the key thing, I expect, is that you needed to figure out how to utilize the dsolve result while plotting the expression u1hat that contained calls like A__2(t) or B__2(t).

restart;

deqs := {-2/9*diff(B__2(t),t,t)-2/90*diff(B__2(t),t)
         -10.15209016*B__2(t)+2.124529588*A__2(t),
         -2/9*diff(A__2(t),t,t)-2/90*diff(A__2(t),t)
         -0.4863996160*B__2(t)-2.918397696*A__2(t)
         -sin(1/10*t),
         A__2(0)=0, B__2(0)=0, D(A__2)(0)=0, D(B__2)(0)=0}:

sols := dsolve(deqs, numeric, range=0..50, output=listprocedure):

AA__2 := eval(A__2(t),sols):
BB__2 := eval(B__2(t),sols):

#
# You didn't show us what this was, originally.
#
u1hat := (x^2-x)*A__2(t);

(x^2-x)*A__2(t)

U1H := unapply(subs(A__2=AA__2, u1hat),[x,t]);

proc (x, t) options operator, arrow; (x^2-x)*AA__2(t) end proc

xmax := 5:

plot3d(U1H, 0..xmax, 0..50);

## These behave the same.
#plots:-odeplot(sols,[t,A__2(t)]);
#plot(AA__2, 0..50);

 

Download ds_subs.mw

It could be adjusted if your u1hat expression contained calls to derivatives of A__2 or B__2. Please just ask in that case. But provide full details.

@pik1432 Here I address your followup query.

Your two expressions are not equal for all complex values of the unknowns. Here is an example set of values for which they are the negation of each other.

Is_eq := II[mu]/sqrt((omega__r^2 + omega__rK^2)*sigma^2
         /(sigma^2*omega__rK^2 + omega__r^2)):

Is_eq2 := II[mu] * sqrt((1+(omega__r/(sigma * omega__rK))^2)
         /(1+(omega__r/(omega__rK))^2)):

evalc(eval([Is_eq, Is_eq2],
      [II[mu] = 1, omega__r = 1,
       omega__rK = 1, sigma = I*sqrt(2)/2]));

            [-1/2*I*2^(1/2), 1/2*I*2^(1/2)]

It is not generally true that sqrt(1/x) is equal to 1/sqrt(x) . It is true for all nonnegative real x, but not for all complex x

If all the unknowns within the radicals of your expressions are real then (since the arguments inside the radicals would then happen to be nonnegative) the expressions will be equivalent. That is a sufficient condition.

[edit] I adjusted the wording of the previous two paragraphs, to more closely match the situation in the OP's expressions and to clarify.

Now, the is command is usually as strong as simplify (and friends). But very rarely it will need a little prod. This seems to be one of those cases, at least for the version Maple 2020.0 in which I executed this.

So we can do the comparison under the assumption that the unknowns are real (and we can help the is command a bit).

simplify(Is_eq - Is_eq2) assuming real;
                               0

is(simplify(Is_eq = Is_eq2)) assuming real;
                              true

is(radnormal(Is_eq = Is_eq2)) assuming real;
                              true

is(evala(Is_eq = Is_eq2)) assuming real;
                              true

# Is it rare that such an extra simplification
# step is required.

is(Is_eq = Is_eq2) assuming real;
                              FAIL

is(Is_eq - Is_eq2 = 0) assuming real;
                              FAIL

Note. I changed I[m] to II[mu] since the name I is special and denotes the imaginary unit by default and you didn't declare it as local.

[edit] I shall log a bug report on the case where the is command needed an simplification extra step. (By which I mean the extra simplification step, not the assumption.)

A somewhat close conversion is as follows,

r,theta := (abs,argument)(1+I):
plots:-animate(
  a->plot(((r^(1/a))*~([cos,sin]))~([seq]((2*Pi*k+theta)/a,k=0..a)),
          style=pointline, symbol=solidcircle, symbolsize=25,
          gridlines, thickness=3, scaling=constrained, color=blue,
          labels=[Re,Im], labelfont=[Helvetica,bolditalic,20]),
  [a], a=1..20, frames=20, paraminfo=false);

But it is not exactly the same, since your Explore example runs with the default of 50 frames.

Note that integer values for the parameter get passed by plots:-animate when the number of frames matches a supplied integer range, but otherwise a float gets passed by the animate command. In contrast, Explore passes the integer values (possibly multiple times) in that case.

For your example there is an effect of passing a float instead (ie. the computed points are different that those obtained from the rounded integers. And so a closer conversion would be as follows, keeping Explore's default of 50 frames.

r,theta := (abs,argument)(1+I):
plots:-animate(
  a->plot(((r^(1/round(a)))*~([cos,sin]))~([seq]((2*Pi*k+theta)/round(a),k=0..round(a))),
          style=pointline, symbol=solidcircle, symbolsize=25,
          gridlines, thickness=3, scaling=constrained, color=blue,
          labels=[Re,Im], labelfont=[Helvetica,bolditalic,20]),
  [a], a=1..20, frames=50, paraminfo=false);

The same effect could be obtained more gracefully with a local variable.

r,theta := (abs,argument)(1+I):
plots:-animate(
  proc(aa) local a:=round(aa);
    plot(((r^(1/a))*~([cos,sin]))~([seq]((2*Pi*k+theta)/a,k=0..a)),
          style=pointline, symbol=solidcircle, symbolsize=25,
          gridlines, thickness=3, scaling=constrained, color=blue,
          labels=[Re,Im], labelfont=[Helvetica,bolditalic,20]);
  end proc,
  [a], a=1..20, frames=50, paraminfo=false);

Of course you are free to adjust the number of frames as you please. I just wanted to mention the difference in behavior.

Also, there's nothing inherently wrong with using non-integer values for the parameter, if you wanted to show the effect of it. There are some nice variants on your animation possible like that. But I was focused on a conversion of what your particular example did in Explore.

There is another difference that comes up for your example. The effective view of the result from plots:-animate is shared across all rendered frames. (Sometimes view is referred to as a "global" plot option.) But in Explore the example you gave shows with the non-forced view being different for each frame. You might actually prefer the common view, however, and of course that could also be forced in the Explore example by adding a view option to the call.

How about a piecewise logarithmic fit?

I am not bothering to make use of the fact that the data is symmetric (because I don't know whether this will be true of some larger data set you might actually have.)

[edit] The only reason I use evalf[6] below is to make the result look a little tidier on the page. You can remove the wrapping evalf[6] calls, if you prefer. (Doing so might improve the fit a little, though it's likely not optimal regardless.)

restart;

X := [-0.012, -0.010, -0.004, -0.002, -0.001, -0.0001,
      0.0001, 0.001, 0.002, 0.004, 0.010, 0.012]:
Y := [-0.695, -0.7, -0.74, -0.825, -0.95, -1.0,
      1.0, 0.95, 0.825, 0.74, 0.7, 0.695]:

P := plots:-pointplot(X,Y,symbol=solidcircle,symbolsize=12,color=blue):

Xn,Xp := selectremove(`<=`,X,0);
T := table([seq(X[i]=Y[i],i=1..nops(X))]):
Yp,Yn := [seq(T[x], x=Xp)], [seq(T[x], x=Xn)];

[-0.12e-1, -0.10e-1, -0.4e-2, -0.2e-2, -0.1e-2, -0.1e-3], [0.1e-3, 0.1e-2, 0.2e-2, 0.4e-2, 0.10e-1, 0.12e-1]

[1.0, .95, .825, .74, .7, .695], [-.695, -.7, -.74, -.825, -.95, -1.0]

Fp := evalf[6]( Statistics:-Fit(a+b*ln(abs(c*x)), Xp, Yp, x) ):
Fn := evalf[6]( Statistics:-Fit(a+b*ln(abs(c*x)), Xn, Yn, x) ):
F := piecewise(x<=0, Fn, Fp);

F := piecewise(x <= 0, .612662+0.701029e-1*ln(6.37473*10^(-7)*abs(x)), .202488-0.701029e-1*ln(0.715150e-1*abs(x)))

plots:-display( plot(F,x=min(X)..max(X), thickness=3, discont),
                P, view=-2..2, size=[500,350] );

 

Download pwlog.mw

Or you could do a rational polynomial fit. (With so few points it's unclear what is the "best" form.) I'll use the symmetry here, for fun.

Fn := evalf[6]( Statistics:-Fit((a+b*x+c*x^2)/(d+e*x+f*x^2),
                                 Xn, Yn, x) );
F := piecewise(x<=0, Fn, -eval(Fn,x=-x)):

                     2                          
            4655.04 x  + 0.575145 x + 0.00875488
      Fn := ------------------------------------
                      2                         
            -6833.43 x  - 2.22097 x - 0.00889769

Read the Help pages for the commands from the HelpTools package.

That ought to provide the functionality for you Create a new database file, Store a custom Help pages to it, and so on.

There are also some Templates for Help pages.

You might also be able to do some of the management from the Tools item on the main menubar.

Sometimes in the past I have found some of this kind of documentation to be out of date, as the utilities get revised but some older instructions stick around for a while. Your mileage may vary.

Basically, when you call select the result is the same operation or container that it is passed.

In the documentation quote you cited the key phrase is, "creates a new object of the same type". Sometimes it's tricky to document behaviour and keep clear which terms are technical and which are being used in a more general sense. Here, a strictly technical definition might well be confusing for most people.

For example, calling select on this product returns a product.

select(type, x*sin(a)*7*cos(y)*z, specfunc({sin,cos})):
lprint(%);
sin(a)*cos(y)

The empty product is 1. The empty sum is 0.

[edit] This behavior in Maple is due not merely to mathematical convention. Or, rather, the convention is not merely incidental. It allows the math to work out more usefully. It allows the programming to work out much more usefully.

`*`(NULL);                                                                        
                  1

`+`(NULL);                                                                        
                  0

If you want to test whether the selected operands of the `+` or `*` expressions are NULL then you could operate on a list of those operands. For example,

[op(3*C)];
                         [3, C]

select(has,[op(3*C)],x);
                           []

[op(3+C)];
                         [3, C]

select(has,[op(3+C)],x);
                           []

I don't understand why you are substituting eval(Sqr), since that procedure a version of Dist with all those anonymous procedures inside the actual procedure body. What benefit do you get from that?! Is it really worth it?

If you are concerned with the life cycle of your code then I think you should give serious consideration to keeping the source in plaintext files, not worksheets. You can still have a worksheet that builds the package and stores it to an .mla file, etc. (You could use the read command on the master source file, and $include directives if you want to store some procedures in separate source files.) Plaintext files will almost never be corrupted, can be maintained by revision control, and accessed without need for Maple itself.

For example, if the source for procedure Dist (or even its template) were stored separately from the Test module source then you could run your testing scheme on it, while also $include'ing it in the source/build of Test. But you wouldn't need the contrived construction of Test:-Dist as a subs on eval(DistWorkSheet).

Getting back to the use of eval(Sqr), is that just a toy example, or is it possibly relfecting some situation where you want Sqr to be inlined into the body of Test:-Dist?

Here I use depends which may be generally better than merely checking for the presence of C[1] (which could possibly occur only as the dummy variable of integration, etc, which conceivably might not matter here).

[edit] To be clear, I think that `has` is wrong for this. I see little justification in using the weak tool  just because corner cases are rare.

You should avoid replacing with just a global name. You might replace with a procedure local created just for that purpose. Or perhaps you could freeze the exp calls.

restart;

expr:=1/exp(z)*arcsinh(x*exp(C[1]))+x*C[1]*sin(exp(x))
      +3*exp(C[1]*y)*sqrt(sin(exp(3*C[1]))):

depends(subsindets(expr, specfunc(exp), freeze), C[1]);

                    true

Now, since this is subsindets (rather than evalindets) there should be less concern with inadvertant evaluation. You don't want to have to worry about situations where the x inside exp(x) was needed so as to avoid accidentally wiping out a C[1] that really did occur outside of any exp call. So you could be more cautious and do it something like so:

depends( subsindets(expr, specfunc(exp),
                    u->%__exp(op(indets(u,name) minus {C[1]}))),
         C[1] );

The subsindets command can be used to process and substitute for subexpressions of a particular type.

Eg,

   subsindets( expr, specfunc(anything, exp), ()->Z );

will replace all exp function calls with just the name Z.

The last argument can be a procedure that accepts the subterms in question as its own argument. So more generally you can process and adjust the target subterms' substitutions -- rather than merely replacing them.

In newer Maple versions the 2nd argument can be specfunc(exp) instead of specfunc(anything, exp) .

Note also that there is a very useful correspondence between the indets and the subsindets commands. Your earlier use of indets and select can be changed to utilize the target type more directly and economically (and robustly, IMO, since has is a bit of a crude hammer).

restart;                                                                          
expr:=1/exp(z)*arcsinh(x*exp(C[1]))
      +x*sin(exp(x))+3*exp(C[1]*y)*sqrt(sin(exp(3*h))):

# You now did this.
s:=select(x->has(x,exp),indets(expr)):
select(x->op(0,x)='exp',s);

      {exp(x), exp(z), exp(C[1]), exp(C[1] y), exp(3 h)}

# But those could be obtained directly with this.
indets(expr, specfunc(exp));

      {exp(x), exp(z), exp(C[1]), exp(C[1] y), exp(3 h)}

Are you trying to accomplish something similar to this? I am not sure whether I properly understand your integration syntax (z and z').

(I have little idea what is your scale, or accuracy requirements, because you didn't bother to say.)

HH := 5*log[10]((c/H_0)*Int(1/(A*(1+zp)^4+B*(1+z)^3+C)^(1/2)/10,
                            zp=0..z,
                            method=_d01ajc, epsilon=1e-5)):

plot(eval(HH,[A=2, B=3, C=4, H_0=1, c=299792458]), z=1e-7 .. 1.0,
     thickness=3, color=red, smartview=false);

int(convert(1/tanh(u),sincos),u);

                   ln(sinh(u))

[edit] Also, if you're ok with it...

res := int(1/tanh(u),u):

   ln(tanh(u))-1/2*ln(tanh(u)-1)-1/2*ln(tanh(u)+1)

simplify(combine(combine(res,symbolic),symbolic),symbolic):

                1/2*I*Pi + ln(sinh(u))

There is a new command in Maple 2020, called ListTools:-Slice, which can split a list into n parts.

If it's not fast enough then tell us the performance/timing you want.

Also related is the (older) command ListTools:-LengthSplit.

 

I am interpreting your question to mean that you don't want to see any float approximations of multiples of Pi, but only want to see the rational multiples like Pi/3, 0, Pi/6, etc.

Here are two ways, one with Explore and one as a conventional animation.

You can of course adjust what plots are included, slow it down with duplicate frames, etc. I figured that the key thing is how the parameter value gets rendered, as mentioned.

I have used a textplot rather than a caption or title for the parameter info, because I dislike even the smallest amount of jitter in the display (as 0*Pi=0 which renders shorter, and other special cases).

There is no way to have the running value of a controller (Slider, etc) be displayed other than as an integer or float, as it appears beside the controller. So I suppress the alpha controller altogether, leaving only the animating slider shown.

(The Explore components look nicer in the actual Maple GUI, but this site's backend doesn't render those so well.)

restart

a := 4; b := 5; x0 := -3; y0 := -4

P1 := plot([a*cos(t)+x0, b*sin(t)+y0, t = 0 .. 2*Pi], scaling = constrained, gridlines, thickness = 3, size = [400, 400])

F := proc (n, N) local p; p := convert(n/N, rational)*Pi; plots:-display(P1, plot([a*cos(t)*cos(p)-b*sin(t)*sin(p)+x0, a*cos(t)*sin(p)+b*sin(t)*cos(p)+y0, t = 0 .. 2*Pi], scaling = constrained, gridlines, thickness = 3, color = red), plots:-textplot([-4, -4.5, ':-alpha' = Typesetting:-Typeset(Typesetting:-EV(p))], align = {right}, color = blue, font = [Times, 16]), view = [-9 .. 3, -10 .. 1]) end proc

Explore(F(n, 12), parameters = [[n = 0 .. 12, shown = false, animate]], frames = 13)

 

 

 

 

 

 

 

 

plots:-animate(F, [n, 12], n = 0 .. 12, frames = 13, paraminfo = false)

NULL

ROTATIONConiquesEllipseAnimation_ac.mw

[edit] In case you want an easy way (at the expense of size) to slow down the conventional animation by duplicating frames:

   plots:-display(seq(F(i, 12)$4, i = 0 .. 12), insequence = true)

First 118 119 120 121 122 123 124 Last Page 120 of 336