acer

32597 Reputation

29 Badges

20 years, 41 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

Do you want something like this?

[edit] Originally I used the range 0*Unit(mm)..100*Unit(mm) along with the accomodating x*Unit(mm) in the calls to tau and Q when plotted. But that only works (by accident) in Maple 2017. So below I've changed the range to 0..100 instead, which makes more sense alongside the argument x*Unit(mm) and which seems to work in both Maple 2017 and Maple 2019.[/edit]

restart

``

b := 120*Unit('mm')

h := 200*Unit('mm')NULL

V := 8*Unit('kN')

I__x := (1/12)*b*h^3

"Q(x):=1/(2)*((h^(2))/(4)-(100⟦mm⟧-x)^(2))*b:" 

"tau(x):=(V*Q(x))/(`I__x`*b):"

plot(proc (x) options operator, arrow; Q(x*Unit('mm')) end proc, 0 .. 100, useunits = [Unit('mm'), Unit('mm')^3])

``

plot(proc (x) options operator, arrow; tau(x*Unit('mm')) end proc, 0 .. 100, useunits = [Unit('mm'), Unit('kN')/Unit('mm')^2])

``

Plot_function_with_units_ac3.mw

[edit] How you approach this may well depend on what you start with. If you have the liberty of entering the initial expression passed to exp (or sin and cos) then it is easier since you can use a replacement symbol for Pi. My suggestions below are more for the case that you've already obtained the -1/2+1/2*I*3^(1/2) form. [/edit]

Here are three related ways.

The first two include examples of printing the inert % form of sin and cos calls without getting the gray elements in the output.

The third way simply delays evaluation (and in consequence is fragile because any subsequent full evaluation undoes the effect).

restart;

 

ec:=proc(Z) local t:=argument(Z);
            abs(Z)*(%cos(t)+I*%sin(t));
    end proc:

 

z:=17*exp(I*2*Pi/3);

-17/2+((17/2)*I)*3^(1/2)

ec(z);

17*%cos((2/3)*Pi)+(17*I)*%sin((2/3)*Pi)

InertForm:-Display(ec(z), inert=false);

17*%cos((2/3)*Pi)+(17*I)*%sin((2/3)*Pi)

value(ec(z));

-17/2+((17/2)*I)*3^(1/2)

restart;

 

ec:=proc(Z) local t:=argument(Z);
            abs(Z)*(%cos(t)+I*%sin(t));
    end proc:

`print/%sin` := Z->'sin'(Z):
`print/%cos` := Z->'cos'(Z):

 

z:=17*exp(I*2*Pi/3);

-17/2+((17/2)*I)*3^(1/2)

ec(z);

17*%cos((2/3)*Pi)+(17*I)*%sin((2/3)*Pi)

value(ec(z));

-17/2+((17/2)*I)*3^(1/2)

restart;

 

ec2:=proc(Z) local t:=argument(Z);
            abs(Z)*('cos'(t)+I*'sin'(t));
    end proc:

 

z:=17*exp(I*2*Pi/3);

-17/2+((17/2)*I)*3^(1/2)

foo:=ec2(z);

17*cos((2/3)*Pi)+(17*I)*sin((2/3)*Pi)

eval(foo,1);

17*cos((2/3)*Pi)+(17*I)*sin((2/3)*Pi)

foo;

-17/2+((17/2)*I)*3^(1/2)

 

Download inert_rcistheta.mw

You may also use InertForm:-Display to show the %Pi from Carl's Answer without the gray symbol. Eg,

bar:=cos(2*%Pi/3)+I*sin(2*%Pi/3);
InertForm:-Display(bar, inert=false);
value(bar);

But in that case you cannot so easily extend the `print` facility to make that aspect automatic.

It is possible to adjust the underlying code so that it also colors (extended typesetting mode) typeset math.

The following seems to work ok for me in Maple 2016.2 through to Maple 2019.0.

Tabulate_mathcolor_hotedit.mw

I don't think that you are doing anything wrong. It's not easy to handle the (possible) splitting fields always best, in general. But your example shows that there's likely something to improve. (I'm submitting a bug report.)

restart:

