Solve Differential Equation Symbolically
Solve Differential Equation Symbolically
Solve a differential equation analytically by using the dsolve function, with or without initial conditions.
To solve a system of differential equations, see Solve a System of Differential Equations.
First-Order Linear ODE
Solve Differential Equation with Condition
Nonlinear Differential Equation with Initial Condition
Second-Order ODE with Initial Conditions
Third-Order ODE with Initial Conditions
More ODE Examples
Define the equation using == and represent differentiation using the diff function.
ode = diff(y,t) == t*y
ode(t) =
diff(y(t), t) == t*y(t)
If dsolve cannot solve your equation, then try solving the equation numerically. See Solve a
Second-Order Differential Equation Numerically.
1|Page
Nonlinear Differential Equation with Initial Condition
Solve this nonlinear differential equation with an initial condition. The equation has multiple
solutions.
2
𝑑𝑦
( + 𝑦) = 1
𝑑𝑡
𝑦(0) = 0
syms y(t)
ode = (diff(y,t)+y)^2 == 1;
cond = y(0) == 0;
ySol(t) = dsolve(ode,cond)
ySol(t) =
exp(-t) - 1
1 - exp(-t)
Solve ode for y. Simplify the solution using the simplify function.
conds = [cond1 cond2];
ySol(x) = dsolve(ode,conds);
ySol = simplify(ySol)
ySol(x) =
1 - (8*sin(x/2)^4)/3
2|Page
Because the initial conditions contain the first- and second-order derivatives, create two
symbolic functions, Du = diff(u,x) and D2u = diff(u,x,2), to specify the initial conditions.
syms u(x)
Du = diff(u,x);
D2u = diff(u,x,2);
uSol(x) = dsolve(ode,conds)
uSol(x) =
𝑑𝑦 syms y(t)
+ 4𝑦(𝑡) = 𝑒 −𝑡 , ode = diff(y)+4*y == exp(-t);
𝑑𝑡 cond = y(0) == 1;
𝑦(0) = 1 ySol(t) = dsolve(ode,cond)
ySol(t) =
exp(-t)/3 + (2*exp(-4*t))/3
𝑑2𝑦
2
𝑑𝑦 syms y(x)
2𝑥 2
+ 3𝑥 −𝑦 =0 ode = 2*x^2*diff(y,x,2)+3*x*diff(y,x)-y == 0;
𝑑𝑥 𝑑𝑥 ySol(x) = dsolve(ode)
ySol(x) =
C2/(3*x) + C3*x^(1/2)
3|Page