acer

32303 Reputation

29 Badges

19 years, 308 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

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

restart;

kernelopts(version);

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

eq:=-0.0004*x^2 - 2.7680*10^(-28)*x^12 - 2.1685*10^(-43)*x^18 - 1.3245*10^(-37)*x^16 - 1.6917*10^(-32)*x^14 + 0.7650 + 6.6773*10^(-18)*x^8 - 2.5543*10^(-23)*x^10 - 8.0002*10^(-13)*x^6 + 3.6079*10^(-8)*x^4 = 0:

plot(lhs(eq),x=-210..210,size=[500,200]);

fsolve(eq);

-202.6025057, -111.9794723, -49.07370166, 49.07370166, 111.9794723, 202.6025057

solve({eq, x<infinity}, x);

{x = -202.6025057}, {x = -111.9794723}, {x = -49.07370166}, {x = 49.07370166}, {x = 111.9794723}, {x = 202.6025057}


Download r01.mw

You can supply 

    output=L

to the,

   CodeTools:-Usage

command call. The list L can contain items like, value, realtime, bytesalloc, etc.

That makes it return an expression sequence of all those output choices. So you can get your hands on the timing/mem results programatically, as additional returned results.

You can then store items in that returned expression sequence, as you see fit. And your computation's own result is included in that sequence, if value is an item in the list L.

That's in contrast to the default behavior of a merely printed message containing the various stats, and only the value as single returned result.

Is this something like what you're after? (I realize that the final construct is not in terms of functional differential operators.)

I've used PDEtools:-undeclare(prime) to get the derivatives displayed in a "subscripted" notation.

restart

interface(showassumed = 0)

assume(tau::real); assume(sigma::real); alias(G = G(tau, sigma), F = F(tau, sigma))

PDEtools:-undeclare(prime, quiet)

X := G/F; Z := sigma+2*(diff(log(F), tau)-(diff(log(F), sigma)))

G/F

 

sigma+2*(diff(F, tau))/F-2*(diff(F, sigma))/F

(1)

X_tau_tau := simplify(diff(X, tau, tau)); X_sigma_sigma := simplify(diff(X, sigma, sigma))

((diff(diff(G, tau), tau))*F^2-2*(diff(G, tau))*(diff(F, tau))*F-G*(diff(diff(F, tau), tau))*F+2*G*(diff(F, tau))^2)/F^3

 

((diff(diff(G, sigma), sigma))*F^2-2*(diff(G, sigma))*(diff(F, sigma))*F+2*G*(diff(F, sigma))^2-G*(diff(diff(F, sigma), sigma))*F)/F^3

(2)

Z_tau := simplify(diff(Z, tau)); Z_sigma := simplify(diff(Z, sigma)); Z_tau_sigma := simplify(Z_tau+Z_sigma)

(-2*(diff(diff(F, sigma), tau))*F+2*(diff(F, sigma))*(diff(F, tau))+2*(diff(diff(F, tau), tau))*F-2*(diff(F, tau))^2)/F^2

 

1+2*(diff(diff(F, sigma), tau))/F-2*(diff(F, sigma))*(diff(F, tau))/F^2-2*(diff(diff(F, sigma), sigma))/F+2*(diff(F, sigma))^2/F^2

 

(2*(diff(F, sigma))^2-2*(diff(diff(F, sigma), sigma))*F+F^2+2*(diff(diff(F, tau), tau))*F-2*(diff(F, tau))^2)/F^2

(3)

eq := F^2*simplify(X_tau_tau-X_sigma_sigma+Z_tau_sigma*G/F) = 0

-(diff(diff(G, sigma), sigma))*F+2*(diff(G, sigma))*(diff(F, sigma))-G*(diff(diff(F, sigma), sigma))+(diff(diff(G, tau), tau))*F+F*G-2*(diff(G, tau))*(diff(F, tau))+G*(diff(diff(F, tau), tau)) = 0

(4)

D_tau_tau_G_F := (diff(G, tau, tau))*F-2*(diff(G, tau))*(diff(F, tau))+G*(diff(F, tau, tau)); D_sigma_sigma_G_F := (diff(G, sigma, sigma))*F-2*(diff(G, sigma))*(diff(F, sigma))+G*(diff(F, sigma, sigma))

(diff(diff(G, tau), tau))*F-2*(diff(G, tau))*(diff(F, tau))+G*(diff(diff(F, tau), tau))

 

