Mac Dude

1536 Reputation

17 Badges

11 years, 99 days

MaplePrimes Activity

These are answers submitted by Mac Dude

There are two ways I would consider:

You can evaluate the Riemann sums directly given that you have the data in tabular form. You can get "fancy" by calculating the lower and the upper sums and take the average. This is quite possibly the most efficient way to do this. You don't need evenly spaced data for this, just keep track of the widths of the stripes whose areas you are tallying up.

You can also use an interpolating function of whatever degree and form required and throw that at one of the numeric integrators in Maple. The CurveFitting package has interpolation routines although I am not quite sure they work in a direct way for your purpose as you need to end up with a functional form of the interpolating function. You can of course always roll your own interpolating function (not difficult for linear interpolation). This may work better if you have many data sets with different ranges, number of points etc.

Mac Dude

In the absence of any detail I'd suggest you look at the Array and Matrix commands and see whether they fit the bill. Note that larger objects of this kind may not be displayed inline, to override that use interface(rtablesize=...);

Mac Dude.

If a1(x) involves numeric integration: you can specify the # of digits in the Int() statement. In my expereience the savings are quite minimal, however. You can also specify an accuracy epsilon (which also gets changed when you change digits). RTFM.

Globally you can change Digits to control Maple's accuuracy. Maybe it helps reducing that, although I doubt it does unless you have set Digits to a large number thus preventing the use of fpp hardware.

Could a1(x) be compiled?

Mac Dude

I believe the plot command tries to eval test(s), which does not work since evalf is a numeric routine (if you do it directly you get your error message also). Just for kicks I tried figuring this out & ended up with the following, rather ugly, construct:

test:=s->fsolve(t^3=s,t); #    % Simplified implicit expression for illustration.    

This achieves the objective which is to plot test(xx). Note the problem I ran into with seq: it prepends two elements valued 0. to the list of results; the [3..] gets rid of these. Why does seq do that? Beats me. But it does. (This was done on Maple 15.)

Not a nice solution, but maybe it gets you over the hump... Maybe someone more experienced in Maple has a better solution?

Mac Dude

Edit: Carls answer showed up while I was typing & trying to coerce Maple to plot this. He got it right.

Assuming your first "=" is a typo & meant to be "+", I can do this in Maple 15:



The result looks messy but in fact has the right structure: one real root and a complex-conjugate pair.

Mac Dude


Making a Package is relatively easy. To summarize what you have seen already in the other answers:

Wrap your procedures in a module()...end module; construct:

description "What it is for";
export ...; # the procs of variables you want to access
local ...; # local variables

option package;# this makes it a package

(your procs)

end module;

All of the above is within one execution group.
You then need to save it as a .mla library, I do it like this:


where I have pre-pended my own library directory to the libname list in my .mapleinit file.

I keep the Maple workbook separate so whenever I need to update one of my libraries I just open the worksheet; make the changes and execute the thing which saves it where I want it.

Occasionally you need to compress your library to clean out older versions. I have forgotten how to do that but help on LibraryTools will tell you.


Mac Dude

With a relatively small file like this I'd just go ahead and do it manually. If you use a good editor like Emacs you can speed up some of the conversions (like batch-converting the "=" to ":=" and changing the array indexing from () to []). For some of the MatLab functions (like zeros) you could write small Maple procedures doing the equivalent Maple calls (in this case I'd probably use Vector()). For the data file read I would look into ImportMatrix.

It is worth spending some time thinking about more structural issues. First, you probably want to declare your Vectors with datatype=float. Second, Maple has constructs like seq that may be more efficient than do loops.

Finally, be aware that Maple does symbolic algebra. I have gotten tripped up with numerical work in Maple when Maple merrily tried to maintain ever growing expressions. Strategically placed "evalf" statements can help preventing this. One sign of this happening is superlinear growth of running time with the number of cycles in a do loop when the loop itself should take linear evaluation time.

Finally; Maple evaluates 10 digits by default. You may want to increase that to 15 to match what MatLab is likely doing.

Overall your code looks fairly straightforward so I would not expect too much trouble. Do make sure you have a good test case to compare, though.

Mac Dude

How about cat:


where i is your serial number. The result of cat has the type of the first object to be concatenated, i.e. a string in this example. This is what you want. If for some reason it is not a string you may need to use convert on the whole thing.

The nested cats are clumsy but I have not found a way yet to avoid them (without rewriting cat) as cat only accepts 2 arguments.

Mac Dude.

I do not pretend to understand what you want to do; but in the upper part of your post you are trying to differentiate by sin(t) (which is assigned to h). That you cannot do. If what you want is applying the chain rule [d/dx(f(g(x))] you can do that explicily. If you really want to differentiate by h; you need to either get rid of the assignment h:=sin(t) (and restart; before you run the code again) or you need to use unevaluation quotes ('...') around h in the diff statement. since each quote pair gets stripped after one assignment you may need more that one pair of unevaluation quotes around h. Once you have the differentiated expression (lets call it xpr) you can then e.g. subs(h=sin(t),xpr)

Mac Dude


Typically, this would be the transpose, then. LinearAlgebra:-Transpose(Matrix) should do the trick.

Mac Dude

Why not try simplify(subs(...)) instead of subs(...,simplify()). It may avoid problems like the one Carl Love describes.

Mac Dude

To find "the" function, you need to have more context or constraints. As you can see from previous anwers there are many solutions to your problem if all one has to go by is what you wrote. I personally might be tempted to Fourier-analyze your series & find the spectrum & express your series as a sum of sines & cosines.

Mac Dude

It seems like that. I tried the same here (Maple 15) & I see exactly what you see when using the cursor.

I assume that a simple copy/paste does not give you sufficient quality...? (you can actually select multiple plots in an array).

I'd probably write a little function to change the plotdevice (with plotsetup) to a file; display the array; & go back to inline plotting. Should not be too hard (says he, who has not actually done so!).

Mac Dude

One way to make this work in other Maple worksheets would be to save the definition of m5 in a library file. Then you can include it in other sheets using with(library_file);.LibTools has the routines you need to create libraries. I use something like this:


where "MathPad" is a module defined before the call to LibTools:-Save (so "m5" in your case) and "MathPad.mla" is the library the module gets save into (you chose your own name). The cat with libname[1] is to get to the right directory (which happens to be in libname[1] for me).

I find that for rarely used simple routines good old copy-paste works just as well.

You can also save a whole Maple sheet as Maplet, but that gets you one specific maplet application that a user interacts with.

Mac Dude

because in Maple e^x is written as exp(x).

Mac Dude

First 16 17 18 19 20 Page 18 of 20