acer

32313 Reputation

29 Badges

19 years, 316 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are replies submitted by acer

Starting with the idea in the Answer by Rob Corless to divide by U__0, we could make a further adjustment.

By further specifying rescaled axis tickmarks (effectively now also multiplying by U__0) we can once again get a plot of U(t) -- which is what the textbook requested. Now U__0 is marked on the vertical axis, even if it is an unassigned symbolic name.

restart;

U := t -> U__0*exp(-1/10*t)*cos(2*t):

plot(U(t)/U__0, t = 0 .. 2*Pi,
     axis[2] = [tickmarks = [0 = 0, 1 = U__0]],
     labels = [t, 'U(t)'], size=[500,300]);

Download initial_U0.mw

or,

 

plot(U(t)/U__0, t = 0 .. 4*Pi,
     axis[2] = [tickmarks = [0 = 0, 1 = U__0],
                gridlines=[seq(-1..1,0.25)]],
     labels = [t, 'U(t)'], gridlines=true,
     view=-1..1, size=[500,300], axes=box);

I have submitted a bug report against this regression (apparently in hardware float mode).

I have also submitted a separate report against the following (which fails for my Linux in Maple 2015.2, 2018.2, and 2021.1 and might not be a regression).

restart; Digits:=20:
with(Statistics):
Histogram(Sample(Poisson(200),34508));
Error, (in Statistics:-Histogram) Segmentation Violation occurred in external routine

@erik10 I believe that the smoother performance is mostly due to the lesser burden on the GUI plot renderer.

I reduced the first value in the grid option of the densityplot call, from 49 down to 19. The GUI itself does some shading interpolation when rendering densityplots, so the horizontally coarser grid is cheaper but not visibly much coarser in appearance.

The second value, 2, was already as small as allowed. It can be so small because the color shading does not vary according to vertical position.

The computational transformation -- from a rectangle to the region below the curve -- is also less expensive for a coarser grid. A hand-tailored transforming routine might make that part a bit faster, but I wouldn't be surprised if GUI rendering overhead were still noticeable.

@erik10 Some more ideas to play with. The slider's action behaves a little more smoothly with the following, and the Slider's length is greater and a little easier to manage, etc.

Planck_curve_ac2.mw

@The function The other direct command (that I gave for your earlier problem) handles this newer example.

Student:-Calculus1:-Roots(tan(Pi/2 - x) - 4.6785, x = 0 .. 2*Pi, numeric);

              [0.2105750775, 3.352167731]

See my explanation above for how each works internally. This newer example is harder for NextZero (ie. fsolve with maxsols in your Maple), while the recursive fsolve approach of Calculus1:-Roots does better. There are also examples which Maple can solve but which stymie the calculators you mention. All numeric methods have some problematic cases.

@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));

First 122 123 124 125 126 127 128 Last Page 124 of 591