acer

32385 Reputation

29 Badges

19 years, 334 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

N := 20; 

... other code, and then,

plot3d( {seq(a[i], i=1...N)}, ... );

 

It's natural that a list would always be exported with one particular orientation, and it happens to be as a row.

But conversion of a list to a column Vector can be done much more easily than by using the convert command.

Try this,

Export( <X1>, "data1.xlsx", 1, "A1" );

You can insert an image from an external image file into a Rectangle within a Drawing.

You can insert the rectangle using the corresponding icon in the Drawing tool menubar (you may wish to first make the color white, to suppress the rectangle's borders). You can then select and fill that rectangle using the corresponding selection and fill (paintcan) icons, to make it contain the image from the external file.

A semicircle image can be produced by exporting a plot, or by using the new ImageTools-Draw commands.

You may need to be careful about resizing the rectangle, and matching its dimensions aspect-ratio to that of the file, in order to get a clean non-jagged curve.

It would be useful if the GUI were to allow a copy of a plot to be pasted into a selected Rectangle within a Drawing canvas.

Another approach is to use the Drawing tools menubar to draw on top of a displayed plot.

Here's an example I made using Maple 2019.1 and both of those two ways I mentioned above to produce an image file.

restart;

P:=plots:-display(plottools:-arc([0,0],1,0..Pi,thickness=2),
                  axes=none,scaling=constrained,size=[200,200]):
print(P):
plotsetup("jpeg",'plotoutput'=cat(kernelopts('homedir'),"/mapleprimes/p1.jpg"));
print(P);
plotsetup("inline");

 

kernelopts(version);
with(ImageTools):
with(ImageTools:-Draw):
img := Create(200,200,channels=3,background=white):
Circle(img,100,0,200-4,color=0.0,thickness=2);
Embed(img);
Write(cat(kernelopts('homedir'),"/mapleprimes/c1.jpg"),img):

`Maple 2019.1, X86 64 LINUX, May 21 2019, Build ID 1399874`

 

Download drawing_semicircle.mw

For the particular kind of polynomial expression you have, it is possible to use the sort command to alter the way in which the structure is currently stored in memory by the kernel. And doing so also forces the way it is displayed by printing. And so in this manner you can obtain what you requested.

It's possible that you will find this approach too heavy-handed, and will prefer to use the InertForm and the %-prefix operators for your display goal. But, contrary to what Carl wrote (as I read it and interpreted the claim), for your given example it is possible to control the orders of the multiplicands in the `*` terms.

Note also that since the forced sorting affects how the operands are stored then it also affects how they get accessed with the op command.

It is possible to get such an effect by applying the sort command to the whole polynomial at hand, or to get a mixed result by applying it to just a few of the individual product terms (even before calling add).

This topic is also related to the fact that Maple only stores a single instance of such product terms in memory, and for efficiency uniquifies equivalent input to the single stored representation.

Note that in the absence of such a forced sort call the default display may differ for prettyprint=3 and prettyprint=1 or 0. (There is some extra subtlety, and there are now different kinds of underlying DAG structure that can come into play, as can be seen using the advanced dismantle command.)

I've tried to illustrate some of the effects below:

restart;

kernelopts(version);

`Maple 2019.1, X86 64 LINUX, May 21 2019, Build ID 1399874`

interface(prettyprint=3): # default

indxes:={[1],[2],[3]};

{[1], [2], [3]}

# For fun I'll sort just this middle product, before calling `add`.
sort(xx[2]*e[2], order=plex(seq(xx[indx[]], indx = indxes))):

F := add(xx[indx[]]*e[indx[]], indx = indxes):

F;
op(1,F);
op([1,..],F);

e[1]*xx[1]+e[2]*xx[2]+e[3]*xx[3]

xx[1]*e[1]

xx[1], e[1]

sort(F, order=plex(seq(xx[indx[]], indx = indxes))):

F;
op(1,F);
op([1,..],F);

e[1]*xx[1]+e[2]*xx[2]+e[3]*xx[3]

e[1]*xx[1]

e[1], xx[1]

sort(F, order=plex(seq(e[indx[]], indx = indxes))):

F;
op(1,F);
op([1,..],F);

xx[1]*e[1]+xx[2]*e[2]+xx[3]*e[3]

xx[1]*e[1]

xx[1], e[1]

sort(xx[2]*e[2], order=plex(seq(xx[indx[]], indx = indxes))):

F;
op(2,F);
op([2,..],F);

xx[1]*e[1]+e[2]*xx[2]+xx[3]*e[3]

e[2]*xx[2]

e[2], xx[2]

restart;

interface(prettyprint=0):

indxes:={[1],[2],[3]};

indxes := {[1], [2], [3]}

F := add(xx[indx[]]*e[indx[]], indx = indxes):

F;
op(1,F);
op([1,..],F);

e[1]*xx[1]+e[2]*xx[2]+e[3]*xx[3]
xx[1]*e[1]

xx[1], e[1]

sort(F, order=plex(seq(xx[indx[]], indx = indxes))):

F;
op(1,F);
op([1,..],F);

e[1]*xx[1]+e[2]*xx[2]+e[3]*xx[3]
e[1]*xx[1]

e[1], xx[1]

sort(F, order=plex(seq(e[indx[]], indx = indxes))):

F;
op(1,F);
op([1,..],F);

xx[1]*e[1]+xx[2]*e[2]+xx[3]*e[3]
xx[1]*e[1]
xx[1], e[1]

 

Download exchangeproblem_ac.mw

Since the OP seems interested in Maple 2018,

restart;

kernelopts(version);

`Maple 2018.2, X86 64 LINUX, Nov 16 2018, Build ID 1362973`

eq := (-2*cos(x)^2+2*sin(x+(1/4)*Pi)^2-1)/sqrt(-x^2+4*x) = 0;

(-2*cos(x)^2+2*sin(x+(1/4)*Pi)^2-1)/(-x^2+4*x)^(1/2) = 0

#
# These two forms of eq, with these options,
# *happen* to avoid the bug in Maple 2018.
#
# The same results attain using :-solve in place
# of RealDomain:-solve.
#

RealDomain:-solve({-x^2+4*x > 0, combine(eq)}, x, explicit, allsolutions);

{x = (1/4)*Pi}, {x = (5/4)*Pi}, {x = (1/2)*Pi}

RealDomain:-solve({-x^2+4*x > 0, simplify(expand(eq))}, x, explicit, allsolutions);

{x = (1/4)*Pi}, {x = (5/4)*Pi}, {x = (1/2)*Pi}

RealDomain:-solve({x>=0, x<=4, combine(eq)}, x, explicit, allsolutions);

{x = (1/4)*Pi}, {x = (5/4)*Pi}, {x = (1/2)*Pi}

RealDomain:-solve({x>=0, x<=4, simplify(expand(eq))}, x, explicit, allsolutions);

{x = (1/4)*Pi}, {x = (5/4)*Pi}, {x = (1/2)*Pi}

combine(eq);

(-cos(2*x)-1+sin(2*x))/(-x^2+4*x)^(1/2) = 0

simplify(expand(eq));

-2*cos(x)*(cos(x)-sin(x))/(-x*(x-4))^(1/2) = 0

#
# Another way to approach this particular example:
#

solve(-x^2+4*x > 0,{x});

{0 < x, x < 4}

Student:-Calculus1:-Roots(eq, x=0..4);

[(1/4)*Pi, (1/2)*Pi, (5/4)*Pi]

 

Download RDsolve_example_2018.mw

How about using an object?

That has a constructor which you need define only once (ie. centrally). And it is supported by the type system.

That is the return value of the call to Tabulate.

You can simply use a statement-terminating colon to suppress it.

Why not write a shell script (text file, with suitable hash bang first line), and ensure that sets its own environment adequately? You could pass arguments along to that, via ssystem.

It's not clear why all you tried before lead nowhere. Why are .cshrc and tcsh and python not referenced with absolute paths?

Surely you should instead refer to shell executable by explicit full location (whether it be to a new shell script file, or to tcsh, or what else that is not a 'sh' builtin).

And how you form strings of commands (possible containing escaped double quotes, or other sttings) to pass along  can matter. It's not clear precisely what you have tried.

 

You asked at least one other question in the last two weeks about patmatch, where the convincing answer was that indets is the better tool for the job at hand.

In at least one exchange you seemed to resist that idea.

And now you seem to have completely forgotten about indets altogether. (That seems weird, to me.)

Please consider the following: indets is one of the most basic tools in Maple, being both fast and flexible. As a result it is very commonly used within stock Library commands.

In contrast patmatch can be slow and quite difficult to use flexibly and robustly. It is very rarely used in stock Library commands.

Your current example is handled by a simple call to indets. I encourage you to figure out the exact call yourself, as doing so would help your understanding and could greatly aid your future Maple development work.

note: the great advantage of indets is that it works with Maple types. The type system is very highly developed in Maple and works closely with the underlying structure of expressions. It's understandable that a Mathematica user would think first to code with patterns, since Mma's pattern-matching is highly developed and works more closely in conjunction with its expression structures. Since Maple and Mathematica have different expression strucures (and supporting tools) then the best mechanisms for matching substructures are also different.

Some years ago I answered a similar question, using a hand-rolled procedure I named &// which would apply its second argument to its first.

Eg,

   foo &// simplify;

would execute simplify(foo). This syntax works even if foo is some involved function call -- where foo gets applied to the result of that.

I only have a cell phone right now, and cannot easily find that old post. I'm sure someone else could write it quickly.

I expect it went something like this (possibly with a few defensive checks)

`&//` := proc(a,b)
             b(a):
end proc;

So then it could get used as follows,

cos(x)^2+sin(x)^2 &// simplify;

Sometimes (but not always), conversion to exp form can help. But the effort to simplify may also vary by example.

And the Roots command can sometime be useful for results within a finite range.

It just so happens that convert to exp form helps produce a simpler set of parametrized formula for the very first example. But I have seen examples where conversion to exp form prevent solve from finding the proper full general solution.

Below I include both the original and the revised example. The techniques that can be practically applied are slightly different.

restart;

kernelopts(version);

`Maple 2019.1, X86 64 LINUX, May 21 2019, Build ID 1399874`

eq := sin(9*x-(1/3)*Pi) = sin(7*x-(1/3)*Pi):

S2 := [solve(convert({eq},exp), x, allsolutions, explicit=true)]:

SS2 := {map(s->eval(x,s),simplify(S2))[]};

{-Pi*_Z1, -(19/48)*Pi-Pi*_Z3, -(13/48)*Pi-Pi*_Z2, -(7/48)*Pi-Pi*_Z3, -(1/48)*Pi-Pi*_Z2, (5/48)*Pi-Pi*_Z3, (11/48)*Pi-Pi*_Z2, (17/48)*Pi-Pi*_Z3, (23/48)*Pi-Pi*_Z2}

pts := {Student:-Calculus1:-Roots(eq, x=-2*Pi..2*Pi, maxsols=100)[]};

{0, Pi, -2*Pi, -Pi, 2*Pi, -(91/48)*Pi, -(85/48)*Pi, -(79/48)*Pi, -(73/48)*Pi, -(67/48)*Pi, -(61/48)*Pi, -(55/48)*Pi, -(49/48)*Pi, -(43/48)*Pi, -(37/48)*Pi, -(31/48)*Pi, -(25/48)*Pi, -(19/48)*Pi, -(13/48)*Pi, -(7/48)*Pi, -(1/48)*Pi, (5/48)*Pi, (11/48)*Pi, (17/48)*Pi, (23/48)*Pi, (29/48)*Pi, (35/48)*Pi, (41/48)*Pi, (47/48)*Pi, (53/48)*Pi, (59/48)*Pi, (65/48)*Pi, (71/48)*Pi, (77/48)*Pi, (83/48)*Pi, (89/48)*Pi, (95/48)*Pi}

plots:-display([
        plot((rhs-lhs)(eq),x=-2*Pi..2*Pi,color=blue),
        plots:-pointplot(map(p->[p,eval((rhs-lhs)(eq),x=p)],pts),
                         color=red,symbol=circle,symbolsize=20)],
        size=[700,200]
       );

iSS2:=indets(SS2,name) minus {Pi}:
pts2:=select(r->is(r>=-2*Pi and r<=2*Pi),
       `union`(seq(seq(seq(eval(SS2,[iSS2[1]=i,iSS2[2]=j,iSS2[3]=k]),i=-2..2),j=-2..2),k=-2..2)));

{0, Pi, -2*Pi, -Pi, 2*Pi, -(91/48)*Pi, -(85/48)*Pi, -(79/48)*Pi, -(73/48)*Pi, -(67/48)*Pi, -(61/48)*Pi, -(55/48)*Pi, -(49/48)*Pi, -(43/48)*Pi, -(37/48)*Pi, -(31/48)*Pi, -(25/48)*Pi, -(19/48)*Pi, -(13/48)*Pi, -(7/48)*Pi, -(1/48)*Pi, (5/48)*Pi, (11/48)*Pi, (17/48)*Pi, (23/48)*Pi, (29/48)*Pi, (35/48)*Pi, (41/48)*Pi, (47/48)*Pi, (53/48)*Pi, (59/48)*Pi, (65/48)*Pi, (71/48)*Pi, (77/48)*Pi, (83/48)*Pi, (89/48)*Pi, (95/48)*Pi}

pts2 minus pts, pts minus pts2;

{}, {}

restart;

eq := sin(9*x-(1/3)*Pi) = sin(5*x-(1/6)*Pi);

-cos(9*x+(1/6)*Pi) = -cos(5*x+(1/3)*Pi)

S2 := [solve(convert({eq},exp), x, allsolutions, explicit=true)]:

SS2 := {map(s->eval(x,s),convert(simplify(evalc(simplify(S2))),tan))[]};

{-(13/28)*Pi+Pi*_Z2, -(11/24)*Pi+Pi*_Z1, -(9/28)*Pi+Pi*_Z2, -(5/28)*Pi+Pi*_Z2, -(1/28)*Pi+Pi*_Z2, (1/4)*Pi+Pi*_Z2, (1/24)*Pi+Pi*_Z1, (3/28)*Pi+Pi*_Z2, (11/28)*Pi+Pi*_Z2}

pts := identify({Student:-Calculus1:-Roots(eq, x=-2*Pi..2*Pi, maxsols=100, numeric)[]});

{-(53/28)*Pi, -(47/24)*Pi, -(45/28)*Pi, -(41/28)*Pi, -(37/28)*Pi, -(35/24)*Pi, -(33/28)*Pi, -(29/28)*Pi, -(25/28)*Pi, -(23/24)*Pi, -(17/28)*Pi, -(13/28)*Pi, -(11/24)*Pi, -(9/28)*Pi, -(7/4)*Pi, -(5/28)*Pi, -(3/4)*Pi, -(1/28)*Pi, (1/4)*Pi, (1/24)*Pi, (3/28)*Pi, (5/4)*Pi, (11/28)*Pi, (13/24)*Pi, (15/28)*Pi, (19/28)*Pi, (23/28)*Pi, (25/24)*Pi, (27/28)*Pi, (31/28)*Pi, (37/24)*Pi, (39/28)*Pi, (43/28)*Pi, (47/28)*Pi, (51/28)*Pi, (55/28)*Pi}

plots:-display([
        plot((rhs-lhs)(eq),x=-2*Pi..2*Pi,color=blue),
        plots:-pointplot(map(p->[p,eval((rhs-lhs)(eq),x=p)],pts),
                         color=red,symbol=circle,symbolsize=20)],
        size=[700,200]
       );

iSS2:=indets(SS2,name) minus {Pi}:
pts2:=select(r->is(r>=-2*Pi and r<=2*Pi),
       `union`(seq(seq(seq(eval(SS2,[iSS2[1]=i,iSS2[2]=j]),i=-2..2),j=-2..2))));

{-(53/28)*Pi, -(47/24)*Pi, -(45/28)*Pi, -(41/28)*Pi, -(37/28)*Pi, -(35/24)*Pi, -(33/28)*Pi, -(29/28)*Pi, -(25/28)*Pi, -(23/24)*Pi, -(17/28)*Pi, -(13/28)*Pi, -(11/24)*Pi, -(9/28)*Pi, -(7/4)*Pi, -(5/28)*Pi, -(3/4)*Pi, -(1/28)*Pi, (1/4)*Pi, (1/24)*Pi, (3/28)*Pi, (5/4)*Pi, (11/28)*Pi, (13/24)*Pi, (15/28)*Pi, (19/28)*Pi, (23/28)*Pi, (25/24)*Pi, (27/28)*Pi, (31/28)*Pi, (37/24)*Pi, (39/28)*Pi, (43/28)*Pi, (47/28)*Pi, (51/28)*Pi, (55/28)*Pi}

pts2 minus pts, pts minus pts2;

{}, {}

 

Download trig_sols2.mw

(I wrote this before Mariusz's followup for the second example, which also does conversion to exp form.)

Here's one way. (No doubt it could be slicker.)

restart;

blockify:=proc(M::Matrix,m::posint)
    Matrix(convert(map(e->LinearAlgebra:-IdentityMatrix(m)*e, M),listlist));
end proc:

A:= Matrix(2, 2, {(1, 1) = 0, (1, 2) = 0, (2, 1) = 0, (2, 2) = 2});

Matrix(2, 2, {(1, 1) = 0, (1, 2) = 0, (2, 1) = 0, (2, 2) = 2})

blockify(A, 2);

Matrix(4, 4, {(1, 1) = 0, (1, 2) = 0, (1, 3) = 0, (1, 4) = 0, (2, 1) = 0, (2, 2) = 0, (2, 3) = 0, (2, 4) = 0, (3, 1) = 0, (3, 2) = 0, (3, 3) = 2, (3, 4) = 0, (4, 1) = 0, (4, 2) = 0, (4, 3) = 0, (4, 4) = 2})

B := Matrix([[-7,0],[0,k]]);

Matrix(2, 2, {(1, 1) = -7, (1, 2) = 0, (2, 1) = 0, (2, 2) = k})

blockify(B, 3);

Matrix(6, 6, {(1, 1) = -7, (1, 2) = 0, (1, 3) = 0, (1, 4) = 0, (1, 5) = 0, (1, 6) = 0, (2, 1) = 0, (2, 2) = -7, (2, 3) = 0, (2, 4) = 0, (2, 5) = 0, (2, 6) = 0, (3, 1) = 0, (3, 2) = 0, (3, 3) = -7, (3, 4) = 0, (3, 5) = 0, (3, 6) = 0, (4, 1) = 0, (4, 2) = 0, (4, 3) = 0, (4, 4) = k, (4, 5) = 0, (4, 6) = 0, (5, 1) = 0, (5, 2) = 0, (5, 3) = 0, (5, 4) = 0, (5, 5) = k, (5, 6) = 0, (6, 1) = 0, (6, 2) = 0, (6, 3) = 0, (6, 4) = 0, (6, 5) = 0, (6, 6) = k})

C := LinearAlgebra:-RandomMatrix(3, generator=-1..1);

Matrix(3, 3, {(1, 1) = 0, (1, 2) = 1, (1, 3) = -1, (2, 1) = 1, (2, 2) = 0, (2, 3) = -1, (3, 1) = -1, (3, 2) = -1, (3, 3) = -1})

blockify(C, 2);

Matrix(6, 6, {(1, 1) = 0, (1, 2) = 0, (1, 3) = 1, (1, 4) = 0, (1, 5) = -1, (1, 6) = 0, (2, 1) = 0, (2, 2) = 0, (2, 3) = 0, (2, 4) = 1, (2, 5) = 0, (2, 6) = -1, (3, 1) = 1, (3, 2) = 0, (3, 3) = 0, (3, 4) = 0, (3, 5) = -1, (3, 6) = 0, (4, 1) = 0, (4, 2) = 1, (4, 3) = 0, (4, 4) = 0, (4, 5) = 0, (4, 6) = -1, (5, 1) = -1, (5, 2) = 0, (5, 3) = -1, (5, 4) = 0, (5, 5) = -1, (5, 6) = 0, (6, 1) = 0, (6, 2) = -1, (6, 3) = 0, (6, 4) = -1, (6, 5) = 0, (6, 6) = -1})

 

Download blockify.mw

First I downloaded that problematic Dtm.mw file, and then I ran the following command using the location to which I saved it.

The generated string of 1D code is not perfect (it has some escaped double-quotes). But it visually shows S*(k+1) as the left hand side of an invalid assignment. And if I manually remove the escaped double-quotes (escaped special characters) and try to run it then I receive an error message about that as an invalid assignment.

restart;

Worksheet:-WorksheetToMapleText(cat(kernelopts(homedir),"/mapleprimes/Dtm.mw"));

"restart: _local(gamma); m := 10; A := 10; delta := .112; rho := .23; mu := .31; beta := 1.4; alpha := 2.1; gamma := 1.02; q := 2.3; b1 := 50; b2 := 10; b3 := 5; b4 := 20; S(0) := b1; B(0) := b2; V(0) := b3; R(0) := b4; "   for k from 0 to N do "S*(k+1) := 1/(k+1)*[A*delta*k-(rho+`&micro;`)*S*k-beta*sum(S*m*B*(k-m),k = 0 .. m)]; B*(k+1) := 1/(k+1)*[(`&micro;`+alpha+gamma)*B*k-beta*sum(S*m*B*(k-m),k = 0 .. m)]; V*(k+1) := 1/(k+1)*[rho*S*k-(1-q)*S*k-`&micro;`*V(k)]; R*(k+1) := 1/(k+1)*[-`&micro;`*R*k+B*gamma*k]; "  end do;";
"

 

Download Dtm_text.mw

[edited] It's understandable, perhaps, that this utility might baulk at complete conversion of input that has a syntax error. I think that it's obvious that code containing a syntax error is in general not translatable. Even though the incorrect syntax for the given example does have a rather obvious and natural 1D analogue.

You might concoct your own procedure to instantiate a given RV at specific values for its parameters.

For example (and you could make this more bullet proof with some additional, defensive checks),

restart;

instantiate:=proc(r::name,L::list(name=anything))
  uses ST=Statistics;
  local d;
  d := [attributes(X)][3]; # you could make this defensive
  ST:-RandomVariable(d:-ParentName(op(eval(d:-Parameters,L))));
end proc:

 

X := Statistics:-RandomVariable(Normal(mu, sigma));

_R

Y := instantiate(X, [mu=1]);

_R0

Statistics:-Mean(Y);

1

Statistics:-PDF(Y,t);

(1/2)*2^(1/2)*exp(-(1/2)*(t-1)^2/sigma^2)/(Pi^(1/2)*sigma)

 

Download RV_instantiate.mw

This also works for deeper nesting.

A1 := {1,2,{5,6},3,{13,{{21,27},16}},{8,9},{{11,12},4}};

        A1 := {1, 2, 3, {4, {11, 12}}, {5, 6},
               {8, 9},{13, {16, {21, 27}}}}

{subsindets(A1,set,op)};

        {1, 2, 3, 4, 5, 6, 8, 9, 11, 12, 13, 16, 21, 27}
First 148 149 150 151 152 153 154 Last Page 150 of 336