Doing 3 second order differential equations numerically

In summary, the conversation discusses solving three second order differential equations in C, with the person seeking help admitting to having little experience in this area. They are open to using existing math libraries or writing their own code. The solution proposed involves reducing the equations to a set of six first order ODEs, which can then be solved using known methods such as Euler's method or Runge-Kutta. The conversation also mentions that the equations can be solved exactly using Maple or Mathematica.
  • #1
WraithM
32
0
I want to write a program in C that's going to solve 3 second order differential equations, and I have little to no experience in solving differential equations in C (however, I know C well enough). I'm having a bit of trouble.

First of all, I don't really know what method I'm going to use to solve these differential equations. I know how to do Euler's method, and Runge-Kutta and those things, but perhaps there's a math library out there for C that works magic with differential equations. I don't really care how these equations get solved. I just care that they get solved, but I'm more than willing to write some code myself to solve them. If anybody has any suggestions, that'd be extremely appreciated.

Also, I don't really know how I'm going to solve 3 equations at once. If I write my own differential equation solver, I'm going to substitute and make them first order, then solve again, but I don't really know how to deal with equations that depend on each other. :/

These are the equations:

[tex]\ddot{t} = \frac{-2M \dot{r} \dot{t}}{r(r-2M)}[/tex]

[tex]\ddot{\phi} = \frac{-2\dot{r}\dot{\phi}}{r}[/tex]

[tex]\ddot{r} = \frac{M\dot{r}^2}{r(r-2M)} - \frac{M(r-2M)}{r^3}\dot{t}^2 + (r - 2M) \dot{\phi}^2[/tex]

Dots mean differentiation with respect to [tex]\tau[/tex].

How do you solve 3 differential equations that all depend upon each other at once (numerically)?

Any help would be greatly appreciated.
 
Physics news on Phys.org
  • #2
Actually, this could be in C++ too. C or C++ works.
 
  • #3
I don't know about C++ but software which was design for mathematic analysis (especially Matlab) surely will have a lot of ODE/PDE tools.

In regards to the algorithm itself, it's not much different from one ODE.
And firstly it will be more simple to bring it down to a set of six first order ODE rather than three second-order.
What you do is define six component state variable
[tex]\vec{x}=(x_{i}), i=1,2,3,4,5,6[/tex],

and define a six-component vector-field

[tex]\vec{F}=(F_{i}(\vec{x})), i=1,2,3,4,5,6[/tex]

So your equations looks like this:

[tex]\frac{d}{d\tau}\vec{x}=\vec{F}(\vec{x})[/tex]

The components of the state variable will be:

[tex]x_{1}=t; x_{2}=\phi; x_{3}=r; x_{4}=\dot{t}; x_{5}=\dot{\phi}; x_{6}=\dot{r};[/tex]

The first components of F will contain the information that the derivative of the first three variables, are actually the last three variables. The last three component of F will relate the derivatives of x4,5,6 to the equations themselves:
[tex]F_{1}=x_{4}[/tex]
[tex]F_{2}=x_{5}[/tex]
[tex]F_{3}=x_{6}[/tex]
[tex]F_{4}=\frac{-2M x_{6} x_{4}}{x_{3} (x_{3}-2M)}[/tex]
[tex]F_{5}=\frac{-2x_{6} x_{5}}{x_{3}}[/tex]
[tex]F_{6}=\frac{M x^{2}_{6}}{x_{3} (x_{3}-2M)}-\frac{M ( x_{3}-2M)}{x^{3}_{3}} x^{2}_{4} + (x_{3}-2M)x^{2}_{5}[/tex]

So we've reduced the equations to the forms of:

[tex]\dot{\vec{x}}=\vec{F}(\vec{x})[/tex]

Now forget the vector signs, and just treat it like a first order ODE, which you know how to solve using Euler's method or Runge-Kutta.

For example in C\++, define a struct\class that will represent a six-component vector, with some basic arithmetic operations.
 
  • #4
Your ODE system can be solved exactly. Please use the following Maple code

ode1:=diff(t(tau),tau,tau)=-(2*M*diff(r(tau),tau)*diff(t(tau),tau))/(r(tau)*(r(tau)-2*M));

ode2:=diff(phi(tau),tau,tau)=-(2*diff(r(tau),tau)*diff(phi(tau),tau))/(r(tau));

ode3:=diff(r(tau),tau,tau)=(M*diff(r(tau),tau)^2)/(r(tau)*(r(tau)-2*M))-(M*(r(tau)-2*M))/r(tau)^3*diff(t(tau),tau)^2+(r(tau)-2*M)*diff(phi(tau),tau)^2;
ans:=[dsolve({ode1,ode2,ode3})];

The answer is lengthy enough to be displayed here.
 
  • #5
Thank you elibj123! Your method worked perfectly. I replicated my results in Mathematica, and my results in C almost perfectly fit the Mathematica curve.
 

1. What are second order differential equations?

A second order differential equation is a mathematical equation that involves the second derivative of a dependent variable with respect to an independent variable. It is commonly used to model physical systems in fields such as physics, engineering, and economics.

2. Why is it important to solve 3 second order differential equations numerically?

Solving second order differential equations numerically allows scientists and engineers to obtain approximate solutions for complex systems that cannot be solved analytically. This is particularly useful in situations where the system is nonlinear or does not have a closed-form solution.

3. What methods are used to solve 3 second order differential equations numerically?

Some common methods for solving second order differential equations numerically include the Euler method, the Runge-Kutta method, and the Adams-Bashforth method. These methods involve approximating the derivatives using discrete time steps and iteratively solving for the dependent variable at each time step.

4. How accurate are numerical solutions to second order differential equations?

The accuracy of numerical solutions depends on the chosen method and the size of the time steps used. Generally, smaller time steps result in more accurate solutions. However, round-off errors and other sources of numerical error can also affect the accuracy of the solution.

5. What are some applications of solving 3 second order differential equations numerically?

Numerical solutions to second order differential equations have a wide range of applications in various fields such as physics, engineering, and economics. They are commonly used to model physical systems such as pendulums, electrical circuits, and chemical reactions, to name a few. They can also be used to predict the behavior of systems over time and make informed decisions based on the results.

Similar threads

  • Differential Equations
Replies
2
Views
1K
Replies
7
Views
3K
Replies
2
Views
2K
Replies
1
Views
1K
  • Differential Equations
Replies
2
Views
972
  • Differential Equations
Replies
4
Views
1K
  • Differential Equations
Replies
10
Views
2K
Replies
3
Views
2K
  • Differential Equations
Replies
8
Views
2K
Replies
6
Views
1K
Back
Top