John May

Dr. John May

3026 Reputation

18 Badges

17 years, 320 days
Maplesoft
Pasadena, California, United States

Social Networks and Content at Maplesoft.com

Maple Application Center
I have been a part of the Mathematical Software Group at Maplesoft since 2007. I have a Ph.D in Mathematics from North Carolina State University as well as Masters and Bachelors degrees from the University of Oregon. I have been working on research in computational mathematics since 1997. I currently work on symbolic solvers and visualization as well as other subsystems of Maple.

MaplePrimes Activity


These are answers submitted by John May

The parse command doesn't work the way you are trying to use it. Take a look at the help for ?parse

The parse command takes a Maple string and parses the string as if it had been entered [as 1-D input.]

The string must consist of exactly one Maple expression. The expression is parsed, and returned unevaluated.

You need to manipulate your strings further so that they each have only one expression.  However, for a case like this you are probably better off using ?sscanf

(**) sscanf("1 -2 A.6","%d%d%s");
# [1, -2, "A.6"]

Go to the Tools > Options... menu, and make these two changes:

Display > Input Style = Maple Notation

Interface > Default format for new worksheets = Worksheet

and then hit "Apply Globally".  This will give you classic like defaults in all your new worksheets.

 

John

The function ?RootOf is a place holder for representing all the roots of an equation in one variable. Your RootOf answers represent solutions to quadratic polynomial equations, so you can have them rewritten in terms of radicals using the command ?allvalues

If you are going to specialize the parameters v1, v2, and v3 at particular values, you are probably best off doing that before calling allvalues on the answer.  You can also give the 'explicit' option to ?solve to do this as well.

 

(**) foo:=w1 = RootOf(( v1^2+v2^2+v3^2)*_Z^2-1,label=_L3)*w*v1;
                              2     2     2    2
        foo := w1 = RootOf((v1  + v2  + v3 ) _Z  - 1, label = _L3) w v1

(**) eval(foo, {v1=2, v2=1, v3=-1});
                                      2
                    w1 = 2 RootOf(6 _Z  - 1, label = _L3) w

(**) bar := eval(foo, {v1=2, v2=1, v3=-1});
                                         2
                bar := w1 = 2 RootOf(6 _Z  - 1, label = _L3) w

(**) allvalues(bar);
                                1/2            1/2
                               6    w         6    w
                          w1 = ------, w1 = - ------
                                 3              3

(**) allvalues(foo); # works too

 

John

Since A is an exact, integer, matrix,

S := SingularValues(A, output=['list']);

gives exact expressions for the singular values, and in particular, does not sort them, so you need to construct the diagonal matrix with a different order:

Sig := DiagonalMatrix([S[2], S[4], S[3]], 4, 3);

evalf[5](U.Sig.Vt);

Alternately, you could sort S by numerical value:

S := sort(S, (x,y)-> Re(evalf(x)) > Re(evalf(y)));

John

You should put the line "with(plots);" at the top of the worksheet so that pointplot gets called properly. To double check, end the line with a semi-colon: 

pp:=pointplot(V,C,symbolsize=5,color=green);

and make sure the output is a plot structure. It should display as  "pp:=PLOT(...)"

John