M:=Matrix(3, 3, [[-2*lambda-kappa__c, -2*sqrt(2)*g, 0],
                 [(1/2)*g*N*sqrt(2), -lambda-(1/2)*kappa__c-gamma__phi,
                  -sqrt(2)*g], [0, g*N*sqrt(2), -2*gamma__phi]]);

Matrix(3, 3, {(1, 1) = -2*lambda-`#msub(mi("κ",fontstyle = "normal"),mi("c"))`, (1, 2) = -2*sqrt(2)*g, (1, 3) = 0, (2, 1) = (1/2)*g*N*sqrt(2), (2, 2) = -lambda-(1/2)*`#msub(mi("κ",fontstyle = "normal"),mi("c"))`-`#msub(mi("γ",fontstyle = "normal"),mi("φ",fontstyle = "normal"))`, (2, 3) = -sqrt(2)*g, (3, 1) = 0, (3, 2) = g*N*sqrt(2), (3, 3) = -2*`#msub(mi("γ",fontstyle = "normal"),mi("φ",fontstyle = "normal"))`})

evals, evecs:=LinearAlgebra:-Eigenvectors(M):

EX := ee ->
  subsindets(ee,And(RootOf,satisfies(u->nops(u)>1 and
                                     type(op(2,u),
                                          identical(index)=posint))),
             u->[allvalues(RootOf(op(1,u)),explicit)][rhs(op(2,u))]):

EX(evals);

Vector(3, {(1) = -lambda-(1/2)*`#msub(mi("κ",fontstyle = "normal"),mi("c"))`-`#msub(mi("γ",fontstyle = "normal"),mi("φ",fontstyle = "normal"))`+(1/2)*sqrt(-16*N*g^2+4*lambda^2+4*lambda*`#msub(mi("κ",fontstyle = "normal"),mi("c"))`-8*lambda*`#msub(mi("γ",fontstyle = "normal"),mi("φ",fontstyle = "normal"))`+`#msub(mi("κ",fontstyle = "normal"),mi("c"))`^2-4*`#msub(mi("κ",fontstyle = "normal"),mi("c"))`*`#msub(mi("γ",fontstyle = "normal"),mi("φ",fontstyle = "normal"))`+4*`#msub(mi("γ",fontstyle = "normal"),mi("φ",fontstyle = "normal"))`^2), (2) = -lambda-(1/2)*`#msub(mi("κ",fontstyle = "normal"),mi("c"))`-`#msub(mi("γ",fontstyle = "normal"),mi("φ",fontstyle = "normal"))`-(1/2)*sqrt(-16*N*g^2+4*lambda^2+4*lambda*`#msub(mi("κ",fontstyle = "normal"),mi("c"))`-8*lambda*`#msub(mi("γ",fontstyle = "normal"),mi("φ",fontstyle = "normal"))`+`#msub(mi("κ",fontstyle = "normal"),mi("c"))`^2-4*`#msub(mi("κ",fontstyle = "normal"),mi("c"))`*`#msub(mi("γ",fontstyle = "normal"),mi("φ",fontstyle = "normal"))`+4*`#msub(mi("γ",fontstyle = "normal"),mi("φ",fontstyle = "normal"))`^2), (3) = -lambda-(1/2)*`#msub(mi("κ",fontstyle = "normal"),mi("c"))`-`#msub(mi("γ",fontstyle = "normal"),mi("φ",fontstyle = "normal"))`})

subsindets(%,radical,u->map(collect,u,g,simplify));
 

Vector(3, {(1) = -lambda-(1/2)*`#msub(mi("κ",fontstyle = "normal"),mi("c"))`-`#msub(mi("γ",fontstyle = "normal"),mi("φ",fontstyle = "normal"))`+(1/2)*sqrt(-16*N*g^2+(2*lambda+`#msub(mi("κ",fontstyle = "normal"),mi("c"))`-2*`#msub(mi("γ",fontstyle = "normal"),mi("φ",fontstyle = "normal"))`)^2), (2) = -lambda-(1/2)*`#msub(mi("κ",fontstyle = "normal"),mi("c"))`-`#msub(mi("γ",fontstyle = "normal"),mi("φ",fontstyle = "normal"))`-(1/2)*sqrt(-16*N*g^2+(2*lambda+`#msub(mi("κ",fontstyle = "normal"),mi("c"))`-2*`#msub(mi("γ",fontstyle = "normal"),mi("φ",fontstyle = "normal"))`)^2), (3) = -lambda-(1/2)*`#msub(mi("κ",fontstyle = "normal"),mi("c"))`-`#msub(mi("γ",fontstyle = "normal"),mi("φ",fontstyle = "normal"))`})

