Linear Algebra
Optimization
Differential Equations

## Explicit Runge-Kutta method.

The OdeExplicitRungeKutta45 class solves an initial-value problem for nonstiff ordinary differential equations using the explicit Runge Kutta method of order (4)5.

In this example the OdeExplicitRungeKutta45 class is used to solve the Euler equations of a rigid body without external forces:

```   y0' = y1 * y2 ,                 y0(0)=0
y1' = -y0 * y2,                 y1(0)=1
y2' = -0.51 * y0 * y1,          y2(0)=1

```

#### C# Code

`using System;`
`using System.Windows.Forms;`
` `
`using DotNumerics.ODE;`
` `
`namespace DotNumericsDemo.DifferentialEquations`
`{`
`    public partial class ExplicitRungeKutta : Form`
`    {`
`        private OdeExplicitRungeKutta45 odeRK = new OdeExplicitRungeKutta45();`
` `
`        private void Solve()`
`        {`
`            OdeFunction fun = new OdeFunction(ODEs);`
`            double[] y0 = new double[3];`
`            y0[0] = 0;`
`            y0[1] = 1;`
`            y0[2] = 1;`
`            this.odeRK.InitializeODEs(fun, 3);`
`            double[,] sol = odeRK.Solve(y0, 0, 0.03, 15);`
`        }`
` `
`        //Euler equations of a rigid body without external forces.`
`        //y0' = y1 * y2 ,                 y0(0)=0       `
`        //y1' = -y0 * y2,                 y1(0)=1 `
`        //y2' = -0.51 * y0 * y1,          y2(0)=1     `
`        double[] yprime = new double[3];`
`        private double[] ODEs(double t, double[] y)`
`        {`
`            yprime[0] = y[1] * y[2];`
`            yprime[1] = -y[0] * y[2];`
`            yprime[2] = -0.51 * y[0] * y[1];`
`            return this.yprime;`
`        }`
`    }`
`}`

#### Solution

Home > Numerical Libraries > Samples > Explicit Runge-Kutta