Mac Dude

982 Reputation

13 Badges

5 years, 294 days

MaplePrimes Activity

These are replies submitted by Mac Dude

@Ronan Here is a minimum working example how to read a proc into a module:


restart; # the message is from my own .mapleinit file
                "Maple Initialization loaded..."
test(); # not defined  so just returns unevaluated
  export test;

     read("test.mpl"); # This reads (and executes!) test.mpl
end module;

test(); # now it is defined
                        "this is a test"


test.mpl looks like this:

  print("this is a test");
end proc;

As for using an external editor, that is obviously your own call. Personally I use Emacs and Joe Riel's maplev.el package for Emacs. maplev mode does syntax coloring and code-indentation; Emacs allows to split a window; all very convenient features when coding. But then, I have known Emacs for a long time... But you can presumably also use Notepad on Windows.

I find editing in Maple and then writing the code out not very satisfactory. Small packages I just keep in the Maple environment & save directly to the .mla file (I call that "compile it" although nothing of that sort is going on), keeping the .mw file in case I want to make changes whereas large ones I do in Emacs.

I am surprised about the mess with the directory separators in Windows. Maple used to deal quite well with the old ":" separator in Max OS 9 and earlier so it certainly knows how to handle different separators. Maybe it is just a bug? I don't do Windows so I don't know.



@Preben Alsholm Thanks much for the investigation & explanation & SCR, thus sparing me the effort of doing it. I do wonder how many people are using these constants... maybe not so many. But be that as it may, if it is in Maple, it should be correct so hopefully they fix it with 2017.3. It should not be a difficult fix.


