Ask Your Question
1

type error solving system of differential equations numerically

asked 2019-07-28 15:44:45 +0200

werner1717 gravatar image

updated 2019-07-28 18:40:10 +0200

slelievre gravatar image

I tried to solve a differential system numerically as follows:

R = 5
g = 9.8
t = var('t')
x = function('x')(t)
y = function('y')(t)
de1 = diff(x,t) - y == 0
de2 = diff(y,t) + (g/R)*sin(x) == 0
desolve_system_rk4([de1,de2],[x,y],ics = [0,(20/180)*pi,0],ivar=t)

and got a type error:

Traceback (most recent call last)
...
TypeError: Error executing code in Maxima
CODE:
    sage4 : rk(['diff('x(_SAGE_VAR_t),_SAGE_VAR_t,1)-'y(_SAGE_VAR_t)=0,'diff('y(_SAGE_VAR_t),_SAGE_VAR_t,1)+1.96*sin('x(_SAGE_VAR_t))=0],['x(_SAGE_VAR_t),'y(_SAGE_VAR_t)],[%pi/9,0],[_SAGE_VAR_t,0,10,0.1])        $
Maxima ERROR:

rk: variable name expected; found: 'x(_SAGE_VAR_t)
 -- an error. To debug this try: debugmode(true);
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2019-07-29 01:15:05 +0200

rburing gravatar image

That is not the type of input that desolve_system_rk4 accepts. As written in the documentation and seen in the example, it accepts a list of right-hand sides of first-order differential equations, like this:

R = 5
g = 9.8
var('x,y,t')
de1 = y
de2 = -(g/R)*sin(x)
sol_points = desolve_system_rk4([de1,de2],[x,y],ics = [0,(20/180)*RR.pi(),0],ivar=t)
sol_points_xy = [(x,y) for (x,y,_) in sol_points]
list_plot(sol_points_xy, plotjoined=True)

sage rk4

edit flag offensive delete link more

Comments

oh I see thx for the help

werner1717 gravatar imagewerner1717 ( 2019-07-29 07:44:22 +0200 )edit
1

@werner1717 if that answers your question please mark the answer as accepted by clicking the "accept" button (the one with a tick mark) at the top left of the answer. This marks the question as answered in the list of questions on the home page of Ask Sage.

slelievre gravatar imageslelievre ( 2019-07-29 16:22:47 +0200 )edit

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: 2019-07-28 15:44:45 +0200

Seen: 144 times

Last updated: Jul 29 '19