### 23.4.1 Approximating solutions of y′=f(t,y)

The odesolve command can solve first order differential equations or first order systems. This section covers equations, while systems of equations are discussed in the next section.

odesolve finds values of the solution of a differential equation of the form y′=f(t,y); specifically, it will approximate y(t1) for a specified t1.

odesolve can take its arguments in various ways. Letting t and y be the independent and dependent variables, t0 and y0 be the initial values, t1 the place where you want the value of y, f be the function in the differential equation, f(t,y) be an expression which determines the function f (see Section 8.2.1 for the difference between a function and an expression).

- odesolve takes three or four mandatory arguments and two optional arguments:
  - mandatory, mandatory arguments given by one of the following sequences:
    - f(t,y),[t,y],[t0,y0],t1
    - f(t,y),t=t0..t1,y,y0
    - t0..t1,f,y0
    - t0..t1,(t,y)->f(t,y),y0
  - Optionally, tstep=n, to set the initial tstep value to the numeric solver from the GSL. It may be modified by the solver. It is also used to control the number of iterations of the solver by 2(t1−t0)/n (if the number of iterations exceeds this value, the solver will stops at a time t<t1).
  - Optionally, curve, the symbol.
- odesolve(mandatory ⟨,tstep=n,curve ⟩) returns an approximate value of y(t1) where y(t) is the solution of:

  y′(t)=f(t,y(t)), y(t0)=y0.

  With an optional argument of curve, the list of all the [t,[y(t)]] values that were computed are returned.

#### Examples

odesolve(sin(t*y),[t,y],[0,1],2)

or:

odesolve(sin(t*y),t=0..2,y,1)

or:

odesolve(0..2,(t,y)->sin(t*y),1)

or:

f(t,y):=sin(t*y); odesolve(0..2,f,1)

| ⎡ ⎣ | 1.82241255674 | ⎤ ⎦

odesolve(0..2,f,1,tstep=0.3)

| ⎡ ⎣ | 1.82241255675 | ⎤ ⎦

odesolve(sin(t*y),t=0..2,y,1,tstep=0.5)

| ⎡ ⎣ | 1.82241255674 | ⎤ ⎦

odesolve(sin(t*y),t=0..2,y,1,tstep=0.5,curve)

⎡ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎣ |
0.0 |
⎡ ⎣ | 1.0 | ⎤ ⎦
0.0238917513909 |
⎡ ⎣ | 1.00028543504 | ⎤ ⎦
0.065808814858 |
⎡ ⎣ | 1.00216696089 | ⎤ ⎦
0.108895370376 |
⎡ ⎣ | 1.00594077449 | ⎤ ⎦
⋮ | ⋮
1.96462490594 |
⎡ ⎣ | 1.8389834135 | ⎤ ⎦
1.97769352646 |
⎡ ⎣ | 1.83297839039 | ⎤ ⎦
1.9908403154 |
⎡ ⎣ | 1.82679805346 | ⎤ ⎦
2.0 |
⎡ ⎣ | 1.82241255674 | ⎤ ⎦
| ⎤ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎦