Question

I would like to plot a function several times for different values of parameters.

The function depends on a set of parameters, say paramOne and paramTwo. I would like to be able to specify several sets of those parameters, and for each set, get the function graphed.

I do not want the number of parameter sets to be hard-coded, so I thought about using a for ... in ... do loop. This is what I tried, but it doesn't seem to work:

parametersList: [
    [paramOne=valueOne, paramTwo=valueTwo],
    [paramOne=valueThree, paramTwo=valueFour],
    ]$
for parameterSet in parametersList do
    block(
       i++,
       functionList[i] : ev(function(x,paramOne,paramTwo),parameterSet),
       return functionList
       )
 wxplot2d(functionList,[x,0,1])$

Any suggestions?

Was it helpful?

Solution

I got a working answer from Maxima mailing list, I thought I would post it here. (Thanks to Jaime for the answer!)

For one function:

f(x,A,w) := A*sin(w*x)$
parametersList: [ [p1=1, p2=2], [p1=3, p2=4] ]$
functionList: makelist( ev(f(x,p1,p2), p), p, parametersList);
plot2d( functionList, [x, 0, 7]);

For several functions, each to be plotted with a different set of parameters:

f(x,A,w) := A*sin(w*x)$
g(x,A,w) := A*cos(w*x)$
parametersList: [ [p1=1, p2=2], [p1=3, p2=4] ]$
functionList: makelist( ev([f(x,p1,p2),g(x,p1,p2)], p), p, parametersList);
/* functionList looks like : [[f1,g1], [f2,g2],...]  */
/* Use flatten() to get : [f1,g1,f2,g2,...] */
plot2d( flatten(flist), [x, 0, 7]);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top