acer

32343 Reputation

29 Badges

19 years, 327 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are replies submitted by acer

@The function If you use the Calculus1:-Roots command, and only need float results, then it will be much more efficient to pass that command its numeric option. Internally this uses a scheme of recursively calling fsolve on subintervals between found roots.

If you go for the fsolve(...,maxsols=n) approach then note the following. This approach internally uses RootFinding:-NextZero in a loop. It also uses that command's maxdistance option (based on the last found root, and the specified range's upper end-point) to help limit how far it needs scan. The finite value of n prevents a runaway computation, in the more general case in which a finite range might contain infinitely many roots. Beware there is unfortunately a hard-coded 100-root limit (to this loop, under fsolve, and thus to the number of roots found). You can get rid of that limit by the following code (executed once per session, say in a startup region or initialization file).

restart;

kernelopts(version);

`Maple 2019.2, X86 64 LINUX, Nov 26 2019, Build ID 1435526`

expr := sin(x)-cos(4*x - 1/6*Pi):

[fsolve(expr, x=0..1000, maxsols=200)]: # oops, hard-coded max number
nops(%);

100

restart;

 

Once per session, this gets rid of the 100-root limit. Oof.
I only checked this on Maple 2019.2.

 

kernelopts(opaquemodules=false): unprotect(fsolve:-scalarmultiple):
fsolve:-scalarmultiple:=FromInert(subsop([5,5,5]=_Inert_LESSTHAN(_Inert_LOCAL(3),_Inert_PARAM(7)),
                                         ToInert(eval(fsolve:-scalarmultiple)))):
protect(fsolve:-scalarmultiple): kernelopts(opaquemodules=true):

 

expr := sin(x)-cos(4*x - 1/6*Pi):

[fsolve(expr, x=0..1000, maxsols=200)]:
nops(%);

200

Download fsolve_scalarmultiple_maxtries.mw

Note also that there are some kinds of expression that NextZero cannot handle. Some of those relate to possible discontinuities.

@superbee Perhaps you have accidentally toggled off the Editable checkbox that appears in the Status Bar? See also here.

If you cannot see the Maple GUI's Status Bar then you can enable that with the main menubar's choice:  View -> Status Bar

Someone keeps removing the tags associated with the Question. Please stop doing that.

@rupsagar Your question about collecting trig terms is different from this question about expanding trig calls, and would be better placed in its own Question thread.

You can use the collect command to group coefficients of trig terms.

For example,

restart;

 

First, a more general programmetic approach to the original query.

 

expr := sin(x+phi)*A + sin(x)*B + sin(2*x)*M + cos(2*x + phi)*N = 0;

sin(x+phi)*A+sin(x)*B+sin(2*x)*M+cos(2*x+phi)*N = 0

ans := normal(subsindets(expr, specfunc({sin,cos}),
                          u->thaw(expand(subsindets(u,`*`,freeze)))));

A*sin(x)*cos(phi)+A*cos(x)*sin(phi)+N*cos(phi)*cos(2*x)-N*sin(phi)*sin(2*x)+sin(x)*B+sin(2*x)*M = 0

targ := sin(x)*cos(phi)*A + cos(x)*sin(phi)*A + sin(x)*B
        + sin(2*x)*M + cos(2*x)*cos(phi)*N - sin(2*x)*sin(phi)*N = 0

A*sin(x)*cos(phi)+A*cos(x)*sin(phi)+N*cos(phi)*cos(2*x)-N*sin(phi)*sin(2*x)+sin(x)*B+sin(2*x)*M = 0

ans-targ;

0 = 0

 

Now, we may collect in various ways. Notice the grouping of terms.

 

[indets(ans,
        specfunc({identical(x),
                  `&*`(integer,identical(x))},sin))[]];

[sin(x), sin(2*x)]

collect(ans, %);

(A*cos(phi)+B)*sin(x)+(-N*sin(phi)+M)*sin(2*x)+A*cos(x)*sin(phi)+N*cos(phi)*cos(2*x) = 0

[indets(ans,
        specfunc({identical(x),
                 `&*`(integer,identical(x))},{sin,cos}))[]]

[cos(x), cos(2*x), sin(x), sin(2*x)]

collect(ans, %);

(A*cos(phi)+B)*sin(x)+(-N*sin(phi)+M)*sin(2*x)+A*cos(x)*sin(phi)+N*cos(phi)*cos(2*x) = 0

[indets(ans,
        specfunc({identical(phi),
                 `&*`(integer,identical(phi))},{sin,cos}))[]]

[cos(phi), sin(phi)]

collect(ans, %);

(A*sin(x)+N*cos(2*x))*cos(phi)+(A*cos(x)-N*sin(2*x))*sin(phi)+sin(x)*B+sin(2*x)*M = 0

Download collect_sincos_multiples.mw

Please stop submitting duplicate Question threads for this.

Please put your followups in this thread, instead.

@jrive Let me know if you'd prefer seeing 6e-10 formatted as 600e-12 rather than 0.6e-9, etc.

I chose different normalized ranges for the cases of positive versus negative exponents of 10, which may be nonstandard but is a preference of my own purposes. That is mostly because I wrote that code long ago, for myself. It could be adjusted.

ps. The ability to strip trailing zeroes (which may or may not be desired here) can be useful on its own, though I didn't make it as export of the module.

@mmcdara I think that you forgot to call your EngForm on ftest for processing the legend value. You left it as EN(ftest).

Also, I am seeing some problem cases in your implementation, seen as follows using an unedited copy of your (original) code:

restart;

