Mac Dude

1546 Reputation

17 Badges

12 years, 36 days

MaplePrimes Activity

These are answers submitted by Mac Dude

I'd suggest you write the important output of your worksheet to disk as a Matrix or as several Matrices (or Vectors). A lot gets saved with the Maple workbook, but the variables do not get assigned their values until the sheet is run. In fact, the kernel has no part in the loading process of a worksheet.

There is a Maple command "save" that allows to save the content of variables in assignment form. Check its documentation. Presumably, if you saved all variables with assigned values, then reading the file back in would allow you to restore the state of your worksheet.

There is also the function anames('user') that returns a sequence of all user-assigned names, which you should be able to use in the save command.

I.e. something like

   save anames('user'), "state.m";

should save,

   read "state.m";

should restore your state.

Note that I have not actually used these. I'd try on a simple example first before using it on results of a 12-hour-run


Your first case fails because of round-off error. You can add "epsilon=<some small number>" to the Int function and adjust epsilon for it to work. On my system I run with Digits=15 by default, and the numeric integration works for epsilon down to 1E-9. Comparing the result to the analytic calculation indicates you get between 8 and 10 digits accuracy.

The case with alpha=500 is pathological and should fail. alpha is in the exponent so you are taking something to the 500s power. You are up to no good here. On my system I get mostly Float(undefined) as damn well I should.

epsilon=1E-9 also works for the last case even though I think alpha=45 is still crazy.

You can also play with digits=<some integer> to get more precision.

But the real question is: What are you trying to achieve here? It seems like your functions approach 0 for relatively modest values of x and stay there (I plotted your expression for some values of alpha, beta and j). You are likely better off by finding a reasonable upper limit for the integration region and use one of the other integration methods like _d01akc or _Sinc. I have had a similar battle once and eventually realized that I can't always avoid determining the upper limit of an integral.

Mac Dude.

There are two ways you can run Maple in the GUI: either with one kernel being shared by all worksheets or with a separate kernel for each worksheet. You pick what you want in the Preferences on the "General" tab (it is called "Mathematical Engine").

If you run separate kernels (which most of us do) then each worksheet is completely separate, and you do not get access to the variables of the other worksheet. If you run a shared kernel you can get access across worksheets, but you need to ensure that the sheets don't clobber each others variables.

For separate kernels, I guess your options of "inter-sheet communication" are limited to writing and reading files. There is a good chance you'll run into synchronization issues.

If you are after parallelism, you may consider running snippets of Maple code as separate processes using either the Thread package (shared memory) or the Grid package (in essence, MPI but only on your machine). In my and others' experience, though, achieving gainful parallelism in Maple is actually not all that easy. If you do not need parallelism, why not wrap the code for the second sheet into a Module with one or more procedures and call it from the worksheet using the data produced?

Mac Dude



plottools[transform] can change the displayed coordinate and therefore do what you want. See its help file.

Mac Dude.

Checkout the Filetools package, it has all sorts of write and read commands, with different formats.

When settling on a scheme you also need to consider how you want the data presented upon reading them back. If you write individual variables out, how will you keep track of them upon reading them back in?

It would be nicest if you could make a table (which is an associative array & you can use variable names as index) and write/read that. A cursory glimpse in the help facility did not reveal existence of a command to write out tables (only rtables seem to be allowed in FileTools:-Write). You may be able to mock something up in a Matrix with datatype-anything and use ExportMatrix.

If it is a simple data sructure with not many parameters, you can consider making a Vector of the values and just use ExportVector and ImportVector and keep track of the names by hand.

Mac Dude

Hi Voltageist,

Please reflect a little on what you want help with. We can guess, but it actually helps you to formulate your problem in a comprehensible way.

