ASKSAGE: Sage Q&A Forum - Latest question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 10 Sep 2014 12:45:59 -0500Weird problem with desolve_rk4http://ask.sagemath.org/question/24090/weird-problem-with-desolve_rk4/ Aloha,
I am trying to use desolve_rk4 to solve differential equations of the form dy/dx=f(x,y). As we can see in the [Solving ordinary differential equations](http://www.sagemath.org/doc/reference/calculus/sage/calculus/desolvers.html) help page, it has two variants in one you just pass f(x,y) and in the other you pass the whole equation dy/dx=f(x,y). It should not make a difference. But in the following examples one can see that one works sometimes and the other doesn't, and vice-versa.
This works ("Variant 2": passing just f(x,y)):
x,y=var('x y')
f=x^2+y^2-1
ICS=[0,0]
STEP=0.01
END=2
plot1=desolve_rk4(x^2+y^2-1,y,ics=ICS,ivar=x,output='slope_field',end_points=END,thickness=3,step=STEP)
sol=desolve_rk4(f,y,ics=ICS,end_points=END,step=STEP)
sol=sol[len(sol)-1]
point1=point(sol, size=50, color='black')
show(point1+plot1)
print(sol)
However, if you change the function and initial conditions to `f=x+(1/2)*y^2` and `ICS=[-2,0]`, we get an error `unable to make sense of Maxima expression`.
On the other hand this works ("Variant 1": passing dy/dx=f(x,y)):
x = var('x')
y = function('y', x)
f=x+(1/2)*y^2
de=diff(y,x)==f
ICS=[-2,0]
STEP=0.1
END=2
plot1=desolve_rk4(de,y,ics=ICS,output='slope_field',end_points=END,thickness=3,step=STEP)
sol=desolve_rk4(de,y,ics=ICS,end_points=END,step=STEP)
sol=sol[len(sol)-1]
point1=point(sol, size=50, color='black')
show(point1+plot1)
print(sol)
However, if you change the function and initial conditions to `f=x^2+y^2-1` and `ICS=[0,0]`, we get the same error `unable to make sense of Maxima expression`.
Does anybody have a solution to this problem.
RamónRamón Figueroa-CentenoWed, 10 Sep 2014 12:45:59 -0500http://ask.sagemath.org/question/24090/