EX(evecs):
subsindets(%,radical,u->map(collect,u,g,simplify));

Matrix(3, 3, {(1, 1) = 8*g^2/(lambda+(1/2)*`#msub(mi("κ",fontstyle = "normal"),mi("c"))`-`#msub(mi("γ",fontstyle = "normal"),mi("φ",fontstyle = "normal"))`+(1/2)*sqrt(-16*g^2*N+(2*lambda+`#msub(mi("κ",fontstyle = "normal"),mi("c"))`-2*`#msub(mi("γ",fontstyle = "normal"),mi("φ",fontstyle = "normal"))`)^2))^2, (1, 2) = 8*g^2/(lambda+(1/2)*`#msub(mi("κ",fontstyle = "normal"),mi("c"))`-`#msub(mi("γ",fontstyle = "normal"),mi("φ",fontstyle = "normal"))`-(1/2)*sqrt(-16*g^2*N+(2*lambda+`#msub(mi("κ",fontstyle = "normal"),mi("c"))`-2*`#msub(mi("γ",fontstyle = "normal"),mi("φ",fontstyle = "normal"))`)^2))^2, (1, 3) = 2/N, (2, 1) = -2*sqrt(2)*g/(lambda+(1/2)*`#msub(mi("κ",fontstyle = "normal"),mi("c"))`-`#msub(mi("γ",fontstyle = "normal"),mi("φ",fontstyle = "normal"))`+(1/2)*sqrt(-16*g^2*N+(2*lambda+`#msub(mi("κ",fontstyle = "normal"),mi("c"))`-2*`#msub(mi("γ",fontstyle = "normal"),mi("φ",fontstyle = "normal"))`)^2)), (2, 2) = -2*sqrt(2)*g/(lambda+(1/2)*`#msub(mi("κ",fontstyle = "normal"),mi("c"))`-`#msub(mi("γ",fontstyle = "normal"),mi("φ",fontstyle = "normal"))`-(1/2)*sqrt(-16*g^2*N+(2*lambda+`#msub(mi("κ",fontstyle = "normal"),mi("c"))`-2*`#msub(mi("γ",fontstyle = "normal"),mi("φ",fontstyle = "normal"))`)^2)), (2, 3) = -(1/4)*sqrt(2)*(2*lambda+`#msub(mi("κ",fontstyle = "normal"),mi("c"))`-2*`#msub(mi("γ",fontstyle = "normal"),mi("φ",fontstyle = "normal"))`)/(g*N), (3, 1) = 1, (3, 2) = 1, (3, 3) = 1})

 

Download evals_ac.mw

I have previously submitted bug reports for examples such as this where simplify(...,size) does not compress as much as can a judicious collect with simplification of the ensuing coefficients.

In this example that situation occurs for the subexpression within the radical.

I have an oracle that speculatively tries collecting w.r.t. the relevant names in the subexpression (sum), and indicates which compresses well or best. Hence the following suggestions, relating to collect w.r.t. g. These vary a little because more generally you may or may not want other kinds of simplification effects:

restart:

expr1:=-lambda-(1/2)*kappa__c
       -gamma__p-(1/2)*sqrt(-16*N*g^2+4*lambda^2-8*lambda*gamma__p
                            +4*lambda*kappa__c
                            +4*gamma__p^2-4*gamma__p*kappa__c
                            +kappa__c^2):

desired_form:=1/2*(-2*gamma__p - kappa__c - 2 *lambda
              - sqrt(-16*N*g^2 + (-2 * gamma__p
              + kappa__c + 2 * lambda)^2)):
desired_form;

-gamma__p-(1/2)*kappa__c-lambda-(1/2)*(-16*N*g^2+(-2*gamma__p+kappa__c+2*lambda)^2)^(1/2)