EngForm := proc(x)
  local n, L, p, r, m, e, f:
  if abs(x) < 10^4 and abs(x) > 1 then
    cat(`#mo("`, x, `")`)
  elif abs(x) > 10^4 then
    n := length(op(1, x));
    L := log[10](abs(x));
    p := floor(L);
    r := irem(p, 3);
    m := 10^(L-p+r);
    m := evalf[n](m);
    e := p-r;
    cat(`#mrow(mo("`, m, `"),mo("&#xd7;"),msup(mo("10"),mo("`, e, `")))`)
  elif abs(x) < 1 then
    n := length(op(1, x));
    L := -ceil(log[10](abs(x)));
    r := 3-irem(L, 3);
    p := L+r;
    m := x*10^(p);
    e := -p;
    f := max(r, n);
    m := nprintf(cat("%", r, ".", f-r, "f"), m);
    cat(`#mrow(mo("`, m, `"),mo("&#xd7;"),msup(mo("10"),mo("`, e, `")))`);
  end if;
end proc:

EngForm(1e3); # shows exponent 4

`#mo(".1e4")`

EngForm(1e4); # returns NULL

EngForm(10000.0); # returns NULL

EngForm(1.0); # returns NULL

EngForm(-31000.0); # drops minus sign

`#mrow(mo("31.0000"),mo("&#xd7;"),msup(mo("10"),mo("3")))`

Download EngineerNotation_ac.mw

@vicky2811 You may have uploaded it, but (as I cautioned) you also have to attach it after uploading.

After you upload the file then (inside the same popup menu) there will appear buttons that allow you to insert either a link to the attachment (URL) or an inlined display of the file along with a link.

You'd know you'd succeeded if you saw a blue hyperlink to the attachment, in your message.

Use the green up-arrow in the Mapleprimes editor to upload (and attach!) your Document here.

Nobody should have to retype your equations based on a screenshot.

@jeffreyrdavis75 Thanks for clarifying what you wanted.

restart;

f := x -> x^3 + 3^x:

plots:-densityplot(1, a=-17..23, b=-36..36,
                   grid=[401,401], style=surface,
                   colorscheme=["xyzcoloring",
                                [(x,y,z)->`if`(Im(f(x+y*I))>0,0.0,1.0),
                                 (x,y,z)->`if`(Re(f(x+y*I))<17 and Im(f(x+y*I))<0,1.0,0.0),
                                 (x,y,z)->`if`(Re(f(x+y*I))>17,0.0,1.0)]],
                   labels=["",""], size=[700,400], axes=boxed):

cplx_xyzcoloring.mw

Since f gets called several times with the same values then it could be more efficient as, say,
    f:=proc(x) option remember,system; x^3+3^x; end proc
though the above example wasn't terribly slow. I didn't bother.

If you really like the subdued colors in one of your question's images then something close can be obtained with minor adjustment to options and the color scheme functions.

f := x -> x^3 + 3^x:
plots:-densityplot(1, a=-17..21.5, b=-36..36,
                   grid=[615,600], style=surface,
                   colorscheme=["xyzcoloring",
                                [(x,y,z)->`if`(Im(f(x+y*I))>0,0.5,1.0),
                                 (x,y,z)->`if`(Re(f(x+y*I))<17 and Im(f(x+y*I))<0,1.0,0.5),
                                 (x,y,z)->`if`(Re(f(x+y*I))>17,0.5,1.0)]],
                   labels=["",""], size=[615,300],
                   axes=normal, axesfont=["Helvetica",8], xtickmarks=spacing(5));

Upload and attach your Maple Document, so that we might see what it actually contains.

@The function Your second function  (-2)^x  is complex-valued.

Ie,

(-2)^1.35;
        -1.157276832 - 2.271283669 I

Re((-2)^1.35);
              -1.157276832

Im((-2)^1.35);
              -2.271283669

In the first plot above the two separate curves represent its real and imaginary components, respectively, versus the independent parameter.

The second plot is by the complexplot command. You could compare that with the following parametric plot, in which the horizontal and vertical coordinates (at each point on the single curve) represent the real and imaginary components.

plot([Re((-2)^t), Im((-2)^t), t=0..10]);

@lekcha You can use colorscheme when calling densityplot (analogously to how I used it in the earlier code above, when using surfdata as part of the substitute for HeatMap in Maple 18).

Note that this is slower and less efficient that the earlier code I showed. The result of densityplot with such a high grid setting can also make the GUI slow and sluggush. The result may be harder to export. And the Maple 18.02 GUI may not be able to save the worksheet with such a high resolution densityplot output. These things get much worse as the grid gets large. All those consderations are a major part of why the method of using images (and the EscapeTime package) instead of plots was invented for such goals.

restart:

newton := proc(x, y)
    local z, m;
    z := evalf(x+y*I);
    for m from 0 to 15 while abs(z^3-1) >= 0.001 do
       z := z - (z^3-1)/(3*z^2)
    od;
    m;
 end:

cm := ["turquoise","cyan","blue", "brown","coral", "maroon",
       "orange", "pink", "magenta", "red", "sienna", "violet",
       "wheat", "yellow", "aquamarine", "black"]:

plots:-densityplot(newton, -2 .. 2, -2 .. 2, grid = [500, 500],
                   colorscheme=["zgradient",cm],
                   axes = none, scaling = constrained,
                   style = patchnogrid, size = [500, 500]);

 

newt_dens_Maple18_colorscheme.mw

Are you asking also about using a .m (dotm) file from within Maple, and not just about putting it as an attachment on a Mapleprimes posting?

Please put your closely related followup queries on this same topic as Replies under this Question thread, instead of posting a separate Question thread. (You've been asked this before.)

Duplicate Question threads will be flagged as such and may be delated.

First 123 124 125 126 127 128 129 Last Page 125 of 592