itsme

599 Reputation

13 Badges

13 years, 28 days

MaplePrimes Activity


These are answers submitted by itsme

another option (to running as cli) is to convert your worksheets to mpl files (just text files with maple commnads), and then open a gui session, and use read command like so:

 

restart:

read("sheet1.mpl");

read("sheet2.mpl");

read("sheet3.mpl");

etc..

depending on you needs you could export the whole thing to pdf. (or copy paste indvidual results - that could be painful though)

This may not answer your question, as I don't know how to guarantee that exported plots have a particular dpi. However what I have found helps exporting usable plots is to make them "large". Literally, export them (using a function like the one I show below), with sizes of say 1000 x 1000 pixels (or more!). I then either let latex shrink them automatically (by enforcing the figure width) or shrink them (and often convert to other formats) with other external software. Note that for this to work (meaning for plots to "look good") one often has to play with font sizes and line widths before the exporting is done.

Here is a function that you may find useful.

savePlot:=proc(v_p, v_fileName, v_w:="800", v_h:="500")
    plotsetup("png", plotoutput=v_fileName, plotoptions=cat("quality=100,portrait,noborder,width=",v_w,",height=",v_h));
    print(plots[display](v_p));
    Threads[Sleep](2):
    fclose(v_fileName):
    plotsetup(default);
end:

Finally, IMHO, exporting plots from maple is a frustrating experience. It all feels like a hack... quite a few things are broken, and even basic things require more work than they should.
Another option is fist exporting your data, and then using something more suitable for the actual plotting - a python library called matplotlib might be worth checking out.

You need to manually provide xtickmarks and ytickmarks as parameters to listdensityplot.

Look in help for examples... but these are basically just lists that tell maple where to put tickmarks and what values they should have for a given column/row of the data matrix.

So if for example f(column_index) is the transformation function that takes a column index and returns the actual parameter you're interested in displaying, then you want to do something like:

listdensityplot(.... , ytickmarks=[seq(i=f(i), i=1..20, 1)], ....);

you can change the spacing of of your items in the list accordingly, and do likewise for xtickmarks.


I second Joe's comment. Everything of course depends on what you're doing inside your function and the kind of data you're dealing with. At a (very) quick glance at your worksheet it seems that all of these could work for you. This also assumes the extra coding and planning required is worth the gain in speed you could get.. for some problems, it may not be worth it.

1) Define all arrays in the problem (where original data lives) as well as where you want to store results as a specific type (say float[8])... and allocate the memory for them before hand (if speed is important, and you know the final sizes of everything before hand, there should be no need to re-allocate/copy of anything once you start a run).

2) compile your function - the right way to go her is to tell maple what kind of data you're passing in... like this

f:=proc(x::float, y::float, .... , results_array::Array(datatype=float[8])

..note here results_array is meant to be filled in inside the function f - it could be just a chunk of a bigger array that you've allocated before the start of the run that can store the data for all the iterations of the loop. This way you're not doing any copying or unnecessary memory allocations.

3) note, you can in fact also put the loop inside the compiled function!.. this may offer a speedup, but then you're limiting your options when it comes to parallelizing... which brings me to...

