Ask Your Question

Ploting ODE (unable to simplify to float approximation)

asked 2018-06-03 20:53:10 +0100

Marsupilamie gravatar image

I wanted to to draw the slope field aswell as the solution for my ODE. When I try to plot the solution i get a warning and an error.

verbose 0 (3749:, generate_plot_points) WARNING: When plotting, failed to evaluate function at 200 points.
verbose 0 (3749:, generate_plot_points) Last error message: 'unable to simplify to float approximation'

My Code:

y = function('y')(x)
a,b,c,d=var('a b c d')
de =  diff(y,x) == (a*x+b*y)/(c*x+d*y)

h = desolve(de, y, ivar=x);  

y = var('y')
x = var('x')


edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2018-06-04 08:43:23 +0100

Sébastien gravatar image

updated 2018-06-04 08:47:18 +0100

First you should avoid using y for two different things. When y = function('y')(x) gets evaluated and not y = var('y'), then you get the error you describe:

sage: y = function('y')(x)
sage: a=1
sage: b=0
sage: c=0
sage: d=1
sage: A = ((a*x+b*y)/(c*x+d*y))
sage: A
sage: A.subs(x=1)
sage: float(A.subs(x=1))
Traceback (most recent call last):
TypeError: unable to simplify to float approximation

The problem is really that Plot2 is empty. Why? You are trying to plot a function that is defined implicitely:

sage: h
1/2*y(x)^2 == 1/2*x^2
sage: h.subs(x=10)
1/2*y(10)^2 == 50

Either, you define the function y(x) explicitely and you can use plot or you can try implicit_plot (look at the examples online). But in both cases, I do no know whether you may use y=function('y')(x).

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2018-06-03 20:53:10 +0100

Seen: 523 times

Last updated: Jun 04 '18