Linear Algebra
Optimization
Differential Equations

Gear’s BDF method.

The OdeGearsBDF class solves an initial-value problem for stiff ordinary differential equations using the Gear’s BDF method.

In this example the OdeGearsBDF 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 GearsBDF : Form`
`    {`
`        private OdeGearsBDF odeBDF = new OdeGearsBDF();`
`        private double _mu = 500d;`
` `
`        private void Solve()`
`        {`
`            OdeFunction fun = new OdeFunction(ODEs);`
`            double[] y0 = new double[2];`
`            y0[0] = 2;`
`            y0[1] = 0;`
`            this.odeBDF.InitializeODEs(fun, 2, 0, y0);`
`            double[] y;`
`            double t;`
`            double[,] sol = new double[3001, 2];`
`            for (int i = 0; i <= 3000; i++)`
`            {`
`                t = i;`
`                y = odeBDF.Solve(t);`
`                sol[i, 0] = t;`
`                sol[i, 1] = y[0];`
`            }`
` `
`        }`
` `
`        //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 > Gears BDF