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).

有帮助吗?

解决方案

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);

其他提示

One approach I am not particularly happy with is to declare the functions with smaller domains as parametric curves, with the x axis parameter being simply x:

f(x, a) := sqrt(a) * exp(-(x-a)^2);
fmax(x) := sqrt(x);
plot2d(endcons([parametric, x, fmax(x), [x, 0, 5], [nticks, 80]],
               makelist(f(x, a), a, [0, 1/2, 1, 2, 5])),
       [x, -1, 10]);

This was frustrating me for hours but I found a way to have multiple differently domained functions on the same graph.

wxplot2d([if x < 0 then -x else sin(x), if x > -1 then x^2],[x,-%pi,%pi],[y,-2,2]);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top