(diff(diff(G, sigma), sigma))*F-2*(diff(G, sigma))*(diff(F, sigma))+G*(diff(diff(F, sigma), sigma))

(5)

simplify(eq, {D_tau_tau_G_F = Diff(G*F, tau, tau), D_sigma_sigma_G_F = Diff(G*F, sigma, sigma)})

F*G+Diff(F*G, tau, tau)-(Diff(F*G, sigma, sigma)) = 0

(6)

NULL

NULL

Download BE_ac.mw

I realize that this has some flaws; it can't get by discontinuities in the numeric solving, due to the set-up. But perhaps it might inspire you.

(I can't help but feel that I once knew some better way, but right now cannot recall it. I'm sure I'll kick myself, shortly.)

restart;

with(plots): interface(warnlevel=0):

epsilon := .01:

pot := 1/sqrt(x^2+y^2+epsilon)-1/sqrt((x-.25)^2+y^2+epsilon):

CP := contourplot(pot,x=-.1..0.35,y=-.25..0.25,contours=15,color="Burgundy"):

ds := dsolve({diff(y(x),x)=-1/subs(y=y(x),implicitdiff(pot,y,x)),y(0.125)=par},
             y(x),numeric,parameters=[par],abserr=1e-5):

SL := proc(p)
  ds(':-parameters'=[par=p]);
  display(odeplot(ds,[x,y(x)],x=-0.1..0.35,color=blue));
end proc:

display(CP, seq(SL(y0),y0=-3..3,0.04),
        view=[-0.1..0.35,-0.25..0.25]);

Download Dipole_fields_ac.mw

Is this the kind of thing you're after?

restart

_local(gamma)

with(PDEtools)

with(Physics)

undeclare(prime)

`There is no more prime differentiation variable; all derivatives will be displayed as indexed functions`

NULL

pde := -I*(diff(U(xi), xi))*gamma*k*mu+I*gamma*(diff(U(xi), xi))*sigma*w+(diff(diff(U(xi), xi), xi))*gamma*k*w+U(xi)*gamma*mu*sigma+(2*I)*(diff(U(xi), xi))*k*sigma+2*alpha*U(xi)^3+(diff(diff(U(xi), xi), xi))*k^2-I*(diff(U(xi), xi))*w-U(xi)*sigma^2-U(xi)*mu

-I*(diff(U(xi), xi))*gamma*k*mu+I*(diff(U(xi), xi))*gamma*sigma*w+(diff(diff(U(xi), xi), xi))*gamma*k*w+U(xi)*gamma*mu*sigma+(2*I)*(diff(U(xi), xi))*k*sigma+2*alpha*U(xi)^3+(diff(diff(U(xi), xi), xi))*k^2-I*(diff(U(xi), xi))*w-U(xi)*sigma^2-U(xi)*mu

case1 := [mu = -(4*gamma*k*w+4*k^2-sigma^2)/(gamma*sigma-1), A[0] = 0, A[1] = -RootOf(_Z^2*alpha+gamma*k*w+k^2), B[1] = RootOf(_Z^2*alpha+gamma*k*w+k^2), w = (gamma*k*mu-2*k*sigma)/(gamma*sigma-1)]

G1 := U(xi) = 2*RootOf(_Z^2*alpha+gamma*k*w+k^2)/sinh(2*xi)

`~`[`=`]([mu, w], eval([mu, w], case1)); C1 := solve(%, [mu, w])[]

[mu = -(4*gamma*k*w+4*k^2-sigma^2)/(gamma*sigma-1), w = (gamma*k*mu-2*k*sigma)/(gamma*sigma-1)]

[mu = (4*gamma*k^2*sigma+gamma*sigma^3+4*k^2-sigma^2)/(4*gamma^2*k^2+gamma^2*sigma^2-2*gamma*sigma+1), w = -k*(4*gamma*k^2+gamma*sigma^2-2*sigma)/(4*gamma^2*k^2+gamma^2*sigma^2-2*gamma*sigma+1)]

newcase1 := [op(C1), op(`~`[`=`]([A[0], A[1], B[1]], eval([A[0], A[1], B[1]], case1)))]

[mu = (4*gamma*k^2*sigma+gamma*sigma^3+4*k^2-sigma^2)/(4*gamma^2*k^2+gamma^2*sigma^2-2*gamma*sigma+1), w = -k*(4*gamma*k^2+gamma*sigma^2-2*sigma)/(4*gamma^2*k^2+gamma^2*sigma^2-2*gamma*sigma+1), A[0] = 0, A[1] = -RootOf(_Z^2*alpha+gamma*k*w+k^2), B[1] = RootOf(_Z^2*alpha+gamma*k*w+k^2)]

pde3 := eval(pde, newcase1)

-I*(diff(U(xi), xi))*gamma*k*(4*gamma*k^2*sigma+gamma*sigma^3+4*k^2-sigma^2)/(4*gamma^2*k^2+gamma^2*sigma^2-2*gamma*sigma+1)-I*(diff(U(xi), xi))*gamma*sigma*k*(4*gamma*k^2+gamma*sigma^2-2*sigma)/(4*gamma^2*k^2+gamma^2*sigma^2-2*gamma*sigma+1)-(diff(diff(U(xi), xi), xi))*gamma*k^2*(4*gamma*k^2+gamma*sigma^2-2*sigma)/(4*gamma^2*k^2+gamma^2*sigma^2-2*gamma*sigma+1)+U(xi)*gamma*(4*gamma*k^2*sigma+gamma*sigma^3+4*k^2-sigma^2)*sigma/(4*gamma^2*k^2+gamma^2*sigma^2-2*gamma*sigma+1)+(2*I)*(diff(U(xi), xi))*k*sigma+2*alpha*U(xi)^3+(diff(diff(U(xi), xi), xi))*k^2+I*(diff(U(xi), xi))*k*(4*gamma*k^2+gamma*sigma^2-2*sigma)/(4*gamma^2*k^2+gamma^2*sigma^2-2*gamma*sigma+1)-U(xi)*sigma^2-U(xi)*(4*gamma*k^2*sigma+gamma*sigma^3+4*k^2-sigma^2)/(4*gamma^2*k^2+gamma^2*sigma^2-2*gamma*sigma+1)

odetest(eval(G1, newcase1), pde3)

0

pde4 := collect(pde3, [U(xi)], simplify)

2*alpha*U(xi)^3-4*k^2*U(xi)/(1+(4*k^2+sigma^2)*gamma^2-2*gamma*sigma)+(diff(diff(U(xi), xi), xi))*k^2/(1+(4*k^2+sigma^2)*gamma^2-2*gamma*sigma)

odetest(eval(G1, newcase1), pde4)

0

Download test_sol_for_PDE1_ac.mw

You have mixed up the order of the arguments. You've used a different order, in two different places.

You have DOE set up with the columns (apparently) being:
    epsilon, A, Br, N, beta, m, lambda0, lambda1

But you constructed your procedure Fop to treat its arguments as if the order were,
    A, Br, N, beta, epsilon, lambda[0], lambda[1], m

I'm guessing that the wrong one is your construction of Fop, because there you just used a lexicographic order, and ignored how you set up the columns of DOE.

So I suppose that you wanted Fop more like this: Answer_not_same_ac.mw

Such a placeholder is not required. And you don't need to substitute into a diff(...) result.

Instead, you can just use D(W). You can use it as D(W)(u(t)) in your DE for dsolve. And you can use it for D(W)(u) in your fieldplot call.

And you also don't need to define W the same way, a second time. Since the original W was defined before the parameters were assigned values then calls to W or D(W) will pick up the latest parameter values assigned.

So your same processes can become more tidy and legible, eg, proteins_ac.mw

If you really want to visualize the latest parameter values in the formula then you can just invoke it to print it, eg.
   D(W)(Un);

If you want you can assign D(W) to some name, to avoid having D repeat effort. Eg,
   dW := D(W);
and then use that. Eg. proteins_acc.mw

You could put all your procedures into a package module, and then LibraryTools:-Save that instead.

See also the relevant section of the Programming Guide.

Here are various ways in which one may leverage the collect command to attain the target form.

restart;

Zin := ((Rsp + (omega*L2 - omega02^2*L2/omega)*I)*(Rpp + (omega*L1 - omega01^2*L1/omega)*I) + 0.01*omega^2*L1*L2)/(Rsp + (omega*L2 - omega02^2*L2/omega)*I);

((Rsp+I*(omega*L2-omega02^2*L2/omega))*(Rpp+I*(omega*L1-omega01^2*L1/omega))+0.1e-1*omega^2*L1*L2)/(Rsp+I*(omega*L2-omega02^2*L2/omega))


Zout := Rpp + (omega*L1 - omega01^2*L1/omega)*I + (0.01*omega^2*L1*L2)/(Rsp + (omega*L2 - omega02^2*L2/omega)*I);

Rpp+I*(omega*L1-omega01^2*L1/omega)+0.1e-1*omega^2*L1*L2/(Rsp+I*(omega*L2-omega02^2*L2/omega))

First, lets assign that denominator to a name, so that we
can more easily manipulate and collect/simplify w.r.t it.

FF:=1/select(type,Zin,anything^(-1));

Rsp+I*(omega*L2-omega02^2*L2/omega)

Let's also veil that 0.01 float, using a placeholder for it. Otherwise various reasonable techniques will get some
subexpression with coefficients of 1. or 1.000..., etc.
(Converting it to rational is not helpful, if you want only that very same float back at the end.)
We can't freeze a float directly, to I'll also wrap with a dummy function.

temp := simplify(subsindets(Zin,float,freeze@__K),{FF=FFF});

((I*L1*omega^2-I*L1*omega01^2+Rpp*omega)*FFF+L1*L2*omega^3*`freeze/R0`)/(omega*FFF)

Going for the target just as you had it, ie. some subexpressions not completely factors w.r.t L1, L2.

Since we cannot collect w.r.t imaginary unit I directly, temporarily replace that too.

subs(I=II,temp):
eval(collect(%,[Rpp,II,omega01],thaw),[II=I,FFF=FF,__K=(x->x)]);

Rpp+I*(omega*L1-omega01^2*L1/omega)+0.1e-1*omega^2*L1*L2/(Rsp+I*(omega*L2-omega02^2*L2/omega))

Alternatively, frontend the collect, so that we may collect w.r.t I.

eval(frontend(collect,[temp,[Rpp,L2,I,omega],thaw],
              [{`+`,`*`,list},{}]),
     [FFF=FF,__K=(x->x)]);

Rpp+I*(omega*L1-omega01^2*L1/omega)+0.1e-1*omega^2*L1*L2/(Rsp+I*(omega*L2-omega02^2*L2/omega))

The choice of variables for which we may collect is not unique.

subs(I=II,temp):
eval(collect(%,[FFF,Rpp,II],thaw),[II=I,FFF=FF,__K=(x->x)]);

Rpp+I*(L1*omega^2-L1*omega01^2)/omega+0.1e-1*omega^2*L1*L2/(Rsp+I*(omega*L2-omega02^2*L2/omega))

These are the kind of irritating 1.000... artefacts that may arise if we
don't veil that float coefficient.

simplify(Zin,{FF=FFF});
eval(collect(subs(I=II,%),[FFF,Rpp,II,omega],thaw),[II=I,FFF=FF]);

0.1000000000e-1*((100.*I)*FFF*L1*omega^2-(100.*I)*FFF*L1*omega01^2+L1*L2*omega^3+100.*FFF*Rpp*omega)/(omega*FFF)

1.000000000*Rpp+I*(1.000000000*omega*L1-1.000000000*omega01^2*L1/omega)+0.1000000000e-1*omega^2*L1*L2/(Rsp+I*(omega*L2-omega02^2*L2/omega))

As I mentioned in my Reply, some of the subexpressions may
be further factored (say, w.r.t L1 or L2).

eval(collect(temp,[FFF,Rpp,L2],simplify@thaw),[FFF=collect(FF,L2),__K=(x->x)]);

Rpp+I*L1*(omega^2-omega01^2)/omega+0.1e-1*omega^2*L1*L2/(I*(omega-omega02^2/omega)*L2+Rsp)

Download collect_I_ex.mw

You can simply pass the explicit option, to get the result in terms of explicit radicals directly from the solve command.

eq1 := y=1/2*(x-5)^2-6:
eq2 := y=3*x-2:

solve([eq1,eq2],{x,y},explicit);

{x = 8+47^(1/2), y = 22+3*47^(1/2)}, {x = 8-47^(1/2), y = 22-3*47^(1/2)}


Download solve_sys_expl.mw

In other words, you don't need to use two different commands to get the roots in radical form.

For a polynomial system involving more than one variable then results involving roots/radicals are not expressed in explicit form by default (even for this low degree).

See also the subsection Controlling the Form of Solutions in the Help page for topic solve,details . (Unfortunately, the difference between a single polynomial in one variable and system is not made entirely clear there, in this respect.)

First 14 15 16 17 18 19 20 Last Page 16 of 336