`dsolve`

can handle several ordinary differential
equations in several variables, with or without initial conditions.
For example, solve these linear first-order equations. First, create
the symbolic functions `f(t)`

and `g(t)`

:

syms f(t) g(t)

Now use `dsolve`

to solve the system. The toolbox
returns the computed solutions as elements of the structure `S`

:

S = dsolve(diff(f) == 3*f + 4*g, diff(g) == -4*f + 3*g)

S = g: [1x1 sym] f: [1x1 sym]

To return the values of `f(t)`

and `g(t)`

,
enter these commands:

f(t) = S.f g(t) = S.g

f(t) = C2*cos(4*t)*exp(3*t) + C1*sin(4*t)*exp(3*t) g(t) = C1*cos(4*t)*exp(3*t) - C2*sin(4*t)*exp(3*t)

If you prefer to recover `f(t)`

and `g(t)`

directly,
as well as include initial conditions, enter these commands:

syms f(t) g(t) [f(t), g(t)] = dsolve(diff(f) == 3*f + 4*g,... diff(g) == -4*f + 3*g, f(0) == 0, g(0) == 1)

f(t) = sin(4*t)*exp(3*t) g(t) = cos(4*t)*exp(3*t)

Suppose you want to solve a system of differential equations
in a matrix form. For example, solve the system *Y*′ = *A**Y* + *B*,
where *A*, *B*, and *Y* represent
the following matrices:

syms x(t) y(t) A = [1 2; -1 1]; B = [1; t]; Y = [x; y];

Solve the system using `dsolve`

:

S = dsolve(diff(Y) == A*Y + B); x = S.x y = S.y

x = 2^(1/2)*exp(t)*cos(2^(1/2)*t)*(C2 + (exp(-t)*(4*sin(2^(1/2)*t) +... 2^(1/2)*cos(2^(1/2)*t) + 6*t*sin(2^(1/2)*t) +... 6*2^(1/2)*t*cos(2^(1/2)*t)))/18) +... 2^(1/2)*exp(t)*sin(2^(1/2)*t)*(C1 - (exp(-t)*(4*cos(2^(1/2)*t) -... 2^(1/2)*sin(2^(1/2)*t) +... 6*t*cos(2^(1/2)*t) - 6*2^(1/2)*t*sin(2^(1/2)*t)))/18) y = exp(t)*cos(2^(1/2)*t)*(C1 - (exp(-t)*(4*cos(2^(1/2)*t) -... 2^(1/2)*sin(2^(1/2)*t) + 6*t*cos(2^(1/2)*t) -... 6*2^(1/2)*t*sin(2^(1/2)*t)))/18) - exp(t)*sin(2^(1/2)*t)*(C2 +... (exp(-t)*(4*sin(2^(1/2)*t) + 2^(1/2)*cos(2^(1/2)*t) +... 6*t*sin(2^(1/2)*t) + 6*2^(1/2)*t*cos(2^(1/2)*t)))/18)

Was this topic helpful?