## SciPy – 14 – integrazione – 4 Continuo da qui, copio qui.

Equazioni differenziali (`odeint`)
Integrating a set of ordinary differential equations (ODEs) given initial conditions is another useful example. The function odeint is available in SciPy for integrating a first-order vector differential equation: given initial conditions `y(0)=y0`, where `y` is a length N vector and f is a mapping from `RN` to `RN`. A higher-order ordinary differential equation can always be reduced to a differential equation of this type by introducing intermediate derivatives into the `y` vector.

For example suppose it is desired to find the solution to the following second-order differential equation: with initial conditions It is known that the solution to this differential equation with these boundary conditions is the Airy function which gives a means to check the integrator using `special.airy`.

First, convert this ODE into standard form by setting and `t=z`. Thus, the differential equation becomes In other words, As an interesting reminder, if `A(t)` commutes with

sp60

under matrix multiplication, then this linear differential equation has an exact solution using the matrix exponential: However, in this case, `A(t)` and its integral do not commute.

There are many optional inputs and outputs available when using `odeint` which can help tune the solver. These additional inputs and outputs are not needed much of the time, however, and the three required input arguments and the output solution suffice. The required inputs are the function defining the derivative, `fprime`, the initial conditions vector, `y0`, and the time points to obtain a solution, `t`, (with the initial value point as the first element of this sequence). The output to `odeint` is a matrix where each row contains the solution vector at each requested time point (thus, the initial conditions are given in the first output row).

The following example illustrates the use of `odeint` including the usage of the `Dfun` option which allows the user to specify a gradient (with respect to `y`) of the function, `f(y,t)`.   Posta un commento o usa questo indirizzo per il trackback.