acer

32400 Reputation

29 Badges

19 years, 344 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

The plotting command plots:-surfdata can handle a 2-dimensional Array or Matrix of data (z-values). It has the advantage over matrixplot in the sense that surfdata accepts a 2nd and a 3rd parameter to specify the ranges over which to interpret the independent axes.

If I import your attached .xlsx file then I get a 9-by-4 Matrix of values. I could plot that and specify the ranges for the x- and y-axes, but I don't see how the given data can be expected to give a plot like the one in your Question's image.

You could add additonal options, (such as scaling=constrained , etc), to adjust the look&feel of the plot. See the plot3d,options Help page. Of course the data could also be flipped or transposed.

restart;

#Import("PlotTest.xlsx");

M := ExcelTools:-Import("PlotTest.xlsx");

_rtable[18446884401930645806]

plots:-surfdata(M, 1.25 .. 5.0, 0.4 .. 1.5);

 

Download surfexample.mw

There are several obstacles in the way of using save and read to store and recover a random variable. There are the attributes. There are the modules. In general modules cannot be properly saved to .m format (it takes storing to .mla format to store module locals), but you might be able to kludge around it here. And there is an unknown risk that Statistics might register some information about the previously generated RVs in some additional location which we don't know about.

I think that your ongoing efforts to rip apart Statistic's RVs -- and put them back together again -- is somewhat dubious. It might be workable, but perhaps only partially. It clearly wasn't designed for that. (The package predates objects, and uses its own special, undocumented techniques to get object-oriented effects.)

So I would suggest that instead you store whatever is needed to create the RVs afresh -- using only stock, documented Statistics commands like RandomVariable, Distribution, etc).

Having said that, you might find the following of some interest (Maple 2020.0). I hope that it's clear that the following is in the dubious realm, and not what I meant by using stock, documented techniques.

restart;

V := Statistics:-RandomVariable(Normal(0, 1));
attributes(V);

_R

protected, RandomVariable, _ProbabilityDistribution

Statistics:-Sample(V, 5);

Vector[row](5, {(1) = -1.072424127998269, (2) = -.329077870547065, (3) = -.6170919369097896, (4) = .21446674524529077, (5) = -0.25428128042384635e-1})

K := eval([attributes(V)][3]);

_m139820665320832

save K, "rvs.m";

restart;

with(Statistics): # this is a kludge
read "rvs.m";
unwith(Statistics):

eval(K);

_m139820665280512

V := `tools/genglobal`(_R);
setattribute(V, protected, ':-RandomVariable',
             :-`tools/genglobal`(':-_ProbabilityDistribution')):
attributes(V);
assign([attributes(V)][3], eval(K));

_R

protected, RandomVariable, _ProbabilityDistribution

Statistics:-Sample(V, 5);

Vector[row](5, {(1) = -1.072424127998269, (2) = -.329077870547065, (3) = -.6170919369097896, (4) = .21446674524529077, (5) = -0.25428128042384635e-1})

 

Download RV_save_read.mw

 

There are several ways to go about this.

For example, you could obtain the result directly using the value command (or the active int command).

Or, if it's homework and you've been told to do it in a particular fashion, you could do it step by step. There too you have several choices about how to go about it. I'll give just one way, utilizing integration-by-parts, as illustration. (In this case I don't know what knowledge you have. If you do not see how integration-by-parts is working in each of the three calls below then please say so.)

Or, are you expected to express the formula for integration-by-parts, and then substitute for the various parts, exactly as if you were doing it by hand on paper?

I don't see limits of integration in your Question. Did you intend on supplying them?

restart;

U := Int( (120+2*t)^3/2 * (1+sin(t)), t );

Int((1/2)*(120+2*t)^3*(1+sin(t)), t)

ans2 := simplify( value(U) );

(-4*t^3-720*t^2-43176*t-862560)*cos(t)+(12*t^2+1440*t+43176)*sin(t)+t*(t+120)*(t^2+120*t+7200)

