acer

32405 Reputation

29 Badges

19 years, 346 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

I showed a similar thing here, using the events functionality of numeric dsolve.

(I also showed it there using Optimization:-Minimize.)

Every call to DocumentTools:-InsertContent entirely replaces any content in the sole Task Region that an Execution Group can have.

In other words, each time through your loop the InsertContent call will wipe out whatever was inserted the previous call.

You cannot work around this with the kind of looped call to InsertContent call that you have.

You can only work around it by inserting xml content which itself contains all the augmented content.

Eg, hyperlink_do-loop_1.mw

So you can use a seq call within the construction. But you cannot succeed doing any looped call to InsertContent.

You have other choices, about what to enclose within such a seq call. It needn't be of the form seq(Group(Input(...)),...) but instead could be different hyperlinks in a sequence of Cells in a Row, or a particular Cell in each of a sequence of Rows in a Table, or a particular Cell in a sequence of subTables within whatever, etc.

My personal preference for such tasks is to try and target any actions by expand, simplify, combine, etc, to only those which are necessary, in as much as that might be possible.

Restricting use of simplify can be more important, since it can turn ln,exp to arctrig,trig form.

This version also separates factors which do not contain any of the names, or those which are not separable. It handles 1, 2, or more arbitrary names.

restart;

F:=proc(ee,vars::list,{pullcontent::truefalse:=false})
  local Finner;
  Finner:=proc(ee,i::posint,vars::list)
    local p1,p2,K;
    if i>nops(vars) then return ee; end if;
    K := [(u->`if`(u::`*`,op(u),u))(subsindets(ee,{`^`,'specfunc(exp)'},
                                               expand))];
    p1,p2 := selectremove(u->has(u,vars[i]) and {seq(has(u,v),
                                  v=[vars[..i-1][],
                                     vars[i+1..][]])}={false},K);
    p1 := `if`(nops(p1)=0,1,`if`(nops(p1)=1,``(op(p1)),``(`*`(op(p1)))));
    p2 := `if`(nops(p2)=0,1,`if`(nops(p2)=1,op(p2),`*`(op(p2))));
    if nops(vars)>i then
      p2 := procname(p2,i+1,vars);
    end if;
    p1*`if`(i=nops(vars) and p2<>1,``(p2),p2);
  end proc;
  if ee::`*` then `*`(Finner(ee,1,vars)); else ee; end if;
end proc:

expr := a/b^2;

a/b^2

F( expr, [a,b] );

``(a)*``(1/b^2)

expr := exp(a)*13.5/b;

13.5*exp(a)/b

F( expr, [a,b] );

``(exp(a))*``(1/b)*``(13.5)

expr := (x^2+1)*y^3*exp(-x-y);

(x^2+1)*y^3*exp(-x-y)

F( expr, [x,y] );

``((x^2+1)/exp(x))*``(y^3/exp(y))

expr := -(x^2+1)*y^3*exp(-x-y);

-(x^2+1)*y^3*exp(-x-y)

F( expr, [x,y] );

``((x^2+1)/exp(x))*``(y^3/exp(y))*``(-1)

expr := -Pi*(1-cos(x)^2)*sin(y)^3/exp(1);

-Pi*(1-cos(x)^2)*sin(y)^3/exp(1)

F( expr, [x,y] );

``(1-cos(x)^2)*``(sin(y)^3)*``(-Pi/exp(1))

expr := (x^2+1)*z^3*exp(-x-y+h(y))*3/4*cos(x+a)/g(z);

(3/4)*(x^2+1)*z^3*exp(-x-y+h(y))*cos(x+a)/g(z)

F( expr, [x,y,z] );

``((x^2+1)*cos(x+a)/exp(x))*``(exp(h(y))/exp(y))*``(z^3/g(z))*``(3/4)

expr := (x^2+1)*y^3*p^(-x-y+b+z)*2*z/3*exp(x*q)*(1-sin(a)^2)*ln(abs(x)*abs(a));

(2/3)*(x^2+1)*y^3*p^(-x-y+b+z)*z*exp(x*q)*(1-sin(a)^2)*ln(abs(x)*abs(a))

F( expr, [x,y,z] );

``((x^2+1)*exp(x*q)*ln(abs(x)*abs(a))/p^x)*``(y^3/p^y)*``(p^z*z)*``((2/3)*p^b*(1-sin(a)^2))

 


Download splitprod.mw

No, that is not offered through Maple for that computation (ie. grinding it out via `isprime`, as opposed to lookup via NumberTheory:-IsMersenne).

Let me know if you'd really rather have the phi details inside the plot (which could be done using a fancy textplot).

