Weird problem with desolve_rk4

asked 2014-09-10 19:45:59 +0100

Ramón Figueroa-Centeno gravatar image

updated 2014-09-10 19:54:24 +0100

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 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ón

edit retag flag offensive close merge delete

Comments

1

I simply can't reproduce this. What version of Sage are you using, on what platform, etc? Also, usually when Sage can't make sense of a Maxima expressions, it often says what that expression is that it's having trouble parsing. Thanks!

kcrisman gravatar imagekcrisman ( 2014-09-10 20:45:17 +0100 )edit