Search code examples
plotmaxima

Plot functions with different domains in Maxima


What is the best way of plotting several functions with different domains into the same plot? Is there a way to do this with plot2d, or do I have to use draw2d instead?

I especially like the possibility in plot2d to give several functions in a list, whereas I would have to add the different functions in draw2d as separate parameters, if I understand the documentation correctly.

An example of what I mean:

f(x, a) := sqrt(a) * exp(-(x-a)^2);
fmax(x) := sqrt(x);

In this example I would like to plot f(x, a) for several a (e.g. using makelist(f(x, a), a, [0, 0.5, 1, 2, 5])) from -1 to 10 and fmax from 0 to 5 (to show where the maxima of the f(x, a) family of curves are located).


Solution

  • You can try draw2d

    f(x, a) := sqrt(a) * exp(-(x-a)^2);
    fmax(x) := sqrt(x);
    
    flist: makelist(f(x, a), a, [0, 0.5, 1, 2, 5]);
    
    par: map(lambda([f], explicit(f, x, -1, 10)), flist);
    par: append([explicit(fmax, x, 0, 5), color=red], par);
    
    load(draw);
    apply(draw2d, par);