restart

L := 7; with(plots); Digits := 30; rf := 997.1; cpf := 4179; kf := .613; bf := 21; sf := 0.5e-1; rs := 8933; cps := 385; ks := 400; bs := 1.67; ss := 5.96*10^7; a[1] := 0; a[2] := 2; a[3] := 5; a[4] := .6; a[5] := 4; a[6] := 6; phi := .1; lambda := .2; Ha := 1; Gr := 2; alpha := .5; Rd := .5; Ecy := 2; Pr := 3.97; Ecx := .3; A := 1; HA := [a[1], a[2], a[3]]

Ha := Pram; Eq1 := (diff(F(eta), eta, eta, eta))/((1-phi+rs*phi/rf)*(1-phi)^2.5)+(F(eta)+G(eta))*(diff(F(eta), eta, eta))-(2*(diff(F(eta), eta)+diff(G(eta), eta)))*(diff(F(eta), eta))+4*lambda*(diff(G(eta), eta))+(1-phi+rs*bs*phi/(rf*bf))*Gr*H(eta)/(1-phi+rs*phi/rf)-Ha^2*(1+(3*(ss/sf-1))*phi/(ss/sf+2-(ss/sf-1)*phi))*(diff(F(eta), eta))/(1-phi+rs*phi/rf) = 0; Eq2 := (diff(G(eta), eta, eta, eta))/((1-phi+rs*phi/rf)*(1-phi)^2.5)+(F(eta)+G(eta))*(diff(G(eta), eta, eta))-(2*(diff(F(eta), eta)+diff(G(eta), eta)))*(diff(G(eta), eta))-4*lambda*(diff(F(eta), eta))+(1-phi+rs*bs*phi/(rf*bf))*Gr*H(eta)/(1-phi+rs*phi/rf)-Ha^2*(1+(3*(ss/sf-1))*phi/(ss/sf+2-(ss/sf-1)*phi))*(diff(G(eta), eta))/(1-phi+rs*phi/rf) = 0; Eq3 := (ks+(m-1)*kf-(m-1)*(kf-ks)*phi)*(diff(H(eta), eta, eta))/(Pr*(ks+(m-1)*kf+(kf-ks)*phi))+(1-phi+rs*cps*phi/(rf*cpf))*((F(eta)+G(eta))*(diff(H(eta), eta))-A*(diff(F(eta), eta)+diff(G(eta), eta))*H(eta))+Ecx*Ecy*((diff(F(eta), eta, eta))^2+(diff(G(eta), eta))^2)/(1-phi)^2.5 = 0

IC1 := F(0) = 0, (D(F))(0) = 1, G(0) = 0, (D(G))(0) = alpha, H(0) = 1, (D(F))(L) = 0, (D(G))(L) = 0, H(L) = 0
params := {B111 = .2}

[0, 2, 5]

for k to nops(HA) do P || k := plots:-odeplot(dsolve(eval({Eq1, Eq2, Eq3, IC1}, `union`(params, {Pram = HA[k], m = 3})), numeric), [[eta, diff(F(eta), eta)]], linestyle = [dashdot, spacedash, dash, longdash][k], color = [blue, blue, blue, blue][k], labels = [eta, f], thickness = 3); Q || k := plots:-odeplot(dsolve(eval({Eq1, Eq2, Eq3, IC1}, `union`(params, {Pram = HA[k], m = 6.3698})), numeric), [[eta, diff(F(eta), eta)]], linestyle = [dashdot, spacedash, dash, longdash][k], color = [green, green, green, green][k], labels = [eta, theta], thickness = 3); R || k := plots:-odeplot(dsolve(eval({Eq1, Eq2, Eq3, IC1}, `union`(params, {Pram = HA[k], m = 16.1576})), numeric), [[eta, diff(F(eta), eta)]], linestyle = [dashdot, spacedash, dash, longdash][k], color = [red, red, red, red][k], labels = [eta, theta], thickness = 3) end do; f1 := plots:-display(P || (1 .. nops(HA))); f2 := plots:-display(Q || (1 .. nops(HA))); f3 := plots:-display(R || (1 .. nops(HA)))

display(f1, f2, f3, axes = boxed, size = [400, 460], labels = [eta, "&phi;(&eta;)"], labelfont = ["Arial", 10, Bold], labeldirections = [horizontal, vertical], axesfont = ["ROMAN", 10], plot([-1, -1, -1], 3 .. 4, color = [blue, green, red], legend = [typeset('phi' = 3), typeset('phi' = 6), typeset('phi' = 13)], legendstyle = [font = ["ROMAN", bold, 10], location = top]), plots:-textplot([1.5, .8, typeset('delta' = .1, .3, .5)], font = ["ROMAN", bold, 10]), view = [default, 0 .. 1])

