165 Reputation

8 Badges

8 years, 318 days

MaplePrimes Activity

These are answers submitted by AmusingYeti

The Optimisation package:

Or Global Optimisation Toolbox:

are what you need to get started. When you say "solve" I assume with constraints as the nurse scheduling problem is NP-hard. As with any other language/tool if you can program it then it can be "solved".



You can use the read command to accomplish this. It is important to export the file you want to read from as a Maple input file, .mpl file and not a Maple worksheet, .mw file.

read "File_with_functions_in.mpl":



Debugging code is a vast topic, but when it comes to Maple there are three methods I regularly use to debug code.

1) Read error message/documentation

1) Page breaks

2) The print() function


Sometimes the error message that flags up is understandable and can often be identified as a missing :, ), = etc... or perhaps my understanding of Maple sytnax was not complete in that area. I turn to the online documentation/MaplePrimes to help me overcome the error.


If however, the error message is a little more cryptic, then page breaks can be of great assistance. Page breaks are useful for debugging longer Maple code and are not as applicable to just a few lines of Maple. Say you have a 1000 line Maple code and it crashes with an error which is not immediately identifiable, where did the error originate? Place a page break at line 100 and run the first 100 lines. If that runs smoothly then move the page break down to line 200 and run the program. keep doing this and you will quickly be able to isolate the portion of code where it originates from, or be able to trace it back to a point earlier in the code


I often use the print() function as it allows for quick testing of procedures/loops to make sure they are functioning correctly by seeing if a test message makes it to the screen or if it is skipped due to the loop condition not being met.


From my knowledge, Maple does not have an easy way to "comment" out large portions of code for testing, which I find a useful feature in other languages such as Python and C++. A quick and easy way to bypass this is to set up an impossible to meet 'if' statement:

if 1 = 2 then
  ...Hundreds of lines of code that I want to ignore for now...


This is an effective means of disabling blocks of code without removing them or modifying loop statements.

These are just a few crude ideas I use to test and debug troublesome Maple code.


The following options simplify these expressions:

simplify(...,size): or simplify(...,trig):

As an example of the size option:


Expr:= 416*(1-tanh(rho*y)^2)^2*tanh(rho*y)^3-272*(1-tanh(rho*y)^2)^3*tanh(rho*y)-32*tanh(rho*y)^5*(1-tanh(rho*y)^2); 

simplify(Expr, size);

And an example of the trig option:


Expr := 416*(1-tanh(rho*y)^2)^2*tanh(rho*y)^3-272*(1-tanh(rho*y)^2)^3*tanh(rho*y)-32*tanh(rho*y)^5*(1-tanh(rho*y)^2); 

simplify(Expr, trig);


- Yeti

Your question is not that clear but I assume you want to integrate the Planck law numerically and compare against the analytical result for the luminosity?

Here is a very quick solution:


# Specify physical constants
T:=10: # Insert desired temperature value here

# Specify integrand

# Numerical integration

# Analytical form

# Compare numerical with analytical result

This highlights the general idea, but of course a more elegant means of handling the infinity in the numerical integration can be implemented without too much trouble.


To use specific (textbook) numerical integration techniques, the ApproximateInt command from Student[Calculus1] can be used if you don't want to write the procedure from scratch:

# Trapezoid rule
ApproximateInt(u,nu=5..1E13,partition=10000, method = trapezoid, output = plot);

# Simpson rule
ApproximateInt(u,nu=5..1E13,partition=10000, method = simpson, output = plot);

See attached the following worksheet.

More information on ApproximateInt:



Consider a very simple example:


## Analytical, two dimensional

## Numerical, two dimensional

The point of numerical integration is that sometimes an antiderivative of a function cannot be found in terms of elementary functions (hence why Maple will sometimes return the input without integration evaluation). This is not to say an antiderivative does not exist, just that Maple cannot find it. Sometimes turning to paper and pencil to rewrite the integration, transform etc... can make the integration easier and thus allow Maple to find a analytical solution.

Lets make the integrand more tricky:


## Analytical, two dimensional

## Numerical, two dimensional

int will yield no solution to this, however numerical integration gives us a result. I had these types of integral pop up in a problem I was solving once; and I believe I did find a analytical form using Bessel and Struve functions but it is not elementary. Using numerical integration in this instance was quick and easy.

The numerical integration help page contains a lot of useful information:



I am not overly familiar with the problem as not much detail has been given, but I assume you want the eigenvalues of the product of F with V^(-1)? The attached worksheet does this. The largest eigenvalue is the basic reproduction number of the model (all assuming your matrices are correct).