with(Student:-Calculus1):
Understand(Int, sum, constantmultiple):

IntegrationTools:-Parts(U, (120 + 2*t)^3);

((1/2)*t-(1/2)*cos(t))*(120+2*t)^3-(Int(6*((1/2)*t-(1/2)*cos(t))*(120+2*t)^2, t))

IntegrationTools:-Parts(%, (120 + 2*t)^2);

((1/2)*t-(1/2)*cos(t))*(120+2*t)^3-((3/2)*t^2-3*sin(t))*(120+2*t)^2+Int(((3/2)*t^2-3*sin(t))*(480+8*t), t)

IntegrationTools:-Parts(%, 480 + 8*t);

((1/2)*t-(1/2)*cos(t))*(120+2*t)^3-((3/2)*t^2-3*sin(t))*(120+2*t)^2+((1/2)*t^3+3*cos(t))*(480+8*t)-(Int(4*t^3+24*cos(t), t))

IntegrationTools:-Expand(%);

((1/2)*t-(1/2)*cos(t))*(120+2*t)^3-((3/2)*t^2-3*sin(t))*(120+2*t)^2+((1/2)*t^3+3*cos(t))*(480+8*t)-4*(Int(t^3, t))-24*(Int(cos(t), t))

rhs( Rule[power](%) );

((1/2)*t-(1/2)*cos(t))*(120+2*t)^3-((3/2)*t^2-3*sin(t))*(120+2*t)^2+((1/2)*t^3+3*cos(t))*(480+8*t)-t^4-24*(Int(cos(t), t))

rhs( Rule[cos](%) );

((1/2)*t-(1/2)*cos(t))*(120+2*t)^3-((3/2)*t^2-3*sin(t))*(120+2*t)^2+((1/2)*t^3+3*cos(t))*(480+8*t)-t^4-24*sin(t)

ans1 := simplify(%);

(-4*t^3-720*t^2-43176*t-862560)*cos(t)+(12*t^2+1440*t+43176)*sin(t)+t*(t+120)*(t^2+120*t+7200)

simplify(ans2-ans1);

0

 

Download example_byparts.mw

 

See the smartview option on the plot,options Help page

restart; plots:-setoptions(size = [300, 300])

s_eq := diff(s(t), t) = -ir*i(t)*s(t); i_eq := diff(i(t), t) = ir*i(t)*s(t)-rr*i(t); d_eq := diff(d(t), t) = dr*i(t); ics := s(0) = s0, i(0) = i0, d(0) = 0

"i0:=1.E3:    P0:=3.E8:    drate:=0.02:     s0:=0.6*P0:    ir:=(0.1)/(s0):   rr:=1/(30.):  dr:=rr*drate:   "

sol := dsolve({d_eq, i_eq, ics, s_eq}, numeric); tf := 120; plots:-odeplot(sol, [t, d(t)], 0 .. tf)

sol := dsolve({d_eq, i_eq, ics, s_eq}, numeric, output = listprocedure); i := eval(i(t), sol); s := eval(s(t), sol); d := eval(d(t), sol)

tf; plot(d(t), t = 0 .. tf)

120

plot(d(t), t = 0 .. tf, smartview = false)

 

Download plot_view_problem_smartview.mw

Yes, it is a long-standing gripe that the GUI Table (inserted by the GUI when rendering arrays of plots) cannot be programmatically controlled and has suboptimal behavior.

You could try DocumentTools:-Tabulate instead, also making use of some of its additional functionality for controlling placement of the whole Table, dimensions, borders, etc.

I'd be interested in knowing how well its embedded Tables did upon export to PDF.

Here are two ways:

restart

combine(2*s^2*(int(Phi[1, 1](x, T[2])*(diff(Y1(x), x, x)), x = 0 .. x1))+int(Phi[1, 1](x, T[2])*(diff(Y1(x), x, x, x, x)), x = 0 .. x1)-omega_y^2*(int(Y1(x)*Phi[1, 1](x, T[2]), x = 0 .. x1)), int)