``

 

 

Legend_1.mw

Using the menubar, select to View -> Show/Hide Contents...  and in the popup dialogue that appears toggle off Execution Group Boundaries.

Note this is a property of the Worksheet itself, rather than a global setting. Which means when the sheet is saved it retains the property when re-opened (by you or someone else). It also won't affect other newly opened sheets. 

restart;

 

simplify( [solve({x=r*cos(theta), y=r*sin(theta)}, {r,theta},
                 explicit, useassumptions)] )[]
   assuming x::real, y::real, r>0;

{r = (x^2+y^2)^(1/2), theta = arctan(y, x)}

restart;

 

simplify( [solve({r>0,x=r*cos(theta), y=r*sin(theta)}, {r,theta},
                 explicit, useassumptions)] )[]
   assuming x::real, y::real;

{r = (x^2+y^2)^(1/2), theta = arctan(y, x)}

 


Download solve_r.mw

For AudioTools:-Preview to recognize a float[8] Array as an audio thing it has to have certain attributes.

In Maple 2017 the Statistics:-MovingAverage operation does not return an Array with the attributes of the original its input Array. But in Maple 12.02 that command did do that.

I don't really understand how a computation like that done by Statistics:-MovingAverage could sensibly just copy over values for audio qualities like sampling rate. Simply giving the same audio attributes to the returned result doesn't make much sense to me. Perhaps even more importantly, what about the case that someone has used atttributes to mean something else entirely, for which blind copying over of attributes bu MovingAverage might make no sense at all.

Perhaps audio things could be implemented as objects. Then their data could be extracted on demand, but it'd be more obvious that manipulations of such data would then just be Arrays of revised data, and not new audio objects per se.

You could put the attributes of a onto d, or you could apply the AudioTools:-Create command to d to set its audio attributes. You may need to think about what values to use.

restart;

kernelopts(version);

`Maple 2017.3, X86 64 LINUX, Sep 27 2017, Build ID 1265877`

with(AudioTools):
with(Statistics):

a:=Read(cat(kernelopts(datadir),"/audio/ding.wav"));

a := Vector(4, {(1) = ` 1 .. 20191 `*Array, (2) = `Data Type: `*float[8], (3) = `Storage: `*rectangular, (4) = `Order: `*C_order})

b:=ToMono(a): #changing to Mono.
c:=b^2: #squaring the signal.

d:=MovingAverage(c,30):

attributes(a);

22050, 16, 1

attributes(d); #NULL

setattribute(d,attributes(a)):
attributes(d);

22050, 16, 1

Preview(d);

dd:=Create(d,rate=22050);
attributes(dd);

dd := Vector(4, {(1) = ` 1 .. 20162 `*Array, (2) = `Data Type: `*float[8], (3) = `Storage: `*rectangular, (4) = `Order: `*C_order})

22050, 16, 1

Preview(dd);

 


audio_prev.mw

Computations are performed on the local computer than is running Maple.

(There are some very uncommon and specials ways to communicate with other machines/servers, but it has to be done purposefully and many people would not even know how. So, to a practical extent: all computations executed in your standard Maple program will be computed locally.)

As for indications of progess, well that depends very much on what kind of computation. And you've told us nothing about the particulars.

Is it a computation done by a procedure (not just a document) written by you? If so then you can inject periodic messaging code into it, in several different ways.

For quite a few Maple stock commands you can also adjust the infolevel setting, to get some progress notes. Note that the extent of such detail varies quite a bit, from command to command.

There are also ways to get Maple to plaster your screen with almost all that its doing at the interpreted Library code level. But this is usually so overwhelming that its not helpful.

 

This can be controlled manually using the the Typesetting:-RuleAssistant popup, or programmatically using the Typesetting:-Settings command.

This setting is not saved as part of the Worksheet/Document, nor can it saved as a global preference.

But you can hide preliminary calls to commands Typesetting:-Settings in the Startup Code region of the sheet, and so get such settings to be specific to the particular sheet.

restart;

Typesetting:-Settings(useprime); # default

true

diff(f(x), x)

diff(f(x), x)

Typesetting:-Settings(useprime=false):

diff(f(x), x)

`#msup(mi("f"),mo("&apos;"))`

lprint(%);

`#msup(mi("f"),mo("&apos;"))`

kernelopts(version);

`Maple 2017.2, X86 64 LINUX, Jul 19 2017, Build ID 1247392`

 


Download primediffparsing.mw

