Question

What am I doing wrong in this code?

atvalue(y(x),[x=0],1)$
desolve(diff(y(x),x)=y(x),y(x));
plot2d(y(x),[x,-6,6]);

Output:

plot2d: expression evaluates to non-numeric value everywhere in plotting range.
plot2d: nothing to plot
false

I want to plot y(x) which is obtained from a differential equation.

Was it helpful?

Solution

In Maxima y(x) = ... is an equation, and y(x) := ... is a function, and those two things are different. Try this:

atvalue (y(x), [x=0], 1)$
desolve (diff(y(x),x)=y(x), y(x));
define (y(x), rhs(%));
plot2d (y(x), [x, -6, 6]);

Here define(y(x), ...) is a different way to define a function. define evaluates the function body rhs(%) to yield exp(x) but := quotes it (not what you want).

OTHER TIPS

The reason is that the result you see after the desolve does not mean y is defined as a function of x; in fact you obtain the same error if you change y(x) with f(x) (or any other unknown function) in plot2d. See the difference:

(%i9) atvalue(y(x),[x=0],1)$

(%i10) desolve(diff(y(x),x)=y(x),y(x));
                                           x
(%o10)                            y(x) = %e
(%i11) y(x);
(%o11)                               y(x)
(%i12) y(x):=%e^x;
                                            x
(%o12)                            y(x) := %e
(%i13) y(x);
                                        x
(%o13)                                %e

I don't know if there's a way to “transform” the equation (the result) into a function definition automatically. If I find a way, I will complete the answer.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top