subsindets(expr1,radical,u->map(collect,u,g,simplify));

-gamma__p-(1/2)*kappa__c-lambda-(1/2)*(-16*N*g^2+(-2*gamma__p+kappa__c+2*lambda)^2)^(1/2)

subsindets(expr1,radical,u->map(collect,u,g,uu->simplify(uu,size)));

-gamma__p-(1/2)*kappa__c-lambda-(1/2)*(-16*N*g^2+(-2*gamma__p+kappa__c+2*lambda)^2)^(1/2)

subsindets(expr1,`+`,u->frontend(collect,[u,g,simplify]));

-gamma__p-(1/2)*kappa__c-lambda-(1/2)*(-16*N*g^2+(-2*gamma__p+kappa__c+2*lambda)^2)^(1/2)

subsindets(expr1,`+`,u->frontend(collect,[u,g,uu->simplify(uu,size)],
                                 [{`+`,`*`},{}],uu->simplify(uu,size)));

-gamma__p-(1/2)*kappa__c-lambda-(1/2)*(-16*N*g^2+(-2*gamma__p+kappa__c+2*lambda)^2)^(1/2)

Download simplification_under_sqrt_ac.mw

Even if you use 2D Input mode the methodology of assigning a procedure with the syntax f(x) := ... is a bad idea, not least because it is ambiguous syntax that can easily lead to problems.

There are a variety of ways to accomplish the substitution for s2 within the procedure body.

First, in 2D Input,

restart

f := proc (x) options operator, arrow; x^2*s2+x+1+s2 end proc

proc (x) options operator, arrow; x^2*s2+x+1+s2 end proc

f(2)

5*s2+3

g := subs(s2 = 9, eval(f))

proc (x) options operator, arrow; 9*x^2+x+10 end proc

g(2)

48

h := subs(s2 = 9, proc (x) options operator, arrow; x^2*s2+x+1+s2 end proc)

proc (x) options operator, arrow; 9*x^2+x+10 end proc

h(2)

48

s := subs(s2 = 9, unapply(s2*x^2+s2+x+1, x))

proc (x) options operator, arrow; 9*x^2+x+10 end proc

s(2)

48

t := unapply(subs(s2 = 9, s2*x^2+s2+x+1), x)

proc (x) options operator, arrow; 9*x^2+x+10 end proc

t(2)

48

``

Download subs_proc_2D.mw

And now in 1D Maple Notation,

restart;

f := x -> x^2*s2+x+1+s2;

proc (x) options operator, arrow; x^2*s2+x+1+s2 end proc

f(2);

5*s2+3

g := subs(s2=9, eval(f));

proc (x) options operator, arrow; 9*x^2+x+10 end proc

g(2);

48

h := subs(s2=9, x -> x^2*s2+x+1+s2);

proc (x) options operator, arrow; 9*x^2+x+10 end proc

h(2);

48

s := subs(s2=9, unapply(x^2*s2+x+1+s2, x));

proc (x) options operator, arrow; 9*x^2+x+10 end proc

s(2);

48

t := unapply(subs(s2=9, x^2*s2+x+1+s2), x);

proc (x) options operator, arrow; 9*x^2+x+10 end proc

t(2);

48

 

Download subs_proc.mw

In the case that you have already assigned to s2 then you can use the unapply command directly. Eg,

s2 := 9:

f := unapply(x^2*s2+x+1+s2, x);

                   2
      f := x -> 9 x  + x + 10

f(2);

                48

As for how the body of the procedure gets pretty-printed (formatted as 2D Math), or not, you have a few alternatives.

restart;

s2 := 9:

f := unapply(x^2*s2+x+1+s2, x);

                   2
      f := x -> 9 x  + x + 10

lprint(eval(f));    # line-printing

  x -> 9*x^2+x+10

sprintf("%a", eval(f));    # as a string

           "x -> 9*x^2+x+10"

sprintf("%-P", eval(f));  # Maple 2019.0

         "x -> 9*x^2 + x + 10"

showstat(f);

  f := proc(x)
     1   9*x^2+x+10
  end proc

You could also set interface(prettyprint=1) (or 0) but keep in mind that would affect display of other expressions as well.