int(Phi[1, 1](x, T[2])*(diff(diff(diff(diff(Y1(x), x), x), x), x))+2*s^2*Phi[1, 1](x, T[2])*(diff(diff(Y1(x), x), x))-omega_y^2*Y1(x)*Phi[1, 1](x, T[2]), x = 0 .. x1)

simplify(%);

int(Phi[1, 1](x, T[2])*(diff(diff(diff(diff(Y1(x), x), x), x), x)+2*s^2*(diff(diff(Y1(x), x), x))-omega_y^2*Y1(x)), x = 0 .. x1)

IntegrationTools:-Combine(2*s^2*(int(Phi[1, 1](x, T[2])*(diff(Y1(x), x, x)), x = 0 .. x1))+int(Phi[1, 1](x, T[2])*(diff(Y1(x), x, x, x, x)), x = 0 .. x1)-omega_y^2*(int(Y1(x)*Phi[1, 1](x, T[2]), x = 0 .. x1)), int)

int(Phi[1, 1](x, T[2])*(diff(diff(diff(diff(Y1(x), x), x), x), x)+2*s^2*(diff(diff(Y1(x), x), x))-omega_y^2*Y1(x)), x = 0 .. x1)

NULL

Download example_int_ac.mw

You could compile Jave code by doing an escaped shell command, (see ssystem). Depending on what is in it, you could run it with an external call (see define_external).

Did you want to map factor over the addends of eq? Note that elementwise factor~(expr) is not the same as map(factor,expr) if expr is a sum of terms rather than an indexable data structure.

Also, I don't understand from your description and attachment whether you are trying to operate (or not) on numerator and denominator separately.

Sorry, but I find your description unclear. What are your f(x) and g(x), etc?

restart

eq := (9*gamma_1*Psi^2*Y1(x1)*alpha_21*omega_y^2-3*gamma_1*Psi^3*alpha_21*omega_y^2+3*gamma_1*Y1(x1)^3*alpha_21*omega_y^2-9*gamma_1*Psi*Y1(x1)^2*alpha_21*omega_y^2)*AA/(-alpha_21*omega_y^2+k_1)+I*cd1*omega_y^3*alpha_21*(-Psi+Y1(x1))*A1(T[2])/(-alpha_21*omega_y^2+k_1)+((diff(Phi[2, 1](x1, T[2]), x1, x1, x1))*alpha_21*omega_y^2-(diff(Phi[2, 1](x1, T[2]), x1, x1, x1))*k_1+k_1*Phi[1, 1](x1, T[2])*alpha_21*omega_y^2-alpha_11*Phi[1, 1](x1, T[2])*omega_y^4*alpha_21+alpha_11*Phi[1, 1](x1, T[2])*omega_y^2*k_1+(2*I)*alpha_11*Y1(x1)*(diff(A1(T[2]), T[2]))*omega_y^3*alpha_21-(2*I)*alpha_11*Y1(x1)*(diff(A1(T[2]), T[2]))*omega_y*k_1-(2*I)*k_1*alpha_21*Psi*(diff(A1(T[2]), T[2]))*omega_y-(diff(Phi[1, 1](x1, T[2]), x1, x1, x1))*alpha_21*omega_y^2+(diff(Phi[1, 1](x1, T[2]), x1, x1, x1))*k_1)/(-alpha_21*omega_y^2+k_1)

