764 Reputation

14 Badges

16 years, 190 days

MaplePrimes Activity

These are answers submitted by itsme

I think one of the dots in the last definition for w is a decimal point and not a multiplication sign.

... Either way, I recommend not using the default 2d math input at all... your millage may vary, but using maple in a worksheet mode with only 1d input will eliminate most of copy/paste/input issues. You can change defaults in the preferences.

Besides using Carl's very nice suggestions above, you might also find the Finance package useful. The Finance package can solve stochastic differential equations "out-of-the-box" and it has some nice features related to plotting (for example showing many realizations at once, etc).

The other reply shows how to get a formatted time. Another command that is very useful when creating "informative" files names is sprintf - it makes it trivial to for example create dynamic file names based on (say) variable names and their values.

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:







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

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

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

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.



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;

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

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



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


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

See the first few examples here:

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:


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

1 2 3 4 Page 2 of 4