So, you know how to plot f(x). Good. Now what is x1? A value for x? Then your question makes little sense. A value for f(x)? How are we supposed to know (other than inferring it from your throwing a reference to Newton's method in there)??

What do you mean by "plotting Newton's method"? Plot the iterations (i.e. the sequence of x,f(x) pairs that approach the wanted value of f(x))? Or plot the result of Newton's for a range of x1=f(x)?

Do you see the issue here?

We are willing to help. But not everyone has the time to formulate the poblem you need help with for you.



The answer to your first question is:

f:=x -> x^3;

The first line is the way to declare a function in Maple. The 2nd line shows how to plot it.

You will need to read the manual: Maple comes with some manuals; you can download these from Maplesoft if you did not get them.

Google Maple introduction or something like that. there is quite a bit of info on the Web.

There is also Edgardo Cheb-Terrab's mini course. Although written with physicists in mind, it'll get you going fast if you are willing to spend the time working through it.

Mac Dude

eval(diff(f(x), x$2),x=5);

This gives you something messy; you can simplify it, and then evalf(...) to get a number (a float in Maple lingo).

It is latest at this point that you realize something is wrong. In your equation you use e^(...). This likely does not what you want. If you want the exponential function, use exp(...). e is not 2.81828... for Maple, just a name.


In Maple, a function is defined like trhis:

f:=(x) -> (x^(12)-x*sin(x^(11)))/(x^(34))+e^(sqrt(x+4))*ln(abs((cos^(5)x)-6));

RTFM, this one is documented.

Also: cos^(5)x is not a valid expression; you want cos(x)^5 (cos(x) to the 5th power) or cos(x^5) (cosine of the 5th power of x). Don't use implicut multiplication (like 5x); endless confusion will result.


Mac Dude.

Ok, first, get rid of the square brackets. In Maple, these define a list. You do not have a list here.

Second, I suggest you use 1-d input when you actually do work in Maple (as opposed to typesetting something). As it is; your worksheet appears to use theta as well as theta(t). I am not quite certain whether 2-d input keeps track of the arguments (i.e. always takes theta as theta(t)) but I suspect it is not. At any rate, it is confusing.

Redefining sin(theta) and/or cos(theta) the way you do it does not seem to me the way to go. In particular it may mess up your differentials sin(diff(theta(t),t)) Instead, I would do what the small angle approximation in reality is: work with the first-order approximation. Maple has the handy series command for that: e.g.


and if you wrap it in a convert statement you get a normal polynomial expression:



Now you do have another problem in that series will not work on functions. To make this work you can use freeze/thaw. In brief, if you substitute an expression with freeze(expression) it will take it as atomic but keep track of what it is so when you thaw later on it'll put the original back in.

Your calculation then becomes the following:


thdoubledot:=solve(de,[diff(theta(t),t,t)])[][]; # the two [][] get rid of the list-creating brackets


where the last two should be in one execution group to avoid problems with the % operator.

In this way you are still left with the sine and cosine of diff(theta(t),t). It is up to you to decide whether you can linearize that or not, and what the corrrect way to do this linearization is (correct for your problem, not for Maple).

So, it is a bit messier than one would like, but along these lines you should be able to get where you need to go. Maybe someone else knows a better way??

Mac Dude.

Edit: Fixed two typos.

Here is what I'd do:

V1 := [1/9, -5/9, 7/9, 1/9, -5/9, 7/9, 1/9, -5/9, 7/9];

V2:=t*~V1; # the ~ makes the multiplication elementwise

int~([seq(V2[i],i=1..9)],t=0..1); # need to make a list as a sequence cannot be argument to int. ~ distributes int across the elements of the list

The results are:

                    [1  -5  7  1  -5  7  1  -5  7]
              V1 := [-, --, -, -, --, -, -, --, -]
                    [9  9   9  9  9   9  9  9   9]
         [1      5    7    1      5    7    1      5    7  ]
   V2 := [- t, - - t, - t, - t, - - t, - t, - t, - - t, - t]
         [9      9    9    9      9    9    9      9    9  ]
              [1   -5  7   1   -5  7   1   -5  7 ]
              [--, --, --, --, --, --, --, --, --]
              [18  18  18  18  18  18  18  18  18]

Come to think of it, why even go through the hassle of making a seq of vector elements: int~ should work on V2. Left as an exercise for the student.


I am not quite sure whether this is what you were looking for, but there it is.

Mac Dude.


I have had the same issue and resolved to writing a proc that would check for the file's existence and ask the user for the directory if it does not see it. currentdir is maintained across restarts so once it has the correct folder you no longer get asked.

Also; if you launch a worksheet by double-clicking, currentdir may point to its directory.

Code follows and is als uploaded. Note that I use ImportMatrix and also futz around with the data types; you can simplify that part.


#---------------- Read Procedure
Read:=proc(filename,separator::string:=" ",format::string:="float")
description "Emulates read() & sets currentdir if needed";
local test,F1,data;

if (not test) then # have to get and set currentdir
F1:=Maplets:-Display(Maplets:-Elements:-Maplet(Maplets:-Elements:-FileDialog[F1]('fileselectionmode'='directoriesonly',title = "Select Folder",approvecaption = "Select",onapprove=Maplets:-Elements:-Shutdown(['F1']))));

  if (F1[1] <> "") then currentdir(F1[1]);
  else return "FAIL";
  end if;

end if;

if (FileTools[Exists](filename)) then

  if (format = "float") then
  elif (format = "anything") then
  elif (format = "string") then
  end if;

 # D1:=Maplets[Display](Maplet(AlertDialog(cat("File ",filename," not found"),oncancel=Shutdown("FAIL"))));
end if;

return data;
end proc; # Read


Uploaded file:

If you want a graphics file (png or gif or...) select the plot and use the Export item on the Plot menu.

If you want to programmatically plot to a file you need to change the plot device.

I do not know how to save the Maple PLOT structure.

Mac Dude.

The universal Matrix constructor is


with too many options to go through here: rtfm.

A shortcut is <<...>|<...>|<...>|...>, which assembles a Matrix using the column Vectors <...> (comma-separated sequence enclosed in <>).


Maple will do symbolic operations with Matrices just fine. The . (dot) performs the matrix product.

The LinearAlgebra package has all the operations you need. Note that each element can be a complex number.

Read up on this in Maple's help or in the various user guides. Come back here for specific questions.

Mac Dude.

It depends on what file type you have. I have been able to open .mws files directly by dropping them onto Maple. I have been able to open .MS files by renaming them to .mws and then Open... from within the Maple GUI.

It may make sense to inspect the files with Emacs or some other editor that can deal with part-binary files. If you cannot open them in Maple, maybe that allows you to extract what you need and copy-paste or read() into Maple.

Mac Dude.



First 12 13 14 15 16 17 18 Page 14 of 20