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

If I enter the word permute in the Help search then the top result is for the command combinat:-permute.

That returns the permutations of a list.

But that Help pages also has a cross-reference to the parent combinat package, whose page shows links to numbperm, nextperm, etc.

 

 

The functionality to specify the format of the float in the labels is a good idea. It would be nice to be able to specify that in the Explore call, for each parameter if relevant. (I will submit a Software Change Request.)

The following surgery on Explore alters the hard-coded numeric formatting for those labels. This might go in your personal initialization file, if it suffices for you. If you really need more flexibility I could make it utilize an environment variable, so that you could adjust it dynamically.

restart;

__KO:=kernelopts(opaquemodules=false):
try
  __KK:=ToInert(eval(Explore:-Runtime:-Update)):
  unprotect(Explore:-Runtime:-Update):
  Explore:-Runtime:-Update:=FromInert(subsop([5,3,4,1,1,2,1,2,3]
    =subs("%.3g"="%.2f",op([5,3,4,1,1,2,1,2,3],__KK)),__KK)):
catch:
  protect(Explore:-Runtime:-Update):
  kernelopts(opaquemodules=__KO):
end try:

Explore(plot(1/10*x^2+a,x=0..10,view=10..23), a=10.5 .. 11.5);

Or you could edit the above to utilize, say, "%.3f" instead of "%.2f", or something else of your choice for the sprintf format string.

Explore_label_format.mw

Of course the optimal solution would be for each parameter's label in each separate exploration to be able to retain its own independent formatting specification.

restart;

kernelopts(version);

`Maple 2015.2, X86 64 LINUX, Dec 20 2015, Build ID 1097895`

P1 := Sum(a*X[n]+b, n=1..N);

Sum(a*X[n]+b, n = 1 .. N)

subs(sum=Sum,expand(value(P1)));

N*b+a*(Sum(X[n], n = 1 .. N))

restart;

P2 := Sum(X[n]+Y[n], n=1..N);

Sum(X[n]+Y[n], n = 1 .. N)

# This alone will work in Maple 2019, but not your Maple 2015
expand(P2);

Sum(X[n]+Y[n], n = 1 .. N)

# This alters how `expand` works on sums
with(student):

expand(P2);

Sum(X[n], n = 1 .. N)+Sum(Y[n], n = 1 .. N)

restart;

P2 := Sum(X[n]+Y[n], n=1..N);

Sum(X[n]+Y[n], n = 1 .. N)

EX := S->subsindets(S,And(specfunc({sum,Sum}),
                           satisfies(u->type(op(1,u),`+`))),
                    u->`+`(map(op(0,u),[op([1,..],u)],op(2..,u))[])):

EX(P2);

Sum(X[n], n = 1 .. N)+Sum(Y[n], n = 1 .. N)

 

Download sum_stuff.mw

Are you looking primarily for a way to manually resize (after embedding), or a programmatic way?

The Explore command itself accepts a size option. You haven't mentioned that, so perhaps you are as yet unaware of that? Eg,


    Explore(plot3d(sin(a*x)*y^2,x=-Pi..Pi,y=-1..1),
                  a=1..2.0,size=[600,600]);

The Explore command uses Embedded Components, and in particular it uses a Plot Component to contain the rendered plot. It is true that this component does not have mouse-pointer "resize handles". But you can adjust the width and height properties of that component, after the exploration is embedded in the Worksheet/Document.

For example, using the mouse-pointer, you can do this (Maple 2019), to change the dimension of the Plot Component:
   - Open the context-panel
   - left-click in the plot itself (It has to be within the Plot Component, and not its surroundings. Getting it slightly off will show properties for some surrounding component, which by your description seems to have been key.)
   - Adjust the "Width in pixels" and "Height in Pixels" context-panel

In versions that predate the context-panel you can right-click on the plot and get the context-menu for the Plot Component. Choose Component Properties, and adjust the two relevant fields in the popup. 

