Python Python, RungeKutta and first-order differential equation system.

AI Thread Summary
The discussion focuses on creating a function named `rhs(u, t)` to return the right-hand side of a first-order differential equation system. The equation involves parameters such as mass (m), friction, spring force, and an external force, with initial conditions specified for position and velocity. The user provides a proposed solution for the `rhs` function, which includes the derivatives of the position and velocity based on the given differential equation. However, clarification is sought on how to derive the `rhs` function from the original equation. The conversation also references testing the function with specific conditions and numerical methods, including the 4th-order Runge-Kutta and Forward Euler methods, using a defined time step. Links to relevant exercises and resources are shared for further context.
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?
 
Technology 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:
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...

Similar threads

Replies
15
Views
2K
Replies
6
Views
2K
Replies
50
Views
5K
Replies
3
Views
1K
Replies
3
Views
3K
Replies
2
Views
2K
Replies
1
Views
3K
Replies
4
Views
5K
Replies
18
Views
2K
Back
Top