Linear Algebra
Optimization
Differential Equations

The OdeAdamsMoulton class solves an initial-value problem for nonstiff ordinary differential equations using the Adams Moulton method.

In this example the OdeAdamsMoulton class is used to solve the van der Pol equation:

```            y''-mu*(1-y^2)*y'+y=0
If y0=y and y1=y' then:
y0' = y1,                                  y0(0)= 2
y1' = mu * (1 - y0 ^2) * y1 - y0,          y1(0)=0

```

#### C# Code

`using System;`
`using System.Windows.Forms;`
` `
`using DotNumerics.ODE;`
` `
`namespace DotNumericsDemo.DifferentialEquations`
`{`
`    public partial class AdamsMoulton : Form`
`    {`
`        private OdeAdamsMoulton odeAdams = new OdeAdamsMoulton();`
`        private double _mu = 1;`
` `
`        private void Solve()`
`        {`
`            OdeFunction fun = new OdeFunction(ODEs);`
`            double[] y0 = new double[2];`
`            y0[0] = 2;`
`            y0[1] = 0;`
`            this.odeAdams.InitializeODEs(fun, 2);`
`            double[,] sol = odeAdams.Solve(y0, 0, 0.02, 20);`
`        }`
` `
`        //The van der Pol equation:`
`        //            y''-mu*(1-y^2)*y'+y=0`
`        //If y0=y and y1=y' then:`
`        //            y0' = y1,                               y0(0)= 2`
`        //            y1' = mu * (1 - y0 ^2) * y1 - y0        y1(0)=0`
`        double[] yprime = new double[2];`
`        private double[] ODEs(double t, double[] y)`
`        {`
`            yprime[0] = y[1];`
`            yprime[1] = this._mu * (1 - y[0] * y[0]) * y[1] - y[0];`
`            return this.yprime;`
`        }`
`    }`
`}`

#### Solution

Home > Numerical Libraries > Samples > Adams Moulton