Try this:

sum(evalf((-1)^k/k^(1/2)), k = 2 .. infinity);




for p from 0.05 by 0.05 to 4 do


The bottom right memory usage meter gives information about the memory used at that point.

gc() will return memory to Maple's self-allocated pool, but will not free up memory for the operating system. This is also true of unnasign so I would think that the memory is being freed up to be passed back for reallocation by Maple. Using the meter in the bottom right (I think) will not highlight this.

If you wanted to free up memory for the operating system, restart needs to be used.


- Yeti

1. An example:

a = [10, 11, 12, 13, 14, 15] # List of elements

b = [a[i] for i in (0,3,3)] # (0,3,4) represent the elements you want to extract

Remember Python arrays start at index 0, unlike Maple's which start at 1.


2. There are probably many ways of achieving this one. Sympy may be best suited to this.




Callable checks if the argument is either:

  1. an instance of a class with a __call__ method or
  2. is of a type that has a non null tp_call (c struct) member which indicates callability otherwise (such as in functions, methods etc.)

It used to be depreciated but was reintroduced and I believe works on Python 2.x and Python 3.x.

./ is to run executables. mpl files are not executable files and need to be run by using just maple instead, i.e.

maple program_to_run.mpl

A useful way to deal with file reading when running things from the terminal is to input the file you want read in via the terminal window itself so you dont need to keep editing the maple file directly. e.g.

maple program_to_run.mpl file_to_read.txt

In your Maple script you could put the following as a placeholder for the filename you want to read in:

filename = "FILE"

You can then use the bash scripting language to automate everything very nicely. I link my .bashrc file to a directory containing a host of bash scripts for automating of nearly everything, including the running of Maple scripts. You could place this in a file and call it maple which points maple to use a particular version of Maple when called from the terminal:

#!/usr/bin/env bash
/Library/Frameworks/Maple.framework/Versions/18/bin/maple ${*} 2>&1 | grep --line-buffered -v "exclude an item from Time Machine"

This sets up the link to the correct Maple version you want to call when running your Maple script (mine is set to 18 in this instance). You can then link this to your .bashrc file and it can be called anywhere at anytime. You could append the following to your .bashrc file which will be able to locate the Maple file on startup of the terminal:

source ${HOME}/../directory_holding_the_above_maple_file/maple

To pipe your input file from the terminal into your Maple script, you could do something like this, which uses sed to insert the name and location of the file you want and replaces the placeholder text FILE which we set above. The advantage of this is that you don't need to keep moving input files around and can leave everything in place and have bash do the leg work. The ${1} is taking your filename you insert in the terminal and storing it as input_file

#!/usr/bin/env bash


mplfile=$(sed "s|FILE|${input_file}|g" "${HOME}/../directory_to_maple_file_you_want_to_read_in_the_file/maple_file.mpl")

There is a lot of scope for this stuff, and the stuff I wrote is just off the top of my head, but bash and Maple can work very well together indeed. There are a lot of useful resources out there to understand the bash scripting language which is incredibly useful to build bridges between all the codes you produce whever they be Maple, Python, C++ etc... bash allows data and code to be passed between these languages and for them to be able to "talk" to one another.

If your script outputs the data to a file, then it will go wherever it is specified. If you do not specify a location for the file to be created and written to, then it will be located in the same directory where the Maple script you are running is.

Running maple scripts from the terminal has one big advantage in that it is easy to kill the process by just using ctrl-c. Within the Maple gui it can sometimes be problematic to kill the code, especially when it goes into C mode; but the terminal bypasses this issue.


You are asking Maple to solve the equation with various parameters not defined. This RootOf placeholder is a convenient way of letting you know that there are multiple solutions of a particular form. As a and P have not been defined in your expression along with no bounds being placed on R, technically the equation has an infinite number of solutions depending on what value they hold. You can usually use the allvalues command to get Maple to print the possible solutions but that will not work in this instance due to the dimensionality of the problem.

Using the solve command in your instance is equivalent to using the isolate command and isolating R; hence it rearranges the expression for R; but is not going to output an infinity of solutions. As both sides of the equations are numerically unknown it is an intractable problem to actually solve it. If you know what values R can take then you can find solutions for those instances. e.g.:





This then tells us that when R=2, a has the following form:




See the script for a plot of S_i from t=0..1:

- Yeti

1 2 3 Page 1 of 3