acer

31448 Reputation

29 Badges

19 years, 135 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

Try NULL instead of your null.

That is the empty value/statement which you mentioned. It will be seen an nothing by the display command.

One might imagine/hope that the size option or a background image on a 2D plot might allow one to force an aspect ratio of the axes. If that were the case, and since plottools:-getdata can pretty much obtain the extent of the axes, then we could programatically force agreement with the textplot rotation angle.

Alas these things appear disconnected, because the size option controls only the inline bounding box dimensions, and is thrown off by caption, axes labels and tickmark width/heights.

restart;

with(plots):

 

plot(-x^2, size=[400,200]);

We can see that the next red curve extends
over a wider portion of the inline box.

display( plot(x^2, size=[400,200]),
         axes = none );

Now it's even smaller than the first one,
because the tickmarks take up space in the
inline box.

display( plot(x^2, size=[400,200]),
         axes = boxed );

The labels can also take up space.
Notice that the in the following rendering
the aspect ratio of the axes box is not the
same as that of the bounding box.

Since we therefore not use the size option to
control the aspect ratio of the axes then we cannot
programatically get force the aspect ratio of the
axes to match appropriately with the rotation angle
of a textplot.

(I feel that this incompatibility is a design mistake.)

display( plot(x^2, size=[400,200]),
         labels = [rrrrrrrrrrrrr,uuuu],
         labeldirections = [vertical, horizontal],
         axes = boxed );


Download plot_box_dims.mw

Next, here's a worksheet showing and explaining how the things mentioned above will affect matching a textplot with rotation. (Sorry, the site's not letting me display that here. So, download only.)
2024-10-15_text_not_always_parallel_ac.mw

As for rotated text in an image, well it's hard to get that right because the GUI and your OS don't know that the pixels represent text and so cannot anti-alias, etc. It's hard to have the rotated text be legible without making it thick and chunky.

Having said that, FWIW here, in modern Maple versions you can make such rotated text images entirely with ImageTools.

restart;

with(ImageTools): with(Draw):

f := 3.3*x:

img := Create(700,700,channels=1,background=white):

Text(img, 325, 350, "parallel piece of text", rotation=Pi/4,
     font_size=16, font=12, weight=2, color="Black"):

plot(f(x), x=0..461, background=img);


Download img_text_plot_rot.mw

A 12pt font character (say, "m") is about 16 pixels wide, at 100% zoom factor.

That's approximate, and it'll vary by font (esp. variable width font, by character, of course). But you can easily find such information on the interwebs, eg. here. (note also this kind of thing)

The size info is used by the GUI to set the dimensions of the inlined plot bounding box. So things like caption, the difference in height of x-axis labels/ticks vs y-axis label/tick (including their orientation) will all throw off the actual aspect ratio of the rendered axes.

I mean to mention some of that to you in response to your recent rotated text Question, but got busy with other things, sorry. I'll try and do that soon.

You have mistakenly entered your expression assigned to F, in 2D Input.

You have terms like l(...) and m(...) without either a space or an explicit multiplication sign between the first term and the opening bracket.

That makes those terms be function calls, instead of products of terms. It's just like having f(x+y) a function call of f with argument x+y, instead of f*(x+y) a product of two terms.

simplify_b_ac.mw

Using Maple 2022.2, I get the following,

restart

s := -2*B1*(A1^2*B2^2*exp((-(2*I)*exp(2*beta2*t)*lambda2^2+2*x*lambda2*(a*beta1-beta)*exp(beta2*t)+beta1*t*beta2)/beta1)-2*A1*A2*B1*B2*exp(((2*I)*(beta1-2*beta2)*lambda2^2*exp(2*beta2*t)+2*x*lambda2*((a*beta2+beta)*beta1-2*beta*beta2)*exp(beta2*t)+beta2^2*t*beta1)/(beta1*beta2))+A2^2*B1^2*exp(((4*I)*lambda2^2*(beta1-3*beta2*(1/2))*exp(2*beta2*t)+(2*((a*beta2+2*beta)*beta1-3*beta*beta2))*x*lambda2*exp(beta2*t)+beta2^2*t*beta1)/(beta1*beta2)))*(beta1-beta2)*B2*lambda2/(sigma*(-A2*exp(2*exp(beta2*t)*lambda2*(beta1-beta2)*(I*exp(beta2*t)*lambda2+beta*x)/(beta1*beta2))*B1+A1*B2)^3)