[edited] It is true that plot3d does not accept the size option. If it did then Explore would act like it does for the 2D plot command, and utilize that for the dimensions of the component. Indeed, this does work too,

   Resize:=proc(P,m::posint,n::posint)
      op(0,P)(op(P),ROOT(BOUNDS_X(0),BOUNDS_Y(0),
                   BOUNDS_WIDTH(n),BOUNDS_HEIGHT(m)));
   end proc:


    Explore(Resize(plot3d(sin(a*x)*y^2,x=-Pi..Pi,y=-1..1),600,600),
                   a=1..2.0);

That Resize procedure also works for displaying 3D plots outside of Explore. (You could add it to a personal initialization file.)

I came up with a "hot fix" that allows 3D plotting commands to accept the size option. I'll try to find a moment to share it.

In Maple 2019.2 a wrapping pair of (2D Input) single-bars | get parsed as a call to the LinearAlgebra:-Determinant command.

But a wrapping pair of (2D Input) double-bars will get parsed as a call to Norm, according to whether that currently has a binding to, say, LinearAlgebra:-Norm or VectorCalculus:-Norm (which use a different default norm).

I obtain these in 2D Input from the Operator palette.

So, can you get by using the double-bars? Making it work with the single-bars could involve some ugly setup code.

restart

with(VectorCalculus)

LinearAlgebra[Norm](`<,>`(3, 0, 4))

5

restart

LinearAlgebra[Norm](`<,>`(3, 0, 4))

4

 

Download Norm_2D.mw

 

The single left-ticks denote names. The double-quotes denote strings.

Occurrences of cc within a name or a string do not get substituted just because cc has some value (whether a name, string, or whatever).

The commands sprintf and nprintf can be used to format (substitute) a value into a string or a name, respectively. But notice that the characters in a name get rendered in italic, while those within a string appear upright.

for c from 1 to 2 do
  sprintf("the power is %a",c);
  plot( x^c, x= -1..1, title=sprintf("the power is %a",c) )
end do;

for c from 1 to 2 do
  nprintf("the power is %a",c);
  plot( x^c, x= -1..1, title=nprintf("the power is %a",c) )
end do;

You can also use cat or || to concatenate strings or names. Notice that concatenating a string with an integer cc produces another string, and concatenating a name with an integer cc produces another name.

for c from 1 to 2 do
  cat("the power is ",c);
  plot( x^c, x= -1..1, title=cat("the power is ",c) )
end do;
for c from 1 to 2 do
  "the power is "||c;
  plot( x^c, x= -1..1, title="the power is "||c )
end do;
for c from 1 to 2 do
  cat(`the power is `,c);
  plot( x^c, x= -1..1, title=cat(`the power is `,c) )
end do;
for c from 1 to 2 do
  `the power is `||c;
  plot( x^c, x= -1..1, title=`the power is `||c )
end do;

You can also use the special term typeset within the context of most plotting commands to blend strings and math for titles, axis labels, captions, etc. See the Help page for topic plot,typesetting

for c from 1 to 2 do
  plot( x^c, x= -1..1, title=typeset("the power is ",c) )
end do;

Note that the examples above use quotes of some sort to delimit strings (or names containing spaces), and commas to delimit items in a sequence. This is to prevent ambiguity. Simply writing, say, title= the power is c in free form is not valid syntax of the language.

ps. I'm not sure where you saw such use of a period (dot) to denote concatenation. That has not been part of the language for 20 years now.

Here is one way, with a few additional items to also specify the view and tickmarks.

L := [1,2,2,2,3,3,4,4,5,5,6,6]:

Statistics:-Histogram( L, binwidth=1,
                       view=[min(L)-1..max(L)+1,0..0.3],
                       xtickmarks=[$1..max(L)] );

histo.mw

If you would like custom spacing between the column bars you could also use the ColumnGraph command. Eg,