Why not scale down the 1014x1024 pixel image before using it? That should reduce the memory allocation by the kernel. (I chose 50x50, but you could experiment.)


 

restart;

with(plots): with(ImageTools):

imgsmaller := Scale(Read(cat(kernelopts(homedir),"/mapleprimes/smile.jpg")),1..50):
op(2,imgsmaller);

1 .. 50, 1 .. 50, 1 .. 3

str:="","","","","","","","","","","?":
location_func,dy,dz:=3*sin(2*3.14/10*y),.75,.75:

Asmaller := display(seq(display(textplot3d([0,1,4.5,cat(str[1..ha])],align='right'),
                                textplot3d([0,3.5,-4.5,"By Janesefor ~"],align='right'),
                                plot3d([0,s,t],subs(y=ha-1,
                                                    [s=y-dy..y+dy,
                                                     t=location_func-dz..location_func+dz])[],
                                       image=imgsmaller,axes=none,scaling=constrained,
                                       orientation=[180,90,-180],view=[default,0..10,-5..5],
                                       glossiness=0,lightmodel=light4)),
                        ha=[`$`(1..nops([str]))]),
                    insequence=true):

Asmaller;

Download smile_acc.mw

Also, here is a way to animate it as a 2D plot. (I used parts of a method from this old post, where the data of an image can be used as the color data of a densityplot structure.) I made it with 22 frames and displayed it with size=[500,500], but you could change those.

restart;

with(plots): with(ImageTools): with(ArrayTools):

imgsc := Scale(Read(cat(kernelopts(homedir),
                    "/mapleprimes/smile.jpg")),1..50):

(m,n) := Width(imgsc), Height(imgsc);

50, 50

C := Alias(imgsc,[m*n,3]):
DataTranspose(C,n,m,1): # acts inplace
img := FlipDimension(Alias(C,[m,n,3]),2):
(imgsc,C) := 'imgsc','C': gc();

zeromn := Matrix(1..m,1..n,datatype=float[8]):

putface:=proc(a,b)
     PLOT(GRID(a..a+1, b..b+1, ArrayTools:-Alias(zeromn),
               COLOR(RGB,ArrayTools:-Alias(img))),
          STYLE(PATCHNOGRID));
end proc:

str:="","","","","","","","","","","?":
location_func,dy,dz:=3*sin(2*3.14/10*y),.75,.75:

numframes := 22;
A := animate(display,['putface(t,3*sin(2*3.14/10*t))',
                      textplot([5,4.5,
                               'cat'('seq'([str][i],i=1..floor(1+t)))]),
                      gridlines=false, scaling=unconstrained,
                      axes=none, view=[default,-3.0..5.0]],
             t=0..10,frames=numframes,paraminfo=false):

22

plots:-display(A, size=[500,500], insequence);

Download smile_acer.mw

Do you mean custom tickmarks along the axis?  If so then try searching the Maple Help for tickmarks.

