Plotting the solution returned by desolve

32 views
Skip to first unread message

Gaurish Telang

unread,
Nov 14, 2022, 9:47:27 AM11/14/22
to sage-support
I want to plot the solution of my differential equation. However, the solution returned by `desolve` is in implicit form (as should be expected, the docs say most solution returned are like that) 

Here is my current broken code. 

```
x = var ('x')
y = function ('y')(x)
sol = desolve(diff(y,x)==(x*y^2 - cos (x) * sin (x) )/(y*(1 - x^2)) ,y, [0 ,2])
# display(sol)  # <--- for displaying solution in jupyter notebook

s,t = var('s t')
p = implicit_plot (sol==0 ,( s,-5,5),(t,-5,5), gridlines='major' )
show(p)
```

The output being returned is a blue square.Clearly there I am doing something wrong 
in the way I am using sol to implicit plot. What can I do to fix it? 

Regards
Gaurish

Emmanuel Charpentier

unread,
Nov 15, 2022, 2:38:24 PM11/15/22
to sage-support

Try this :

sage: var("x, t") ## t will be used later
(x, t)
sage: y=function("y") ## Note : no default argument
sage: sol=desolve(diff(y(x),x)==(x*y(x)^2 - cos(x)*sin(x) )/(y(x)*(1 - x^2)) ,y(x), ics=[0, 2]) ; sol  ## Note : specify y argument
1/2*(x^2 - 1)*y(x)^2 + 1/2*cos(x)^2 == (-3/2)
sage: implicit_plot((sol.lhs()-sol.rhs()).subs(y(x)==t), (x, -5, 5), (t, -5, 5)) ## Substitute a variable to the expression...
Launched png viewer for Graphics object consisting of 1 graphics primitive

tmp_y92wys2o.png

HTH,

Reply all
Reply to author
Forward
0 new messages