4) parallelize if possible. If your function f is thread safe, then you can use Threads:-Map. If not, then Grid:-Map should work (but see this thread if you're having issues http://www.mapleprimes.com/questions/201392-GridMap-No-Speed-Up  - also note, that i've had problems with Grid and compiled code, but Grid:-Map in some cases where code can't be comipiled can be very useful)

Depending on what you're doing you can often get an order of magnitude speedup (easily) for many things just following (some of) the above.

 

 

you can read up on plotsetup in the docs on how to adjust this for jpegs... here is a procedure that will save a png.

 

savePlot:=proc(v_p, v_fileName, v_w:="450", v_h:="350")
    plotsetup("png", plotoutput=v_fileName, plotoptions=cat("quality=100,portrait,noborder,width=",v_w,",height=",v_h));
    print(plots[display](v_p));
    Threads[Sleep](2):
    fclose(v_fileName):
    plotsetup(default);
end:

p:=plot(sin(x), x=0..10);
savePlot(p, "myfile.png");

Here are a couple of pointers that work for me when trying to get maple to generate pretty-plots. How well these can work slightly depends on what you're doing with the plots after.

- use postscript as as "plotting device" in the plotsetup command, instead of jpeg/png/gif. This helps things tremendously, but does not work in all instances. It is a good approach if you have "simple 2d plots" (i.e. something like 'plot(sin(x),x=0..10);' ). For other cases, where there are many data points (example densityplot) the files generated are not usable as they are too big. If you still need the final plot in a jpeg/png/gif format, sometimes converting afterwards gives better results. 


- if you have to generate jpeg/png/gif plots directly, increase the dimensions of the plots. This can be done via something like:


plotsetup('jpeg', plotoutput=myfile.jpeg, plotoptions="quality=100,portrait,noborder,width=800,height=800);

The plot you will generate will be often bigger in dimensions than you need, but when scaled down by the program (say latex, or a presentation, or whatever) where you want to use the plot, it will look very good. The "trick" here is that you may want to increase the sizes of everything, so make the fonts bigger, the linewidth bigger, etc.

Also, note that these pointers are only useful when plotting from within the gui environment (document or worksheet). Producing plots through the cmd-line (i.e. via 'maple some_code.mpl') is unfortunately completely broken. I have big hopes that it gets fixed sometime, as now presumably more people will use maple in a non-interactive way (via the new IDE for example) - but we have to wait and see if that will be a priority.

I do wonder how other people deal with this issue? How do you produce publication-quality plots? do you use maple or just export final data to other programs?

Good find!

Has anyone yet submitted an SCR about this? it seems like it should be very high priority.

I have recently been simplifying long and tedious expressions where had to make lots of these kinds of assumptions - now having second thoughts regarding the correctness of the results.

The Physics package can do that. See:
http://www.maplesoft.com/support/help/Maple/view.aspx?path=Physics/*

in the future, please try to type out the equations so that one can easily copy/paste into maple. That will increase your chances of the question being answered. Note, that usually these things simply if you write k[n] in terms of L.

 

restart:

psi:=N[n]*(sin(k[n]*x) + I* k[n]*lz*cos(k[n]*x));
psiSquared:=conjugate(psi)*psi assuming k[n]::integer, x::real, N[n]::real, lz::real;
#want to calculate:
Int(psiSquared, x=0..L) assuming k[n]::integer, x::real, N[n]::real, lz::real;

result:=value(%);
#solve result=1 for N[n] - taking the positive value usually makes sense
solve(result=1, N[n]);

 

find_normalizatio.mw

... you can use the ~ operators. Like this:

 

r:=[a,b,c]:


s:=-r^~2 +~ lambda;

 

You can do this with the diff operator from the "Physics" package. 

See the first few examples here:

http://www.maplesoft.com/support/help/Maple/view.aspx?path=Physics%2fdiff

For everything to work, you just have to make sure that in L itself, you define parameters as functions of time. So in your L, you should have theta be theta(t) and thetad be diff(theta(t),t) and same for r. Then just import the Physics package at the top of your worksheet like this:

with(Physics):

... and now maple understands statements like, diff(L, diff(r(t),t))  , etc

 

 

I can confirm seeing this behavior, but can't now remember how I got around it. As Carl below suggests, it would be best if you constructed a simple (simplest possible) example and show us the full contents of the ".mw" and ".mpl" files that lead to this problem.

 

... As a side note, saving plots from the "terminal mode" is certainly broken. For example the jpeg backend does not support antialising and/or respect the font settings at all (at least as of maple 15/16 which is the last time I had checked). I have reported this in the past, but I think it's a low priority problem, as perhaps not that many people use the terminal mode.

This does not address any of your memory questions, but as a workaround, you can just use the "-c " flag of the "maple" command, which lets you define some maple code (in your case variables) that gets passed to the maple interpreter. You can then simply have a loop over some set of values in an external script (say in bash/python/whatever) that would execute "maple -c ... " type command which would define the values for the variables maple would work on. This way each time you run "maple" you would run it with a new kernel.

I have done this kind of thing often and it works fine. 

 

EDIT1: Note, I'm calling "maple" what you're calling "cmaple" as in linux (what i use) the executable is in fact called "maple". 

EDIT2: For completeness, let me add a trivial example in case someone finds this kind of thing useful:


contents of maple_code.mpl:
a:=a_INPUT:

b:=b_INPUT:

evalf(a*sin(b*Pi));

 

contents of runner.sh
!/bin/bash

for variable1 in 1 2 3 

do    

for variable2 in "0.1" "0.2"     

do          

maple -c "a_INPUT:=${variable1};" -c "b_INPUT:=${variable2};" ./maple_code.mpl   

done

done


Then simply make sure runner.sh is executable with 
chmod +x ./runner.sh
and run it.

It will run the maple_code.mpl with effectivelly different set of parameters each time. 


Note that the use of "_INPUT" suffix is of course not necessary and you could imagine settings variable values directly, but it can be useful in more complicated cases where you may want to give certain variables values later during execution and want only minimal changes to the code you usually execute in a "reagular" way. 

 

1) look up ExportMatrix

 

2) the command 

interface(rtablesize=32);

will do it. You can change the number 32 to whatever you want if you have bigger matrices. 

 

 

 

here is one way:

savePlotEPS:=proc(p, fileName, w:="750", h:="450")
    plotsetup('postscript', plotoutput=fileName, plotoptions=cat("quality=100,portrait,noborder,width=",w,",height=",h));
    print(display(p));
    plotsetup(default):
end proc:

myplot:=plot(sin(x), x=0..10):

savePlotEPS(myplot,"myfile.eps", 500, 400):

You could change the 500/400 numbers to whateve size you want.

Note that I have had problems with maple sometimes not reseting back to defaults or even overwriting files (when savePlotEPS is called in a loop!). One way around it that seems to work, is this version (see the sleep command):

savePlotEPS:=proc(p, fileName, w:="750", h:="450")
    plotsetup('postscript', plotoutput=fileName, plotoptions=cat("quality=100,portrait,noborder,width=",w,",height=",h));
    print(display(p));
    Threads[Sleep](2);
    plotsetup(default):
end proc:

1 2 3 4 Page 2 of 4