Mac Dude

1102 Reputation

13 Badges

7 years, 87 days

MaplePrimes Activity

These are answers submitted by Mac Dude

I believe what you are looking for the the error of the parameters. I ran into a imilar issue years ago and wrote a variance routine that does this to firt order. See the attached Mape worksheet. Read up on how to use the matrix in Statistics:-Linearfit.


You use phi in two ways: once as a scalar (phi) and once as an element of a table (phi[c]). Maple does not like that. If you aim for phi[c] is just to get a subscript in the output you can use phi__c (double underscore) in not-too-old versions of Maple, which remains a simple name (atomic) and avoids this confusion. You have other cases of using indexed names; they look ok but be aware that to Maple beta[k] is an element of table beta. If you assign a number to k then beta[k] becomes something different. The table in Maple is an associative array, so k or c in this case act as the keys.


Carl already commented on your statements.

I would like to add the suggestion for you to read and peruse the Maple Programming Guide that you can download from Maplesoft's website. It has in-depth descriptions and examples of programming with modules and procs; I found it indispensable when I got into programming with modules.

You ask about the difference between modules and procs. I would say a module is a bit like a class in object-oriented lingo. It has methods (procs) and properties (exports). Think of it as a container. A module does not get called and had no parameter list. The two uses of modules I encounter most often are for writing packages (module() option package; ...; end module;) and in the so-called "module factory", where a proc returns a module with its own procs and properties, thus allowing to create multiple instances of an object.

Maple modules are powerful and fascinating. But it took me a while to really understand how to use them; be prepared for a learning curve to climb.

Mac Dude

Your first piece of code is syntactically incorrect. f3 is in output format.

Fixing that, still no solution, because you don't have enough Digits. Increase Digits to 40 and you get a solution. Whether it is correct or not I cannot tell (n not being an integer makes me suspicious).


Maybe the trickiest part is the creation of A:

A:=Matrix(n,n,(i,j) -> piecewise(i=j,0,1));

as this is not well documented. Then it is smooth sailing using the LinearAlgebra package:




Read the docs for the LinearAlgebra package to understand how to use it.

One deficiency of Maple is that it does not deal with abstract matrices (or vectors, for that matter) of arbitrary dimension. I.e. n has to be defined, else the Matrix constructor throws an error. So you will need to write a loop or otherwise solve the problem explicitly for the 3 cases.


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.



1 2 3 4 5 6 7 Last Page 1 of 18