(9*gamma_1*Psi^2*Y1(x1)*alpha_21*omega_y^2-3*gamma_1*Psi^3*alpha_21*omega_y^2+3*gamma_1*Y1(x1)^3*alpha_21*omega_y^2-9*gamma_1*Psi*Y1(x1)^2*alpha_21*omega_y^2)*AA/(-alpha_21*omega_y^2+k_1)+I*cd1*omega_y^3*alpha_21*(-Psi+Y1(x1))*A1(T[2])/(-alpha_21*omega_y^2+k_1)+((diff(diff(diff(Phi[2, 1](x1, T[2]), x1), x1), x1))*alpha_21*omega_y^2-(diff(diff(diff(Phi[2, 1](x1, T[2]), x1), x1), x1))*k_1+k_1*Phi[1, 1](x1, T[2])*alpha_21*omega_y^2-alpha_11*Phi[1, 1](x1, T[2])*omega_y^4*alpha_21+alpha_11*Phi[1, 1](x1, T[2])*omega_y^2*k_1+(2*I)*alpha_11*Y1(x1)*(diff(A1(T[2]), T[2]))*omega_y^3*alpha_21-(2*I)*alpha_11*Y1(x1)*(diff(A1(T[2]), T[2]))*omega_y*k_1-(2*I)*k_1*alpha_21*Psi*(diff(A1(T[2]), T[2]))*omega_y-(diff(diff(diff(Phi[1, 1](x1, T[2]), x1), x1), x1))*alpha_21*omega_y^2+(diff(diff(diff(Phi[1, 1](x1, T[2]), x1), x1), x1))*k_1)/(-alpha_21*omega_y^2+k_1)

op(0, eq);

`+`

3

map(factor, eq);

3*gamma_1*alpha_21*omega_y^2*(-Psi+Y1(x1))^3*AA/(-alpha_21*omega_y^2+k_1)+I*cd1*omega_y^3*alpha_21*(-Psi+Y1(x1))*A1(T[2])/(-alpha_21*omega_y^2+k_1)-(-(diff(diff(diff(Phi[2, 1](x1, T[2]), x1), x1), x1))*alpha_21*omega_y^2+(diff(diff(diff(Phi[2, 1](x1, T[2]), x1), x1), x1))*k_1-k_1*Phi[1, 1](x1, T[2])*alpha_21*omega_y^2+alpha_11*Phi[1, 1](x1, T[2])*omega_y^4*alpha_21-alpha_11*Phi[1, 1](x1, T[2])*omega_y^2*k_1-(2*I)*alpha_11*Y1(x1)*(diff(A1(T[2]), T[2]))*omega_y^3*alpha_21+(2*I)*alpha_11*Y1(x1)*(diff(A1(T[2]), T[2]))*omega_y*k_1+(2*I)*k_1*alpha_21*Psi*(diff(A1(T[2]), T[2]))*omega_y+(diff(diff(diff(Phi[1, 1](x1, T[2]), x1), x1), x1))*alpha_21*omega_y^2-(diff(diff(diff(Phi[1, 1](x1, T[2]), x1), x1), x1))*k_1)/(-alpha_21*omega_y^2+k_1)

map(proc (u) options operator, arrow; simplify(u, size) end proc, eq);

-3*gamma_1*alpha_21*omega_y^2*(Psi-Y1(x1))^3*AA/(-alpha_21*omega_y^2+k_1)+I*cd1*omega_y^3*alpha_21*(-Psi+Y1(x1))*A1(T[2])/(-alpha_21*omega_y^2+k_1)+((-alpha_21*omega_y^2+k_1)*(diff(diff(diff(Phi[1, 1](x1, T[2]), x1), x1), x1))+(alpha_21*omega_y^2-k_1)*(diff(diff(diff(Phi[2, 1](x1, T[2]), x1), x1), x1))-2*omega_y*((I*alpha_11*(-alpha_21*omega_y^2+k_1)*Y1(x1)+I*k_1*alpha_21*Psi)*(diff(A1(T[2]), T[2]))-(1/2)*(-omega_y^2*alpha_11*alpha_21+k_1*(alpha_21+alpha_11))*omega_y*Phi[1, 1](x1, T[2])))/(-alpha_21*omega_y^2+k_1)

 

Download example_ac.mw