Take a look at ?GreekLetters for more information on this behavior.  Each of the Greek letters is actually equivalent to a maple name as shown in the chart in that help page (i.e. you can't prevent this behavior).  Your best option owuld be to use `XI` or `xI` instead or a literal subscript: `x` ctrl-_ `i`  (or  explicitly: `#msub(mi("x"),mi("i"))`).

If you don't mind the confusion sure to result, you could use the name ` xi` which will display as " xi".  Or you could use the name `ξ` which will display as the Greek letter, but is distinct from the name `xi`.  I wouldn't recommend doing either of those things.

 

John

It looks like you are trying to solve the 4x4 non-linear system:

 {(A+B)*E = .25,
(A*exp(20*C^(1/2))+B*exp(-20*C^(1/2)))*E*exp(20*C^(1/2)) = .146435452344,
(A*exp(40*C^(1/2))+B*exp(-40*C^(1/2)))*E*exp(40*C^(1/2)) = .171440065,
(A*exp(60*C^(1/2))+B*exp(-60*C^(1/2)))*E*exp(60*C^(1/2)) = .20572092}

The substitution CC=exp(10*sqrt(C)), converting floats to rationals, and taking denominators turns this into a polynomial system:

{CC^2*(4283068*CC^4*E*A+4283068*E*B-627193),
 CC^4*(114349*CC^8*E*A+114349*E*B-19604),
 CC^6*(249785*CC^12*E*A+249785*E*B-51386),
 4*E*A+4*E*B-1}

which has solution:

{A = A, B = B, CC = 0, E = 1/4/(A+B)}

The component CC=0 implies exp(10*sqrt(C))=0 which has no solution for C, which this solution is not valid for the original equations and so it has no solutions. That's what solve is telling you be returning "[]". That or a return of NULL, means that there is no solution.

First, it is best to avoid building lists or any other immutable data structure incrementally in a list. Second, are you really trying to build tables?  If not, you should probably not assign to indexed names since those implicitly construct a hash table. 

If a is supposed to be a nested list, and c should also be a nested list then you should use nested calls to seq:

(**) a := [[1], [2,3], [3,4,5], [6,7,8,9]]:
(**) c := [ seq( [seq(op(a[j]),j=1..i)], i=1..nops(a) )];

   c := [[1], [1, 2, 3], [1, 2, 3, 3, 4, 5], [1, 2, 3, 3, 4, 5, 6, 7, 8, 9]]

It is okay to use a table or array to build things up in a loop, but there will be a small amount of construction and conversion overhead so something like the following will usually be a bit slower than the above.

(**) a := [[1], [2,3], [3,4,5], [6,7,8,9]]:
(**) c := table(); # or c := Array(1..nops(a));
(**) for i from 1 to nops(a) do
             c[i] := [seq(op(a[j]),j=1..i)];
        end do:
(**) c := convert(c,list);
   c := [[1], [1, 2, 3], [1, 2, 3, 3, 4, 5], [1, 2, 3, 3, 4, 5, 6, 7, 8, 9]]

John

There are some good tips on this sort of thing to be found in both of the Maple programming manuals.  If you do not have printed copies, there are PDFs that can be download in the Maple Documentation Center. They can also be read in the online help at ?ProgrammingGuide and ?AdvancedProgrammingGuide,Contents .

 

John

As written I cannot seem to replicate the problem either in Maple 14 or Maple 7:

for mm from 3 to 5 do print(mm); aaa:=combinat[permute]([e,l,i,z,a], mm); print(nops(aaa)); end do:

I would suspect the error has to do with bad assignment lurking around somewhere else.  Something like the following:

> b := a;
                                    b := a

> a := ['b', 'c', 'd'];
                                a := [b, c, d]

> e := a;
Error, too many levels of recursion

Where delayed evaluation of 'b' in the assignment to 'a' is preventing an "Error, recursive assignment" error, but then raising the "too many levels of recursion" error whenever a or b is subsequently evaluated.

John

I am not the inhouse plotting expert, but as far as I know, there is not a way to do this unless your plots were created initally as plot components (see ?PlotComponent ).

In that case, you can do something like:

for p in [Plot0, Plot1] do
    DocumentTools:-SetProperty(p, pixelHeight, 500);
    DocumentTools:-SetProperty(p, pixelWidth, 500);
end do;

That probably doesn't help fix the problem in an existing worksheet, but it might make things easier in a future project.

I don't know of anything pre-built in the Maple Library itself, but perhaps this Protein Data Bank ( PDB ) Viewer in the Maple Application Centre might give you a place to start.

John

These are complex numeric values. Take a look at ?I and ?Complex . If you were expecting real numbers, perhaps there is something wrong with the construction of your matrix.

John

In Maple, "solve for q", (mostly) means "find an expression for q valid for essentially all values of the parameters in that expression".  In this case, if you use ?eliminate as suggested by pagan:

eliminate({mu = (1-q)/q, sigma^2 = (1-q)/q^2}, {q});

[{q = 1/(mu+1)}, {sigma^2-mu^2-mu}]

this gives a formula "solving" for q with the proviso that: sigma^2-mu^2-mu=0.  Since this is not "essentially all" values of mu, solve returns no solutions. 

Eventually, it would be nice to extend the model of solve to allow for this sort of provisional parametric solution, but there are a lot of practical and theoretical hurdles to doing this for all the cases that solve currently supports.

John

If you are in the worksheet and printing lots of things or you need more control, you might prefer a loop and ?printf:

printf("%-15s %-15s %-15s \n", `First heading` , `Second heading` , `Third heading`); for i to nops([entries(A)]) do printf("%-15a %-15a %-15a\n",A(i), B(i), C(i)) end do;

First heading   Second heading  Third heading   
a1 b1 c1
a2 b2 c2
a3 b3 c3

 

If you are using a Maple document, you'd do something a little different with ?cat and ?sprintf instead of printf and assign the result to a ?TextArea using ?DocumentTools.

mytableoutput := cat( sprintf("%-15s %-15s %-15s \n", `First heading` , `Second heading` , `Third heading`), seq(sprintf("%-15a %-15a %-15a\n",A(i), B(i), C(i)), i = 1..nops([entries(A)])));
DocumentTools:-Do(%TextArea0=mytableoutput);

John

5 6 7 8 9 10 11 Page 7 of 11