Ask Your Question
0

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: plot.py, generate_plot_points) WARNING: When plotting, failed to evaluate function at 200 points.
verbose 0 (3749: plot.py, 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')
_C=var('_C')
a=1
b=0
c=0
d=1
de =  diff(y,x) == (a*x+b*y)/(c*x+d*y)

h = desolve(de, y, ivar=x);  
h=h.substitute(_C==0)
h

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

Plot1=plot_slope_field(((a*x+b*y)/(c*x+d*y)),(x,-10,10),(y,-10,10))
Plot2=plot(h,(x,0,5))

Plot1+Plot2
edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

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
x/y(x)
sage: A.subs(x=1)
1/y(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

Stats

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

Seen: 595 times

Last updated: Jun 04 '18