I do not see the behavior that you describe, in Maple 2018.2, either in a Worksheet or a Document. In that version I see the plots rendered prior to final conclusion, separated in time by the Sleep() specification.

But I do see the behavior that you describe if I execute your code in a Document in Maple 18.02.

So I'll ask whether perhaps you have given this Question an incorrect Product label, and whether you might actually have an older version such as Maple 18 (released, 2014).

If you are in fact using Maple 18 then you can try your computation in a Worksheet, rather than a Document. See the main menubar's File->New->Worksheet to open a fresh Worksheet instead of a Document. In that environment I do indeed see the plots rendered prior to final conclusion, staggered in time by the Sleep() specification.

If you really want the staggered display within a Document in version Maple 18 or older then you could insert a Plot Component and push the plots into that instead or printing. That too would stagger the rendering with the loop iteration, but each of the plots would in turn overwrite the same location. Here is an example. I inserted the Plot Component using the Components palette.  Download loop_plot_EC.mw

By the way, if you ever use a version later than Maple 18 then you could get a similar (in-place) overwriting, staggered effect by using DocumentTools:-Tabluate([plot(...)]) instead of print(plot(...)) . Here is an example done in Maple 2015 .  loop_tab_2015.mw

Yes, there are several ways. You could try solve (possibly after evalf). You could try the addon DirectSearch package's SolveEquations command. You could try Optimization:-Minimize and use the equations for constraints. You might even be able to leverage fsolve (it depends).

Why not attach a worksheet and show us the system?

You didn't explain how you wanted to utilize "&", eg. with "tabular", "array", "align", etc. Note that Maple's latex command already emits "array" for a Matrix.

For "tabular", I found this in the vault, which could likely be adjusted as needed.

restart;

 

Lat:=proc(M::Matrix,
          {output::{NoUserValue,identical(string)}:=':-NoUserValue'})
  local m,n,S;
  (m,n):=op(1,M);
  S:=cat(" \\begin{tabular}",
         "{|",seq("c|",i=1..op([1,2],M)),"} ",
         "\\hline ",
         seq([seq(sprintf("$%s$ & ",latex(M[i,j],':-output'=string)),j=1..n-1),
         sprintf("$%s$ \\\\ \\hline ",latex(M[i,n],':-output'=string))][],i=1..m),
         "\\end{tabular} ");
  if output=':-string' then
    return S;
  else
    printf("%s",S);
    return NULL;
  end if;
end proc:

 

Lat( < < x^2+1 | x^3 > > );

 \begin{tabular}{|c|c|} \hline ${x}^{2}+1$ & ${x}^{3}$ \\ \hline \end{tabular}

 

S := Lat( < < x^2+1 | x^3 > > , output=string):
S;

" \begin{tabular}{|c|c|} \hline ${x}^{2}+1$ & ${x}^{3}$ \\ \hline \end{tabular} "

 

Lat( Matrix(3,3,(i,j)->randpoly(x,coeffs=rand(0..2),degree=3)) );

 \begin{tabular}{|c|c|c|} \hline $2\,{x}^{2}+2\,x+1$ & ${x}^{2}+x+2$ & ${x}^{3}+2\,x$ \\ \hline ${x}^{2}+2\,x+1$ & ${x}^{3}+2\,{x}^{2}+2\,x$ & ${x}^{3}+1$ \\ \hline ${x}^{3}+2\,{x}^{2}+2\,x+1$ & ${x}^{3}+2$ & ${x}^{2}+1$ \\ \hline \end{tabular}

 

The last example produces this, for me, when processed using LaTeX.

Download latextabular.mw

This is a known issue with licensing.

You could try to install the last point-release update to Maple 2019.2.1 . That could help your case, to overcome a rare issue with licensing misidentification.

Otherwise you should contact Maplesoft Technical Support ( ie. send email to support@maplesoft.com )

If I add the compile=true option to the dsolve call then it takes about 6 seconds on my machine.

