acer

32405 Reputation

29 Badges

19 years, 351 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

In Maple 2020 you could use printf with the new P format. Or you could use print.

Of course, you could also use sprintf if you prefer a string as return value.

The rules for when if...then...end clauses get indented are not clear to me.

The example below using print does render with more indentation in the Maple GUI than appears when inlined below. And that survives cut&paste, in my Linux.

[edit] One thing that I prefer about the printf format is that it displays semicolon terminators even when optional (eg. before an end). Of course that is a personal preference. I like that it helps prevent a sloppy typo if an extra line is inserted inbetween (or via an $include).

Another thing -- that might matter in some use cases -- is that printf doesn't contain the extra decoration at the start (ie. the printed name and colon-equals) and it's easier to add it than remove it.

restart;

kernelopts(version);

`Maple 2020.0, X86 64 LINUX, Mar 4 2020, Build ID 1455132`

f := proc(x)
   if x <= 2 then
     if x>0 then
       print(-x);
     else
       print(-x^2);
     end if;
   else
     if x>0 then
       print(-x);
     end if;
   end if;
   print(-x);
   x^3;
   if x <= 2 then
     if x>0 then
       if x > -5 then
         print(-x);
       end if;
     else
       print(-x^2);
     end if;
   else
     if x>0 then
       if x > -5 then
         print(-x);
       end if;
     end if;
   end if;
end proc:

 

printf("%P", eval(f));

proc(x)
    if x <= 2 then
        if 0 < x then print(-x); else print(-x^2); end if;
    else
        if 0 < x then print(-x); end if;
    end if;
    print(-x);
    x^3;
    if x <= 2 then
        if 0 < x then
            if -5 < x then print(-x); end if;
        else
            print(-x^2);
        end if;
    else
        if 0 < x then if -5 < x then print(-x); end if; end if;
    end if;
end proc

 

showstat(f);


f := proc(x)
   1   if x <= 2 then
   2       if 0 < x then
   3           print(-x)
           else
   4           print(-x^2)
           end if
       else
   5       if 0 < x then
   6           print(-x)
           end if
       end if;
   7   print(-x);
   8   x^3;
   9   if x <= 2 then
  10       if 0 < x then
  11           if -5 < x then
  12               print(-x)
               end if
           else
  13           print(-x^2)
           end if
       else
  14       if 0 < x then
  15           if -5 < x then
  16               print(-x)
               end if
           end if
       end if
end proc
 

print(f);

proc (x) if x <= 2 then if 0 < x then print(-x) else print(-x^2) end if else if 0 < x then print(-x) end if end if; print(-x); x^3; if x <= 2 then if 0 < x then if -5 < x then print(-x) end if else print(-x^2) end if else if 0 < x then if -5 < x then print(-x) end if end if end if end proc

 

 

Download format_P.mw

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.)

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