Dr. John May

2571 Reputation

16 years, 27 days
Maplesoft

Social Networks and Content at Maplesoft.com

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.

sscanf will do the job too, it just happ...

sscanf will do the job too, it just happens to return a list, since it can extract multiple values from a string:

```﻿(**) sscanf("0.02","%f");
#                                    [0.02]
(**) x := sscanf("0.02","%f")[1];
#                                   x := 0.02
(**) (x,y) := sscanf("0.02, 0.03", "%f, %f")[];
#                              x, y := 0.02, 0.03
```

The bitwise Xor in the ?Bits package wil...

The bitwise Xor in the ?Bits package will complain if you don't give it integers.  One solution would be to use the neutral operator &xor and then do a substitution when you are ready to evaluate:

```(**) expr := (a1*b0) &xor (a0*b1);
#                           expr := a1 b0 &xor a0 b1

(**) expr2 := eval(expr, {a0=1,a1=32,b0=2,b1=43});
#                              expr2 := 64 &xor 43

(**) eval(expr2, `&xor` = Bits:-Xor);
#                                      107
```

This form has the advantage that it can be manipulated by the ?Logic package as well (if that even makes sense for your application.

```(**) Logic:-Normalize(expr);
#             (a0 b1 ∧ ¬(a1 b0)) ∨ (a1 b0 ∧ ¬(a0 b1))

```

The ?GF package will allow you to comput...

The ?GF package will allow you to compute over GF(p^k):

```(**)G16 := GF(2,4);
4
G16 := Z[2] [T] / <T  + T + 1>

(**)a := G16:-PrimitiveElement();
3
a := 1 + T + T

(**)b := G16:-random();
2
b := T + T

(**)G16:-`+`(a,b);
2    3
1 + T  + T

(**)G16:-`*`(a,b);
2    3
1 + T + T  + T
```

Rather than converting your Maple to Lat...

Rather than converting your Maple to Latex, I suspect you probably want to include your 1-D source using something like the listings package for Latex. While that package does not explicitly support Maple code, it can probably be made to work well enough using one of the other language modes.

I wouldn't call this using gauges "in re...

I wouldn't call this using gauges "in reverse" since many of these components are designed to display values rather that set them. Casual inspection suggests that virtually every Gauge Component help page has an example of doing just that. e.g. ?VolumeGaugeComponent has an example of a volume gauge and dial gauge that update each other.

Here is a good post on mapleprimes explaining how to set up a continually updating component as well. Here is an example doing it with a meter: meter.mw

When you invoke the plot builder from th...

When you invoke the plot builder from the menu, it calls the Maple command ?plots,interactive.  That piece of information together with the ?showstat command should lead you to the answer with a little elbow grease.

Putting aside discussion on what code is...

Putting aside discussion on what code is completely optimal, for the most part, there is very little overhead in doing add versus a loop, as long as you are doing numeric operations and not building a symbolic sum like a polynomial (in which case 'add' always wins).

The following are all in Maple 14 in 64bit Linux.

```(**) restart;
(**) f:=proc(n) local x,i; x:=0; for i from 1 to n do x:=x+(i-1)*0.123^(i-1); end do; return x end proc:
(**) CodeTools:-Usage( f(10e5) );
#memory used=2.92GiB, alloc change=64.49MiB, cpu time=26.51s, real time=26.77s
#                                 0.1599211576

(**) restart;
(**) CodeTools:-Usage( add( (i-1)*0.123^(i-1), i=1..10e5) );
#memory used=2.86GiB, alloc change=63.99MiB, cpu time=25.64s, real time=25.71s
#                                 0.1599211576
```

However, in cases like this, a lot of speed can be gained by using hardware floating point arithmetic instead of Maple's software floats. You can introduce ?HFloat objects in the constants, and then all arithmetic will be hardware float arithmetic by contagion rules:

```(**) CodeTools:-Usage( add( (i-1)*HFloat(0.123)^(i-1), i=1..10e5) );
#memory used=96.55MiB, alloc change=75.24MiB, cpu time=1.26s, real time=1.31s
#                               0.159921157569146
(**) restart;
(**) f:=proc(n) local x,i; x:=HFloat(0.); for i from 1 to n do x:=x+(i-1)*HFloat(0.123)^(i-1); end do; return x end proc;
(**) CodeTools:-Usage( f(10e5) );
#memory used=175.48MiB, alloc change=75.99MiB, cpu time=2.07s, real time=2.08s
#                               0.159921157569146
```

The ?evalhf command generally even faster than using hfloats, but it is very restrictive. It works very well for this simple case, however

```(**) CodeTools:-Usage( evalhf( add( (i-1)*0.123^(i-1), i=1..10e5) ) );
#memory used=0.93KiB, alloc change=0 bytes, cpu time=0.38s, real time=0.38s
#                             0.159921157569146349

(**) restart;
(**) f:=proc(n) local x,i; x:=0; for i from 1 to n do x:=x+(i-1)*0.123^(i-1); end do; return x end proc:
(**) CodeTools:-Usage( evalhf( f(10e5) ) );
#memory used=0.57KiB, alloc change=0 bytes, cpu time=0.42s, real time=0.43s
#                             0.159921157569146349

```

Take a look at ?LinearAlgebra,Column tha...

Take a look at ?LinearAlgebra,Column that is probably the most straightforward approach.  Another option is the 'list' output form of ?LinearAlgebra,Eigenvectors

```(**) B := <<1,2,3>|<2,4,6>|<5,10,15>>:
(**) LinearAlgebra:-Eigenvectors(B, output='list');

#                            [-5]  [-2]             [1/3]
#                            [  ]  [  ]             [   ]
#                   [[0, 2, {[ 0], [ 1]}], [20, 1, {[2/3]}]]
#                            [  ]  [  ]             [   ]
#                            [ 1]  [ 0]             [ 1 ]
```

This gives you a list of eigenvalue, multiplicity, and a set of eigenvectors

.

sscanf...

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"]

```

Use Standard in Worksheet Mode...

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

allvalues...

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

Different order...

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

with(plots)...

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 in...

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 `&xi;` which will display as the Greek letter, but is distinct from the name `xi`.  I wouldn't recommend doing either of those things.

John

Appears to be inconsistent...

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.

 4 5 6 7 8 9 10 Page 6 of 10
﻿