@Ronan Your problem with the dot is simply syntax: you need to specify filenames as strings i.e. use double quotes (").

I am uploding a Maple worksheet showing how you can save and read your function Antisym, and also how you can wrap it into a module (RatTrig), declare it a package, save it as a .mla file, and then use Antisym as as a member of the RatTrig package. You need to declare the function as export to be able to use it. You can have many procedures and even, as John Fredsted suggests, have modules within modules to get a hierarchy of functions, although I do suggest starting somewhat simple until you get the hang of it. If you want to delve deeper get the Maple Programming Guide (from Maplesoft's documentation area), it is invaluable if you want to do more programming in Maple.

Note that this sheet uses my own defaults esp. for libname so you need to adapt it before use. I set libname in my .mapleinit file.

And I use Mac OS X. It looks like you use Windows so your file specs look different, esp. you need the backslash instead of slash as directory separator.


@tomleslie With MathType it works, I do this often, although usually into Ppt.

In Word, select "Insert MathType Equation" (which you will be able to do with MathType installed correctly).

An empty MathType wondow opens.

In Maple, select your equation & "Copy as MathML"

Paste into MathType.

There are some issues with this: First, Maple variables & such appear in blue. Looks kind-of pretty but usually unwanted. Trivial to fix in MathType. More annoying is that everysooften I get Greek letters as something approaching ML markup: β or similar where a Greek beta should be. So I have to select & paste the correct character by hand. Not nice.

At least the general layout is preserved.

There are instructions on the DesignScience website. Also, I found their cust. service to be quite responsive.



Doing as you propose would have far-reaching consequences.

E.g., often one takes sin(x)=x to first order. This would lead to confusion if sin would take degrees as argument. Also, the radian has unit [1]; if you are doing dimensional analysis then the degrees obfuscate the issue significantly, to say nothing about Taylor series.

While I am sympathetic to the plight of students; if they do math sophisticated enough that Maple is a viable tool, either as a teaching tool or to be used in analysing math problems, then they should be taught to grasp the idea of radians. In the end, learning that a right angle is Pi/2 vs 90 deg is maybe not that big a deal.

I grew up with degrees. This did not make my life in physics easier. On the plus side, becoming bilingual with units (as in degF vs degC, inches vs metric, and rad vs degrees) is actually quite a useful skill.


@vv Slick! I love it.


@Rouben Rostamian  Let's see... assume t counts the iterations.

Then the first equation calculates y[t+2] as a function of y[t+1] and x[t].

The second one calculates x[t+2] as function of x[t] and y[t+1]...??

Turns out when you play this through you can's do the next iteration as x[1] never gets calculated. You can chose x[1] of course also, but then this becomes a rather weird system. It seems to need an internal state to work.


I am also hopelessly confused by the OP's writing of the function e(x). It seems it is being redefined as E(x)..?? and e is declared global... a mess.

To the OP: First, make sure your map equations are written correctly. The way you have them does not look right.

Then you need to write the procedure that gets handed to DataPlot as Map. Obviously z refers to either a two-element Vector or to a complex number, so the mapping functions have to be rewritten accordingly. There is probably someone here who can help with that, but with the way the mapping equations are written it seems not right. If this is really to be something like a phase-space plot for a dynamic system then Map should only depend no x[t] and y[t].

Then: Rewrite your e(x) function so it can be understood. DON'T USE GLOBALS!! The only global for which there is justification would be N as it is basically a constant. Anything else needs to be an argument if really necessary. And what is this business of e and E (which are declared as globals in some functions)??




@nm you are absolutely correct; this issue will occur when there are Maple-generated symbols involved. As I said; I haven't run into this, but I do see your point and it is a valid one.



You are not telling us what u is. But in the call to NonlinearFit you enclose u in square brackets which makes it a list; that seems fishy. For NonlinearFit to work, the function has to evaluate to values that can be compared to the dependent values of your data set (i.e. veloc in your case). If these are anything else than simple numbers I don't know whether NonlinearFit will work; you may need to use one of the other optimization routines and build your "penalty function" (i.e. the sum of the squares of the differences) yourself.

You also don't give us your data set so we cannot try this ourselves.




@optoabhi Attachment? Also, read the addition I just edited into my answer.



@leafgreen Actually, it is the other way around. First there were indices. Printing them as subscripts is actually quite a natural way and how it is often done in paper-pencil math. But sometimes people want to use a subscript that is not an index. Maple only fairly recently addressed that typesetting desire by introducing the double underscore. Since a single underscore is a valid character in a name they pretty much could not use a single underscore for that, lest they would break tons of extant code. Double-underscored names are what Maple calls atomic, meaning these are just names as any other one.

The reason your original function definition fails actually makes a lot of sense: a parameter to a function is either a Vector (say) or a scalar. For a scalar argument the indexing makes little sense; it only would acquire an index by being called in that way. So you can call your parameters x1, x2 etc. without any loss. When you call the function you can say f(x[1],x[2],...). and get it pretty-printed nicely. Or you define the arglist in terms of x and y and use x[1], x[2] etc. in the formula; that works also.

BTW, do not use a name as both indexed name (x[1]) and non-indexed name (x). Confusion will arise as Maple will treat x as a table & x[1] as an entry.

Maple has weirdnesses. This is not one of them. It is quite logical, dear Watson.


@DSkoog Thanks much again. You are right, Install has an option where, which can be either the users homedir or the Maple installation directory. Feels slightly restrictive but is ok for my purposes. I actually now agree with your recommendation about the location for the libraries except that historically I have put them into Maple's installation directory for a long time so I'd need to move stuff... maybe I am too lazy to do this... it is actually not so difficult since I set libname anyway... oh, well.

So, now I need Maple2017.2 with the page-break issue fixed. Until then I cannot really upload my package to MapleCloud since I don't want to carry around two different users guides, one with & one without the page breaks. Think that will actually happen?

Anyway, thanks much, I have learned a few things.


@DSkoog Ok, so I was able to create a Lattice.maple file by omitting the Users Guide and removing the continuation characters from the PackageTools:-Create command. Putting that into a directory known in libname indeed allows with() to work. Good. (I realize now that I did not check the help files...).

From what you wrote it appears that PackageTools:-Install creates a new, hard-wired directory structure in my home directory (maple/toolbox/...). What if I want this to be somewhere else? What is this guy "%USERFOLDER%"? Can I set this to some folder I chose? I am familiar with the kernelopts() directories and with currentdir() and libname; but this is a new one for me.



@dharr Hmm... thanks much for finding this out.

The page breaks I have in the file are there for reason of structuring the document esp. when printed to a pdf and looked at in this way, and I am not really interested in removing them. I don't know what a "child page break" is supposed to be; but this will prevent me from creating a workbook of Lattice. It is actually a real issue: Maple has the unique ability to allow typesetting text; adding things like page breaks and line breaks etc. are a fairly fundamental part of it. For our accelerator physics course I practically wrote a book in Maple. If workbooks do not support this it mars the concept.

And I cannot even fathom why the workbook even cares about these.

Anyway, needs to get fixed pronto. SCR incoming.



@nm if the fopen() call fails, Maple stops unless you catch the error using try...catch. If it does not stop, the fopen was successfull & you can rely on the filehandle being valid.

Does not seem to be that bad to me. If you want to get fancy, try...catch allows you to parse the error message & catch only specific errors, so you can take specific actions. E.g. if you try to fopen an already open file, fopen will fail as well (per the help page) and you can catch that. Although I have had trouble with this mechanism & gave up on being fancy.

High-level, but in my view not so bad. Incidentally, I do not fund the help page that bad. It explains all this pretty much.


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