Python, RungeKutta and first-order differential equation system.

In summary, the conversation discusses the creation of a function called "rhs" that returns the right-hand side of a first-order differential equation system. The function takes in an array or list of two solution components and a time argument. It also utilizes three global Python functions: friction, spring, and external for evaluating different components of the equation. The function is then tested with different numerical methods and a specific set of initial conditions. The conversation also includes links to relevant resources.
  • #1
MaxManus
277
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
  • #2


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:
  • #3




I can understand your confusion about the process of converting the given first-order differential equation system into a function that returns the right-hand side (rhs) of the system. Let me explain it in a step-by-step manner:

1. The given equation is: mu'' + f(u') + s(u) = F(t), t > 0, u(0) = U0, u'(0) = V0

2. We can simplify this equation by substituting v = u', which gives us a new equation: mv' + f(v) + s(u) = F(t), t > 0, u(0) = U0, v(0) = V0

3. Now, the rhs function is essentially a way to represent the right-hand side of the given equation. In this case, the rhs function will take in two arguments: u and t, and will return the right-hand side of the equation at the given values of u and t.

4. To do this, we first need to define the functions f(v), s(u), and external(t). These functions are given to us in the problem and represent the friction, spring, and external forces acting on the system, respectively.

5. Next, we need to substitute the values of these functions in the given equation. This will give us the final form of the equation that we need to return in the rhs function.

6. Finally, we need to make sure that the rhs function takes into account the initial conditions of the system, which are u(0) = U0 and v(0) = V0.

I hope this helps to clarify the process of creating the rhs function for the given first-order differential equation system. Please feel free to ask any further questions if needed.
 

1. What is Python?

Python is a high-level, interpreted programming language that is widely used for various applications, including scientific computing, data analysis, and machine learning.

2. What is RungeKutta?

RungeKutta is a numerical method used for solving differential equations. It is a popular method due to its accuracy and ability to handle a wide range of problems.

3. What is a first-order differential equation system?

A first-order differential equation system is a set of equations that describe the relationship between a variable and its rate of change. It involves only the first derivative of the variable with respect to time.

4. How is Python used for solving first-order differential equation systems using RungeKutta?

Python has many libraries and modules that provide functions for solving differential equations, including RungeKutta. These functions can be used to define the system of equations, set initial conditions, and solve for the desired variables.

5. What are some applications of using Python and RungeKutta for solving first-order differential equation systems?

Python and RungeKutta are commonly used in many scientific and engineering fields for modeling and simulating real-world systems, such as population dynamics, chemical reactions, and electrical circuits. They are also used in economics, finance, and other areas where differential equations are used to describe complex systems.

Similar threads

  • Programming and Computer Science
Replies
15
Views
1K
  • Programming and Computer Science
Replies
3
Views
930
  • Programming and Computer Science
Replies
15
Views
2K
  • Programming and Computer Science
2
Replies
50
Views
4K
  • Programming and Computer Science
Replies
1
Views
943
  • Programming and Computer Science
Replies
6
Views
1K
  • Programming and Computer Science
Replies
2
Views
2K
  • Programming and Computer Science
Replies
4
Views
4K
  • Differential Equations
Replies
7
Views
390
  • Programming and Computer Science
Replies
1
Views
2K
Back
Top