If you change that to Shutdown("0") then the return value wil be the string "0" upon Cancel (and, as you've implemented the other button, a list containing the selected filename string otherwise).

Assign the return value directly to say f1, and leave indexing into it until after you've tested whether it is "0".

You can just check evalb(f1="0") and then return/break/next/stop/end/etc as you wish. If it isn't then you can index into it like f1[1], etc, to get at the filename.

You can use subsindets and type anyfunc or type specfunc to find and act directly upon (ie. freeze) all those subexpressions which you don't want to be combined.

For example, excluding any function of alpha or beta,

thaw(combine(subsindets( expr, anyfunc(identical(alpha,beta)), freeze)));

Or, restricting it to just a few particular functions such as any combination of sin or cos of alpha or beta,

thaw(combine(subsindets( expr, specfunc(identical(alpha,beta),{sin,cos}), freeze)));

For handling an explicit (and small, say) list of items to exclude the choice is a matter of personal preference, I'd say. I find that I usually reach for subsindets so that I have less editing to do if I want to switch from a fixed list to more encompassing type. For example, to work on expression expr,

L:=[cos(beta),sin(alpha)]:
thaw(combine(subs(((x->x)=freeze)~(L),expr)));
thaw(combine(eval(expr,((x->x)=freeze)~(L))));
thaw(combine(eval(expr,(x->x=freeze(x))~(L))));
thaw(combine(subsindets(expr,identical(op(L)),freeze)));

I pointed out a new bug in the parsing of 2D Input, new to Maple 2017, on Sept 7th, 2017 in another thread on Mapleprimes.

There is a new problem in that infix arithmetic operations are being parsed to prefix function calls. For your example done in 2D Input Maple compute the float reciprocal of the denominator first, and then multiplies the numerator by that preliminary result.

Of course, compared to using proper float division, that new behavior can violate the expected behavior of attaining no more then 0.6 ulps error for the atomic floating-point arithmetic operation.

I recall that the rules for when this happened for 2D Input infix arithmetic operations, or not, were all over the map.

I submitted at least two bug reports related to it, at that time. (The bug report submitted approximately Sept 7th did not make it to a fix for the 2017.3 point release of Oct 3rd.)

I'll note that your Question's input appears to be in 1D Notation input. But you also indicated that it made a difference whether you were in a Document of Worksheet. It may be that the disctinction occurs, say, between a Document Block and a plain Execution Group. It would help if you uploaded your document as an attachment rather than just inlining images input in your Comments.

If you are passing a list of expressions to plot then you can also pass a list for the legend option. Eg,

exprs:=[sin(x), cos(x), sqrt(x)*sin(x)];

plot(exprs, x=0..6, legend=exprs);
Here are a few different ways:

restart;

sys:={x^2 + y^2 + z^2 = 4, x + y + z = 0, x*sin(y*z) = -1}:


After inspecting the implicit plot (Kitonum's idea) we could call
fsolve using restricted ranges for y.

fsolve(sys, {x,y,z}, {y=0.8..1});

{x = -1.630958259, y = .8860579420, z = .7449003167}

fsolve(sys, {x,y,z}, {y=0..0.8});

{x = -1.630958259, y = .7449003167, z = .8860579420}

restart;

sys:={x^2 + y^2 + z^2 = 4, x + y + z = 0, x*sin(y*z) = -1}:


It turns out that fsolve (with its avoid option) can find two roots for
the restriction that comes from eliminating x.

T:=eliminate(sys,{x});

[{x = -y-z}, {-sin(y*z)*y-sin(y*z)*z+1, 2*y^2+2*y*z+2*z^2-4}]

S1:=fsolve(T[2], {y,z});
ans1:=S1 union eval(T[1],S1);

{y = .7449003167, z = .8860579420}

{x = -1.630958259, y = .7449003167, z = .8860579420}

S2:=fsolve(T[2], {y,z}, avoid={S1});
ans2:=S2 union eval(T[1],S2);

{y = .8860579420, z = .7449003167}

{x = -1.630958259, y = .8860579420, z = .7449003167}

kernelopts(version);

`Maple 2017.3, X86 64 LINUX, Sep 27 2017, Build ID 1265877`

 

Download sys_fsolve.mw

[edit] Having obtained a solution, there will be another with values for y and z interchanged (due to symmetry).

sys:={x^2 + y^2 + z^2 = 4, x + y + z = 0, x*sin(y*z) = -1}:

evalb( eval(sys, [y=z,z=y]) = sys );

                    true

So swapping values for y and z is another way to get a second solution.

First 187 188 189 190 191 192 193 Last Page 189 of 336