simplify(expand(s))

-2*(beta1-beta2)*B1*B2*exp(2*x*lambda2*exp(beta2*t)*a+beta2*t)*lambda2/((A1*B2*exp(2*lambda2*exp(beta2*t)*(I*exp(beta2*t)*lambda2+beta*x)/beta1)-A2*exp(2*lambda2*exp(beta2*t)*(I*exp(beta2*t)*lambda2+beta*x)/beta2)*B1)*sigma)

(1)


The above is zero is any of these (individually) is satisfied:

`~`[remove](evalb, solve(%, [A1, A2, B1, B2, beta1, beta2]))

[[beta1 = beta2], [B1 = 0], [B2 = 0]]

(2)


Download ss_ac.mw

(We can also get solution lambda2=0 from the numerator, by eye or by a more general solve. You could also find conditions for which the denominator of the above is zero, using solve.)

ps. Not everone has Equation Labels enabled in their GUI preferences. So your mentioning Eq (1). is not immediately useful to everyone. (I don't see such labels even when I merely Open your .mw file. I have to go to GUI Options, enable that, then reexecute the whole sheet, and hope nothing was Cut since your own last execution. Luckily this example is simple enough to guess or re-do.) If you mean the expression assigned to s, then it's more immediately helpful to state that, thanks.

With the assumptions provided later in a Reply by the OP, a single result for eliminating {h, v1, t} can be obtained directly from solve.

restart;

kernelopts(version);

`Maple 2024.1, X86 64 LINUX, Jun 25 2024, Build ID 1835466`

solve({v1^2 = 2*g*(h - h1), 1/2*g*t^2 = h2, v1*t + 1/2*g*t^2 = h1},
      {h, t, v1}, useassumptions) assuming g > 0, t > 0;

{h = (1/4)*(h1^2+2*h1*h2+h2^2)/h2, t = 2^(1/2)*(g*h2)^(1/2)/g, v1 = (1/2)*(h1-h2)*g*2^(1/2)/(g*h2)^(1/2)}


Download solve_pos_ex.mw

nb. The OP has not indicated whether he prefers to eliminate g rather than t, or vice versa. These equations can be solved explicitly for [h,v1,t], or for [h,v1,g], but we don't (yet) know which the OP would prefer.

What is a candidate/typical value for your a parameter? What range for the r parameter?

Have you looked at the IterativeMaps package? (It can be fast, but finicky, and sometimes unstable.) You might start with the Bifurcation command [here, or here], or the more flexible command. Eg. some_bif_ex.mw

You could also try modifying earlier code variants to get the usual Logistic map image (but some done more like plots). [more references..]

If you want it colored/shaded, rather than monotone, then nice rescaling of values can get tricky.

@Susana30 For your followup question:
[Alternative to these below which both restrict the viewing range, you could play with a restricted domain for the red curve.]

restart;

with(plots):

 

display(polarplot([$1..12], color="LightGray"),
        plot([seq(x/tan(i*Pi/6), i=[$-2..-1,$1..2])], color="LightGray"),
        polarplot([4+4*sin(theta), 3/(1-sin(theta))],
                       color=["Green","Red"]),
        axiscoordinates=cartesian, scaling=constrained,
        tickmarks=[[seq(i=String(i),i=-9..6)],
                   [seq(i=String(i),i=-4..10)]],
        font=["Times",7],
        view=[-9..7, -5..10.6]);

polarplot([4+4*sin(theta), 3/(1-sin(theta))],
          color=["Green","Red"],
          coordinateview=[0..11,default]);

 

 

Download pol_fun.mw

This followup action line-prints the variable=value pairs, and formats the display of a procedure body with line-breaks and indenting.

You should be able to copy&paste that line-printed display of the proc (as 1D Maple input, aka Maple Notation). Or you could use fprintf instead, to write it straight to a text file.

(If you still have trouble, you might zip up the .m file and then upload and attach it here.)

restart;

foo,bar := blah,17:

 

show := proc(f::string)
  local temp := {anames(':-user')};
  read f;
  map(u -> parse(String(u)) = eval(u),
      {anames(':-user')} minus temp);
end proc:


The following returns the set of name=value pairs.
 

res := show("mydotfile.m");

{blech = proc (f, t) local i, n, r, x, f0; option `Copyright (c) 1993 by the University of Waterloo. All rights reserved.`; global D; if nargs < 2 or not (args[-1])::'list' then error "invalid arguments" elif type(f, 'function') then f0 := op(0, f); if type(f, 'constant') and type(f0, 'mathfunc') then f elif f0 = '`@`' then n := nops(f); if type(t, '[function]') and type(op(0, t[1]), 'anything@@anything') and op(n, f) = op([0, 1], t[1]) then (`@`(op(1 .. n-1, f)))((op(n, f)@@(op([0, 2], t[1])+1))(op(t[1]))) else r := op(t); for i from n by -1 to 1 do x := op(i, f); if (x = 'eval' or sprintf("%a", x) = "eval") and nops([r]) = 2 then r := x(eval(r[1], 1), r[2]) else r := x(eval(r, 1)) end if end do; eval(r, 1) end if elif f0 = '`@@`' then n := op(2, f); if type(t, '[function]') and op(0, t[1]) = op(1, f) then (op(1, f)@@(n+1))(op(t[1])) elif type(t, '[function]') and type(op(0, t[1]), 'anything@@anything') and op(1, f) = op([0, 1], t[1]) then (op(1, f)@@(n+op([0, 2], t[1])))(op(t[1])) elif type(n, 'integer') then if 0 <= n then r := t; for i to n do if type(r, [('specfunc')(op(1, f))]) then break end if; r := [(proc (F, X) F(args[2 .. -1]) end proc)(op(1, f), r[])] end do; if n < i then r[] else (proc (f) ('f')(args[2 .. nargs]) end proc)(op(1, f)@@(n-i+2), op(r[])) end if else subsop(1 = op(t), 'f(x)') end if elif nops(t) = 1 and type(op(1, f), '{identical(D), specindex(D)}') and (t[1])::'{`=`, algebraic}' then r := op(1, f); if r = D then r := setattribute(D[`$`(1, n)], f) else r := D[seq(`$`(i, n), i = op(1, f))] end if; i := r(t[1]); if op(0, i) <> r then if i = 'i' and i::'{table, `D/procedure_or_applyable_module`}' then eval(i, 2) else i end if else ('f')(op(t)) end if else ('f')(op(t)) end if elif f0 = 'DESol' then if not type(f, 'DESol(operator)') then error "cannot apply non-operator differential equation" end if; `DESol/apply`(f, t) elif type(f0, 'name') then userinfo(1, evalapply, `general function case`, [f, t]); n := f0; if type(n, 'indexed') then r := `evalapply/` || (op(0, n)); if type(r, 'procedure') then try r[op(n)](f, t) catch: error  end try else ('f')(op(t)) end if else r := cat('`evalapply/`', n); if type(r, 'procedure') then r(f, t) else ('f')(op(t)) end if end if elif f0::'{identical(D), specindex(D)}@@nonnegint' and nops(f) = 1 then return `evalapply/@@/D`(op(f0), op(f), t) else ('f')(op(t)) end if else subs(x = op(t), 'f(x)') end if end proc, x = 4, y = 3.1}


The following line-prints the entries of that set using printf, where
the %P format to get nice line-breaking of a saved procedure.
 

interface(verboseproc=2):
map[2](printf,"%P\n",eval(res,1)):

blech = (proc(f, t)
    local i, n, r, x, f0;
    global D;
    option `Copyright (c) 1993 by the University of Waterloo. All rights\
     reserved.`;
    if _npassed < 2 or not _passed[-1]::'list' then
        error "invalid arguments";
    elif type(f, 'function') then
        f0 := op(0, f);
        if type(f, 'constant') and type(f0, 'mathfunc') then
            f;
        elif f0 = '`@`' then
            n := nops(f);
            if type(t, '[function]') and
            type(op(0, t[1]), 'anything@@anything') and
            op(n, f) = op([0, 1], t[1]) then
                `@`(op(1 .. n - 1, f))(
                    ((op(n, f))@@(op([0, 2], t[1]) + 1))(op(t[1])));
            else
                r := op(t);
                for i from n by -1 to 1 do
                    x := op(i, f);
                    if (x = 'eval' or sprintf("%a", x) = "eval") and
                    nops([r]) = 2 then
                        r := x(eval(r[1], 1), r[2]);
                    else
                        r := x(eval(r, 1));
                    end if;
                end do;
                eval(r, 1);
            end if;
        elif f0 = '`@@`' then
            n := op(2, f);
            if type(t, '[function]') and op(0, t[1]) = op(1, f) then
                ((op(1, f))@@(n + 1))(op(t[1]));
            elif type(t, '[function]') and
            type(op(0, t[1]), 'anything@@anything') and
            op(1, f) = op([0, 1], t[1]) then
                ((op(1, f))@@(n + op([0, 2], t[1])))(op(t[1]));
            elif type(n, 'integer') then
                if 0 <= n then
                    r := t;
                    for i to n do
                        if type(r, ['specfunc'(op(1, f))]) then
                            break;
                        end if;
                        r := [(proc(F, X) F(_passed[2 .. -1]); end proc)(
                            op(1, f), r[])];
                    end do;
                    if n < i then
                        r[];
                    else
                        (proc(f) 'f'(_passed[2 .. _npassed]); end proc)(
                            (op(1, f))@@(n - i + 2), op(r[]));
                    end if;
                else
                    subsop(1 = op(t), 'f(x)');
                end if;
            elif
            nops(t) = 1 and type(op(1, f), '{identical(D), specindex(D)}')
             and t[1]::'{`=`, algebraic}' then
                r := op(1, f);
                if r = D then
                    r := setattribute(D[1 $ n], f);
                else
                    r := D[seq(i $ n, i = op(1, f))];
                end if;
                i := r(t[1]);
                if op(0, i) <> r then
                    if i = 'i' and
                    i::'{table, `D/procedure_or_applyable_module`}' then
                        eval(i, 2);
                    else
                        i;
                    end if;
                else
                    'f'(op(t));
                end if;
            else
                'f'(op(t));
            end if;
        elif f0 = 'DESol' then
            if not type(f, 'DESol(operator)') then
                error "cannot apply non-operator differential equation";
            end if;
            `DESol/apply`(f, t);
        elif type(f0, 'name') then
            userinfo(1, evalapply, `general function case`, [f, t]);
            n := f0;
            if type(n, 'indexed') then
                r := `evalapply/` || (op(0, n));
                if type(r, 'procedure') then
                    try r[op(n)](f, t); catch: error ; end try;
                else
                    'f'(op(t));
                end if;
            else
                r := cat('`evalapply/`', n);
                if type(r, 'procedure') then
                    r(f, t);
                else
                    'f'(op(t));
                end if;
            end if;
        elif f0::'{identical(D), specindex(D)}@@nonnegint' and nops(f) = 1
        then
            return `evalapply/@@/D`(op(f0), op(f), t);
        else
            'f'(op(t));
        end if;
    else
        subs(x = op(t), 'f(x)');
    end if;

end proc)
                                     x = 4
                                    y = 3.1


Download read_ex1.mw

You might consider a revision to your first (symbolic series dsolve) approach. You could instead search your Y1 list with a binary search. On my machine that reduces its time from 41.1 sec down to just 0.33 sec.

Note also that Y gets formed by merely splitting the range -2..5  by increments of 0.002. So the first element of Y1 which makes exp1>exp2 is a coarse root approximation. A little hammering can make a procedure with which fsolve can find finer resolution roots for your X1 values. On my machine that takes 3.9 sec.

Proc_Error_ac2.mw

If you also adjust your second approach to do a binary search (of Y1) then you can quickly determine that the numeric integration is not succeeding for some avar,bvar values. I'm not sure how that integration issue might be best resolved, or even whether it first occurs before exp1>exp2 is satisfied, etc. But this attachment also shows such problematic values.

Proc_Error_ac.mw


(Could the DE be augmented, instead of doing a separate integration involving the dsolve solution? I didn't really look, to see if that makes sense... Sorry, no time)

A minor adjustment can switch the x- and y- roles in the data, before the interpolation. This flips the densityplots across the x=y line (...one of several ways to do that).

Also, in your fourth construction your final call to plots:-display is wrongly using C11 (from earlier), instead of the new C22 as in that fourth part. I've corrected that. Now the fourth pair agree, with the switch.

Help_4_ac.mw

For example, here is that fourth pair overlaid, with the variable switch before interpolation as well as the C11->C22 correction.

(This code looks like it may have been a modification of this.)

ps. I used Maple 2015.2 for this, since that's your version. In later Maple versions some aspects might be easier or more flexible.

@salim-barzani Another choice for experimenting with plotting options is to use the PlotBuilder (either by right-click on an expression/output or -- my preference -- using the command).

PB_3d_ex.mw

If you put the mouse cursor/focus back on the PlotBuilder's plot then the right-panel gets repopulated with its menus, etc. But you can also switch back-and-forth between that and other work areas in your worksheet.

It's not clear what you mean by "template" above. Are you saying that you want to extract the numeric data generated in the plot structure, and then export that (as a Matrix of numbers, say), to Matlab or other programs? That's trickier for densityplot, but for plot3d you can use the plottools:-getdata and ExportMatrix commands.

For densityplot, one could extract the genetrated numeric Array of shading color values. Let us know if that's what you need, in say your Maple 2021.

You can combine multiple 3D plots by passing them to the plots:-display command.

I'm marking this Question as being for the "Maple 2021" Product, since that's your version (and, for some commands, the version matters). In future, could you please do that yourself? Also, please don't mark your queries about Maple as being for "Mapleprimes" and other products, thanks.

The GUI does not actually use a Maple command, when it adjusts the plot's characteristics via that right-click menu. What the GUI has at hand is the PLOT call structure.

There is some new-ish "re-draw" stuff related to a command that the Maple plotting commands sometimes inject as text into the plotting structure -- eg. PLOT function call, as structure. It can use that now for some zooming. For example you can zoom out of the following plot, and magically the (post Maple 2022) GUI will cause the plot command to be reformed with a widened range, and reexecuted.

P:=plot(sin(1/x), x=0..1, gridlines=true):
indets(P,"input"=anything); # outputs the following:

{"input" = [table([1 = plot, 2 = [sin(1/x)], 3 = (x = 0 .. 1), 4 = (gridlines = true)]), "originalview" = [0.0000192831942484872343 .. 0.997499999997671694, -1. .. 1.], "originalaxesticks" = AXESTICKS(DEFAULT, DEFAULT, _ATTRIBUTE("source" = "mathdefault"))]}

So, that is actually stored in the PLOT function call (data structure) that the Library plot command produces, in modern Maple. And when the rendered, inline plot is zoomed out then the GUI is now able to send a modified reconstruction of the plotting command call, to the kernel. The original structure only had data computed for x=0..1, but after zoom-out the reexecuted call can recalculate for the wider range.

But the GUI's knowledge of how to adjust the call is limited. It knows how to change the range, but not everything. And not all plotting commands store the details in the structure. And, importantly, there's no place for the GUI to hand back the modified command (or even the new output structure) to the user.

A plot in a PlotComponent does allow the user to access the GUI's stored structure. If you right-click the above plot when inside a PlotComponent, and change the color, then you can programmatically extract the modified plot structure from the embedded component (GetProperty). But unfortunately the spiffy zoom-out redraw/reexecute thing doesn't seem to work in a component. And the GUI lacks knowledge about how to itself adjust the relevant stored command data, in most cases.

That leaves the PlotBuilder. You can issue,
   PlotBuilder(lhs(eq));
and, in the right-panel, modify the range and the gridline choices, etc, and toggle on the "Show Command" button. That can be a handy way to explore various option choices, and see/copy the underlying command. Unfortunately it doesn't yet support discrete data (eg. your list of numeric root values, for which pointplot could be a choice).

@salim-barzani In the attached variant, the lastest parameter values used in the exploration are available (outside the exploration). They are assigned in a list to the name last.

graph_in_simple_shape_accc.mw

You could, of course, subsequently programmatically substitute those values into your M expression, if you also need that.

Alternatively, the following variant has the latest instance of M (substituted) assigned to the name last.

graph_in_simple_shape_acccB.mw

5 6 7 8 9 10 11 Last Page 7 of 327