with(Statistics):
L := [1,2,2,2,3,3,4,4,5,5,6,6]:
T := table(Tally(L,output=list),sparse):
S := {L[]}:
LL := [seq(i=T[i]/nops(L),i=min(S)..max(S))]:
ColumnGraph(LL, datasetlabels=none,
            offset=0.625, distance=0.25, width=0.75,
            view=[min(L)-0.625..max(L)+0.625,0..0.3],
            xtickmarks=[seq(i,i=min(S)..max(S))]);

Is this the kind of thing you want?

restart

kernelopts(version);

`Maple 16.01, X86 64 LINUX, May 6 2012, Build ID 744592`

n := sqrt(3):

with(DEtools), with(linalg):

interface(displayprecision = 10):

PDEtools:-declare(prime = t, quiet):

ross_z := diff(z(t), t) = -3*z(t)-sqrt(3/2)*l(t)*n*y(t)^2+(3/2)*z(t)*(1-y(t)^2+z(t)^2):

ross_y := diff(y(t), t) = sqrt(3/2)*y(t)*z(t)*l(t)*n+(3/2)*y(t)*(1-y(t)^2+z(t)^2):

ross_l := diff(l(t), t) = (3/2)*l(t)*(l(t)^2-1)*(1-y(t)^2+z(t)^2)/(l(t)^2+1):

NULL

sys := {ross_l, ross_y, ross_z}:

``

sys1 := eval(sys, [l = 1]):

sys11 := {op(2, sys1), op(3, sys1)}:

ics1 := [z(0) = .29, y(0) = .27]:

``

P := DEplot(sys11, [z(t), y(t)], t = -7 .. 7, z = -1 .. 1, y = 0 .. 1, [ics1, ics2, ics3], linecolor = [red, blue, cyan], stepsize = 0.1e-1, thickness = 2, arrows = medium):

plots:-display(P, scaling = constrained);

plots:-display((plottools:-transform(proc (x, y) options operator, arrow; [`if`(x^2+y^2 < 1, x, undefined), `if`(x^2+y^2 < 1, y, undefined)] end proc))(P), scaling = constrained);

 

``

Download mapleprimes_ac.mw

See the command combinat:-numbpart for the number of partitions of an integer.


When you call fsolve on the multivariate system then it does use Newton's method. See below. You can choose any t value you want below (not just 0 or 1).

You can also obtain explicit solutions in terms of t, symbolically, using solve. These can also be evaluated at specific values of t.

restart;

eq1:= (1/2)*x[0]*sqrt(3)-(1/2)*x[1]*sqrt(3) = ((1/2)*x[0]*(t+(1/3)*sqrt(3))*sqrt(3)-(1/2)*x[1]*(t-(1/3)*sqrt(3))*sqrt(3))*(1-(1/6)*y[0]*(t+(1/3)*sqrt(3))*sqrt(3)+(1/6)*y[1]*(t-(1/3)*sqrt(3))*sqrt(3)-(1/8)*y[0]*(5*sqrt(3)*(1/12)-1/4+t)*sqrt(3)+(1/8)*y[1]*(-(1/4)*sqrt(3)-1/4+t)*sqrt(3)-(1/8)*y[0]*((1/4)*sqrt(3)-1/4+t)*sqrt(3)+(1/8)*y[1]*(-5*sqrt(3)*(1/12)-1/4+t)*sqrt(3))-5*t^3*(1/2)+49*t^2*(1/12)+17*t*(1/12)-23/6:
eq2:= (1/2)*y[0]*sqrt(3)-(1/2)*y[1]*sqrt(3) = ((1/2)*y[0]*(t+(1/3)*sqrt(3))*sqrt(3)-(1/2)*y[1]*(t-(1/3)*sqrt(3))*sqrt(3))*(-2+(1/2)*x[0]*(t+(1/3)*sqrt(3))*sqrt(3)-(1/2)*x[1]*(t-(1/3)*sqrt(3))*sqrt(3)+(1/4)*(-(1/12)*sqrt(3)-3/4)*((1/2)*x[0]*(5*sqrt(3)*(1/12)-1/4+t)*sqrt(3)-(1/2)*x[1]*(-(1/4)*sqrt(3)-1/4+t)*sqrt(3))+(1/4)*((1/12)*sqrt(3)-3/4)*((1/2)*x[0]*((1/4)*sqrt(3)-1/4+t)*sqrt(3)-(1/2)*x[1]*(-5*sqrt(3)*(1/12)-1/4+t)*sqrt(3)))+15*t^3*(1/8)-(1/4)*t^2+3*t*(1/8)-1:
eq3:=(1/2)*x[0]+(1/2)*x[1] = 1:
eq4:=(1/2)*y[0]+(1/2)*y[1] = 0:

fsolve(eval({eq1,eq2,eq3,eq4},t=0));

{x[0] = -.7079945458, x[1] = 2.707994546, y[0] = -.5773502690, y[1] = .5773502690}

fsolve(eval({eq1,eq2,eq3,eq4},t=1));

{x[0] = .7816742684, x[1] = 1.218325732, y[0] = .2184568586, y[1] = -.2184568586}

S:=subs((t=t)=NULL,[solve({eq1,eq2,eq3,eq4},{x[0],y[0],x[1],y[1]},explicit)]):

remove(has,map(u->evalf(map(limit,u,t=0.0)),S),Float(undefined));

[{x[0] = -.707994547, x[1] = 2.707994547, y[0] = -.5773502693, y[1] = .5773502693}]

remove(has,map(u->evalf(map(limit,u,t=1.0)),S),Float(undefined));

[{x[0] = .7816742678, x[1] = 1.218325732, y[0] = .2184568586, y[1] = -.2184568586}]

 

Download RFs.mw

My usual experience is different from what you describe.

When the computational kernel crashes in the GUI then I am usually still able to save the worksheet by closing the GUI using the top corner icon (window decoration button from the OS, which often looks like an X). When I do this the GUI still offers me the choice to save the worksheet, even though the kernel has crashed.

Of course that doesn't include instances when the GUI itself has frozen. By far the most common cause of that is an attempt at printing an extremely large result.

The .m (dotm) structure does not support modules completely. (It never has and I doubt it ever will.) And objects are modules.

Trying to save an object to a single .m file is user-error, in my opinion.

Additionally, two MultiSets constructed with the same elements are still two MultiSets. The documentation states that explicitly. It also states that they can be compared directly with `=` under evalb.

But *nowhere* does it state that they are the same or identical and would therefore be treated as such under evalb when compared in any nondirect manner (ie. contained in any other structure).There is nothing in the Help page of evalb that suggests that, and it is a mistake to infer it.

The command DocumentTools:-Layout:-Equation will pick up and make use of the current typesetting level during its construction.

You can also override that by passing the option typesetting=extended to that Equation command.

(nb. I've also wrapped your argument to Table within a Textfield, which Maple 2019 seems to like, although Maple 2015 works without it. You can also give that Textfield the alignment=left option if you don't want it centered by default. So this attachment work in both versions.)

Equation_typesetting.mw

[edited] I am aware that the piecewise pretty-prints as 2D in regular output, regardless of the interface(typesetting) level. In the context of Layout:-Equation this just means that the naming of the permitted values for its typesetting option are somewhat misnamed. But the details above should still suffice to resolve the OP's question.

You can enforce runtime type-checking for assignments to locals of procedures. You can do this by setting the assertion level.

Note that type(y,integer) will not return true (below) while y is still unassigned.

restart;

kernelopts(assertlevel=2):

p := proc()
  local y::integer;
  y := 1.2;
end proc:

p();

Error, (in p) assertion failed in assignment, expected integer, got 1.2

local z::integer;

z

z:=1.2;

1.2

 

Download local_type_assertion.mw

One additional problem here is that your original qN_ep doesn't guard against fsolve possibly returning NULL.

I'll answer the same way as your previous question, using operator form instead of the awkward/confusing multiple unevalution quotes.

I also reduce Digits from 100 to 20, since it produces similar plots but doesn't take as long.

NLPSolve_test_ac1.mw

 

First 136 137 138 139 140 141 142 Last Page 138 of 336