You supply the range option to dsolve; the first two odeplot calls over the same range are fast.

I suppress output of the eval calls to pick off the solution procedures.

I removed adaptive=8 in the final two plot calls, since it doesn't make sense to me to try adaptive plotting over such high oscillation (which would not be clearly seen at this resolution, I doubt). Instead I supply adaptive=false and force a high numpoints.

I used Maple 2019.2, as you had.

dsolve1_1r_ac0.mw

Do you want arrows? There are several available commands for that.

Plot_eigenvectors_in_3d_scatterplot_ac.mw

(I also changed the symbol to solidcircle. I gave Cov the symmetric shape.)

Using odeplot and a single dsolve (numeric) call -- with parameters -- this can be done somewhat efficiently.

(I compute it also with Carl's Answer's phaseportrait code, to illustrate that odeplot is reasonably quick. There's about a 10-fold timing speedup on my Maple 2020 on Linux, for this number of different Initial Conditions. The performance speedup increases with the number of ICs.)

 

First, using plots:-odeplot and a dsolve solution with parameters.

 

restart;

str:=time[real]():
dsol:=dsolve({diff(r(t),t)=r(t)^2*(r(t)+sin(theta(t))),
              diff(theta(t),t)=r(t)^3*(r(t)+theta(t)+cos(theta(t))),
              theta(0)=partheta, r(0)=parr}, numeric,
              parameters=[partheta, parr]):

odeplotpar:=proc(thetapar,rpar,i)
  dsol(parameters=[thetapar,rpar]);
  plots:-odeplot(dsol, [:-theta(t),:-r(t)], t=0..0.5,
                 numpoints=ceil(0.5/0.0005),
                 color=COLOR(HSV,0.85*i/16,0.85,0.7));
end proc:

P:=plottools:-transform((t,r)->[r*cos(t),r*sin(t)])(
 plots:-display(
   plots:-fieldplot([r^3*(r+theta+cos(theta)),r^2*(r+sin(theta))],
                    theta=0..2*Pi, r=0.7..3, fieldstrength=fixed(0.3),
                    color=COLOR(HSV,0,0,0.85)),
   seq(odeplotpar(i*Pi/8,0.75,i), i=0..15),
   axiscoordinates=polar, size=[600,600],
   axis[2]=[tickmarks=[subticks=0]],
   axis[1]=[gridlines=false, tickmarks=[[seq(0..3,0.5)]]])):
time[real]()-str;

.200

P;

 

For a timing comparison, a similar plot done with DEtools:-phaseportrait.
(One can also compare with DEplot, etc).

 

restart;

str:=time[real]():
P:=plots:-display( #needed to get polar axes
    plottools:-transform((t,r)-> r*~[cos,sin](t))( #transform to polar
        DEtools:-phaseportrait(
            [
                diff(r(t),t) = r(t)^2*(r(t)+sin(theta(t))),
                diff(theta(t),t) = r(t)^3*(r(t)+theta(t)+cos(theta(t)))
            ],
            [theta,r](t),
            t= 0..0.5, #independent variable range for all trajectories
            (i0:= map2(`~`[`=`], [theta,r](0), `[]`~(Pi/8*~[$0..15], .75))), #inits
            linecolor= [seq(COLOR(HSV, .85*i/ni, .85, .7), i= 0..(ni:= nops(i0)-1))],
            thickness= 1, #trajectory thickness (min. is 0, not 1)
            method= rkf45, stepsize= 0.0005,
            color= COLOR(HSV, 0, 0, .85), #light-grey arrows
            arrowsize= .3
        )
    ),
    axiscoordinates= polar, size= [600$2],
    axis[2]= [tickmarks= [subticks= 0]], axis[1]= [gridlines= false]
 ):
time[real]()-str;

1.949

#P;

 

Download polar_odeplot.mw

First 126 127 128 129 130 131 132 Last Page 128 of 336