Mac Dude

1561 Reputation

17 Badges

12 years, 238 days

MaplePrimes Activity

These are answers submitted by Mac Dude

If you look for goodness of fit in the statistical sense you need to apply the Chi-square test.
Your criterion then is to find the function with the minimal value of Chisq/(degrees of freedom) where (degrees of freedom) is the number of data points (17 in your case) minus (number of fitted variables+1). If you have values for the uncertainties you would expect Chisq to approach 1 for a good fit. Since you do not, you do not know what the minimum Chisq will be.

Check out help on [Student][Statistics][ChiSquareGoodnessOfFitTest] to figure out how to do this in Maple. It is not that difficult to do, but the fit command does not directly give you the answer. It does give you the residuals from which you can compute Chisq.

Practically speaking you probably observed that setting n to 4 you get a decent fit, but you have only 1 degree of freedom left (1 5 parameters vs 17 data points). This is why the fit complains about the model not being of full rank and it is likely that you "overfit". What it is telling you is that you have too many parameters (and with enough parameters any function can fit pretty much any data set).


I see the same problem as you see, in Maple 2015. Exporting to png or to pdf works fine, however, so the solution is to use a format that works and then convert to eps using a graphics program or GhostScript.


You can set Digits to a larger value (the default is 10) for increased precision. In my setup with Digits:=15, your code gives:

and the residual is

Do note that a numeric method like fsolve will in general not give a zero residual unless you use guard digits during evaluation & then round them away.

Needless to say, your example is better solved analytically.


Rather than trying to trick Maple into letting it writee your package into the installation, I strongly suggest you setup your own directory for your Maple packages. Then pre-pend that path into the libname list, which you do in the startup file (.mapleinit on OS X/Linux; I thin Maple.ini on Windows, always in your home directory) and put your package there using e.g. this construct:

libname; # just to list what is there
   "/Applications/Math_Calc/Maple 2015/My_Maple_Libraries",

LibraryTools:-Save(Filters,cat(libname[1],"/Filters.mla")); # the actual save

As an additional benefit, Maple version upgrades won't clobber your packages.


IntSect appears to be a table. To make a true copy of it you need to use the copy() function:


then IntsectCopy should be a true copy. Else you really only copy the pointer to the data structure, i.e. your IntSect and IntSectRoll are really the same objects, just accessible through two different pointers.


Mac Dude

Edit: Ninja'd by tomleslie... :-)


It appears that your proc evaluates R prematurely, in the definition phase for QuotientField. This is happening in the use construct.

One work-around is to avoid use and just enter the operators that are members of R, e.g. like this:

Doing this the error goes away. I cannot tell whether your program works as intended after that (I get a warning obout 'print/pair' form the last module) but at least the immediate problem is no longer present.

Some other hints:

Writing modules like this is quite inconvenient in 2-d input as there are too may type-setting idiosyncrasies in Maple's 2-d input. I highly suggest you convert this to normal 1-d input. After all; what you are writing is essentially a package of code, to be used from a main routine. So I'd make a Maple package out of it and then load it using with(). Your type definitions should go into ModuleLoad(), else they don't actually execute (and I have found it necessary to call ModuleLoad explicitly in my modules for this to work right).

Any interactive worksheet needs to begin with a restart; line. If you do not; changes in your modules or procs may not properly take and you spin your wheels figuring out what is going wrong. The restart cleans out prior mess & gives you a reasonably clean slate for your next execution.


Mac Dude

I suggest checking out the autoexecute feature in Maple, which is a per-sheet construct.

Also, there is the .mapleinit file that gets executed upon each restart; this is a global construct.

And if you write packages, there is Moduleload() which gets executed upon loading of the package.

Seems to me we are pretty well covered here. Pesonally, I use .mapleinit and Moduleload but not the autoexecute sections.



First, add "option package" after the module declaration.

Then, save this as a ".mla" file in a directory in Maple's libname path; like this example:


Here "MathPad" is the name of the module and "MathPad.mla" the filename (they don't have to be identical although I usually keep them like that).

libname is Maple's list of files to look for when searching for packages. It is preset with Maple's package directory and your working directory; I prepend the directory with my own packages to it in the startup file. My libname looks like this:


Mac Dude

The diffidulty in the given DE is the sin(psi1(t)) that makes it nonlinear. taylor will not expand in terms of psi1(t). Freezing psi1(t) (or just substituting it with a variable) causes taylor to replace essentially 0 because the differential terms now become 0.

I found I had to replace sin(psi1(t)) and cos(psi1(t)) with sin(spsi1) and cos(spsi1) and then do the taylor expansion:


which is not very elegant.

There is however a problem with this: Until you know something about psi1(t) you do not know whether this linearization makes any sense. dsolve will solve the homogeneous linearized DE easily:

but it will also solve the original DE:

and one now sees that the initial conditions are relevant here in assessing whether this linearization is applicable.

So it isn't quite clear (to me) what you are trying to achieve here...


It has been like this since I started using Maple.

The work-around is to "Select all" (Cmd-a on macOS) and then hit the single-step button (!) to run the whole 2nd sheet.

I forget whether Maple will open a new worksheet when another one is running. You may need to open the 2n done first.



You can work around the first problem by initially asking for the expansion to 6th order. After that everything appears to work fine; even when the forget(series) statement is removed.

I am not sure about the 2nd issue. The series command makes little sense as it only expands the linear term (x)... what is the point? You are still left with a transcendental equation that has no analytic solution. Maple 2015 hangs on the 2nd try to solve ser for y. Maybe you want expansion by y??










The result is too messy to print here, see the worksheet. Do note that I is Maple's imaginary unit so I changed I to i.


It depends on the specifics of your data and what you are trying to achieve. Technically, your Fourier analysis constitutes the test of a hypothesis, the hypothesis being that your samples are taken from a distribution given by your function, the Fourier series. If x could never be negative for fundamental reasons then I'd argue both Fourier series are equally valid; your data cannot discriminate between the two. The catch is that it is hard to imagine a case where x is fundamentally positive and a Fourier series is a valid representation of what is going on. When frequency analysis is meaningful, the independent variable (x) usually is a location or a time variable that is unbound in either direction.

What you really should do is have a model of the underlying distribution, i.e. of the process that generated the data in the first place. If that is symmetric about 0 then you are in a good place and can use the symmetry.

If you need to known the spectral composition of the Fourier series then you need to tread carefully here. Your two series have a significantly different spectrum; if you do not have enough data to discriminate between the two you may not be able to determine the spectrum of the underlying distribution.


About the simplest way is to use the element-wise operations:

B:=sqrt~(1/~A); # note the tildes

More flexible is map(sqrt,A) which maps the sqrt function over all elements of A. RTFM for these. While map and ~ seem to be the same there are somewhat subtle differences, but for this simple case they should produce the same answer.

If the 0 elements in A bother you you can define a new  function

f:=x -> `if`(x>0,sqrt(1/x),0);

and use f~.

Mac Dude

Edit: Ninja'd by Rouben. I like Rouben's way of using an unnamed function...

It isn't quite clear what you want. If it is Maple code you want to compare then you can e.g. write the code out as a .mpl file (which is ASCII) and then either use diff on them (Linux or Mac OS X) or read these back into Maple and use one of the StringTools commands to compare.

The worksheets are xml files, so your comparison of these may yield differences in the xml code as opposed to real code differences.

RTFM on write, read and StringTools to figure out how to use these.

Mac Dude


2 3 4 5 6 7 8 Last Page 4 of 20