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

You might take a look at ?plots[matrixplot] and ?plots[listplot3d] those are two different methods for creating plots from coordinate data.

 

John

You might try generating the points yourself and then using ?plots[pointplot3d] to build the plot.

Here is the shortest way I could think off the top of my head:

(**) WTable := Matrix(40,9,(i,j)->i*1000+j):
(**) WTable := WTable([seq(i,i=1..40,2)],..);

It is also possible to use `$` instead of 'seq' but the above is probably better Maple (esthetically):

(**) WTable := Matrix(40,9,(i,j)->i*1000+j):
(**) WTable := WTable([(2*i-1)$i=1..20],..);

I should back up a second and address this:

Writing some code in the "Startup Code" via Edit > Startup Code. The good thing here is that this code follows the document, meaning that it can be used by another person. The bad thing is: it does not seem to work after a restart, only at startup.

As fas as I can tell (at least in Maple 14), the code in the startup code area does execute every time the "Restart Maple Server" button is pressed or the "restart;" command is given (this is the expected behavior).  Here is a small test of that: startup_restart_tes.mw

For details on initialization files you can see ?CreateMapleInitializationFile

You could try to make a worksheet script for your students.  I know the following Maple code works in Linux to set up the init file so that it will automatically run 'with' after each restart. I think it works in Windows, but I have not tested it.

 # Uncomment the approriate line below:
#mapleinitfile := cat(kernelopts(homedir), kernelopts(dirsep), ".mapleinit"); # Linux, Solaris, and Mac
#mapleinitfile := cat(kernelopts(homedir), kernelopts(dirsep), "maple.ini"); # Windows (untested)

FileTools:-Copy(mapleinitfile, cat(mapleinitfile, ".mpl.bak"));
FileTools:-Text:-Open( mapleinitfile, 'append');
FileTools:-Text:-WriteLine(mapleinitfile, "with(PackageName):");
FileTools:-Text:-Close( mapleinitfile );


In many cases ?isolve can handle these sorts of problems. But for the specific problem of finding integral points on curves I suspect that it only works in the genus 0 case.

 

John

A slightly simpler solution than the one Acer proposes would be to use the parametric sytem tool added to SolveTools in Maple 14:

sol := SolveTools:-PolynomialSystem( {a*b^2-b+c-d-3, a^3*b^2-b+c-d^3+4, 
    a^4+b^3-b^2+c-d+2, 2*a*b^2-b+c-d-1-X}, {a,b,c,d}, domain=parametric);

sol[1] will be a (large) generic solution in terms of X. while sol[2] is a condition on X which must hold for the sol[1] to be a valid solution. In this case:

(X^4-8*X^3+24*X^2-33*X+20)*(X^4-8*X^3+24*X^2-33*X+24)*(X-2) <> 0

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

.

4 5 6 7 8 9 10 Page 6 of 11