You might try making sure that you have the latest point-release update for Maple 2016. That is a free download if you already have a valid installation of Maple 2016. (You can also check for updates within Maple's main menubar.)

The update to Maple 2016.2 is available here. It includes changes in the point-release(s) before it, eg. Maple 2016.1.

(One reason I mention this is that the update Maple 2016.1 release notes specifically mentions some "Enhancements to Maple's context-sensitive menus" to right-click context-menus. So perhaps that might address some of your performance issues.)

If the problems persist, then more details might help diagnose the problem. What packages, if any, do you have loaded when the context-menu is slow to generate and display? Is it only slow the first time in a session, including following any restart? Is it slow for a particular kind of expression? And, as Carl queried, do you have the language set to something other then English?

Maple has its own 3rd-party installer and uninstaller. While Maple itself (once installed) is 64-bit, its installer has some 32-bit runtime components.

So to install Maple 2018 or 2019 for Debian it is necessary to have some 32-bit compatibility packages installed. See this Maplesoft Tech Support page for a list (which includes a Debian note).

Yes, in principle it's possible to run Maple on Debian.

You can map the expand command over a matrix or Matrix.

The simplify command will map automatically over those, in modern Maple.

restart;
# Using lowercase matrix

Ts:=matrix([[cos(omega*t), cos(omega*t-2/3*Pi), cos(omega*t+2/3*Pi)],
            [sin(omega*t), sin(omega*t-2/3*Pi), sin(omega*t+2/3*Pi)],
            [1/2, 1/2, 1/2]]):

Xin:=matrix([[cos(omega*t+alpha)],
             [cos(omega*t+alpha-2/3*Pi)],
             [cos(omega*t+alpha+2/3*Pi)]]):

map(simplify@expand,linalg:-multiply(Ts, Xin));

Matrix(3, 1, {(1, 1) = (3/2)*cos(alpha), (2, 1) = -(3/2)*sin(alpha), (3, 1) = 0})

simplify(map(expand,linalg:-multiply(Ts, Xin)));

Matrix(3, 1, {(1, 1) = (3/2)*cos(alpha), (2, 1) = -(3/2)*sin(alpha), (3, 1) = 0})

restart;
# Using capitalized Matrix

Ts:=Matrix([[cos(omega*t), cos(omega*t-2/3*Pi), cos(omega*t+2/3*Pi)],
            [sin(omega*t), sin(omega*t-2/3*Pi), sin(omega*t+2/3*Pi)],
            [1/2, 1/2, 1/2]]):

Xin:=Matrix([[cos(omega*t+alpha)],
             [cos(omega*t+alpha-2/3*Pi)],
             [cos(omega*t+alpha+2/3*Pi)]]):

map(simplify@expand, Ts . Xin);

Vector(3, {(1) = (3/2)*cos(alpha), (2) = -(3/2)*sin(alpha), (3) = 0})

simplify(map(expand, Ts . Xin));

Vector(3, {(1) = (3/2)*cos(alpha), (2) = -(3/2)*sin(alpha), (3) = 0})

 

Download map_expand_matrix.mw

Yes. Your last paragraph describes what's happening.

It's not specific to the simplify command.

Why are you so surprised by this?

What would be your comprehensive delineation between circumstances where NULL inside an expression sequence should get flattened out and circumstances where it should not?

It doesn't seem like a very good idea to have an application that relies on the initial state of currentdir().

But cannot your application's startup code set currentdir to something relative to, say, kernelopts(':-homedir') ?

What sort of i/o do you intend on trying within the MaplePlayer? (There's a possibility that the MaplePlayer would have to look into a temp directory in the FileTools sense.)

Right, an Execution Group or Document Block can only have a sole Task region, which can have worksheet content embedded into it. So each call to Tabulate (or Explore, or InsertContent, or ImageTools:-Embed, etc) executed within the same Execution Group simply replaces the content in that sole Task Region.

Here are two approaches to getting what you've described.

The first way involves keeping a running Matrix that accumulates the various results. It simply replaces the embedded tabulation each time that additional results are added to the bottom of that Matrix. This is easy if the tabulations all have the same number of columns.  Tab1.mw

The second way involves keeping a running copy of the XML representations of separate Tabulate calls, stored separately as, say, entries of a Vector. At each iteration it embeds all the tabulations accumulated so far (in order) as separate Tables. This is more suitable if the various tabulations are quite different from each other, eg. different number of columns. Tab2.mw 

The Tabulate command is really just a convenient way to build -- and, normally -- embed the XML representing a GUI Table. The undocumented option output=XML allows the Tabulate command to return the XML for the constructed Table without actually embedding it. So the second approach simply stores them, allowing you to replace the sole Task region for an Execution Group or Document Block with whatever combination of such previously constructed Tables as you see fit.

Hopefully you can adjust one of the two approaches to your purpose. I used Maple 2018.0.

You already had them combined by using plots[display], but their curves are so close that they overlap and you can only see the one on top.

One alternative is to plot one of them as a line and the other as a point-plot.

I increased h for Runge while plotting List as a point-plot, since otherwise the point symbols overlap and don't look so good. But you could also use the smaller h and just plot every 2nd (or 10th, or whatever) entry of List generated using the smaller h.

I also added a legend entry to each.

Another alternative is to plot them side by side.

question_ac.mws

It'd be helpful if you told us what exactly you wanted the final combined plot to look like.

First 157 158 159 160 161 162 163 Last Page 159 of 339