Python, RungeKutta and first-order differential equation system.

Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
1 reply · 12K views
MaxManus
Messages
268
Reaction score
1
Make a function:
Code:
def rhs(u,t):
for returning the right-hand side of the first-order differential equation system
from Exercise 11.36. As usual, the u argument is an array or list with the two
solution components u[0] and u[1] at some time t. Inside rhs, assume that
you have access to three global Python functions friction(dudt), spring(u),
and external(t) for evaluating f(u˙ ), s(u), and F(t), respectively.


Homework Equations



The equation is, given to me by lurflurf,:
mv' + f(v ) + s(u) = F(t), t > 0, u(0) = U0, v (0) = V0
where v=u'
For the record the equation was:
mu'' + f(u' ) + s(u) = F(t), t > 0, u(0) = U0, u' (0) = V0 .

Test the rhs function in combination with the functions f(u' ) = 0, F(t) = 0, s(u) = u, and the choice m = 1. The differential equation then reads
u'' + u = 0. With initial conditions u(0) = 1 and u'(0) = 0, one can show
that the solution is given by u(t) = cos(t). Apply two numerical methods:
the 4th-order RungeKutta method and the Forward Euler method from the
ODESolver module developed in Chapter 11.4, using a time step dt = pi /20.


The Attempt at a Solution



Code:
 def rhs(u, t):
    return [u[1],
            (1./m)*(external(t) - friction(u[1]) - spring(u[0]))]

This is the solution, but I don't get how yuu go from the equation to rhs.
Can someone help me?
 
Physics news on Phys.org


Here is the page with the exercises: http://www.ifi.uio.no/~inf1100/ODE_project.pdf"

The equation is given in 11.36 and it is 11.37 I need help with.
The solution is http://www.ifi.uio.no/~inf1100/live-programming/oscillator_v1.py"

ODESolver http://www.ifi.uio.no/~inf1100/src/oo/ODESolver.py"

Scitools contains array, plot etc
 
Last edited by a moderator: