What is the difference between analytical solutions (dsolve) and numerical ODE solvers (ode45) in MATLAB?
Neeta Dsouza answered .
2026-07-24
Analytical solutions compute exact symbolic expressions (e.g., y(t) = 5e-2t). Numerical solutions compute discrete numerical arrays approximating solution curves over time intervals.
% Differential Equation: dy/dt = -2y, y(0) = 5
% 1. Analytical Solution (Symbolic Math Toolbox)
syms y(t)
ode = diff(y,t) == -2*y;
cond = y(0) == 5;
y_exact = dsolve(ode, cond);
disp('Exact Analytical Solution:'); disp(y_exact);
% 2. Numerical Solution (ode45)
dydt = @(t,y) -2*y;
[t_num, y_num] = ode45(dydt, [0 2], 5);
plot(t_num, y_num, 'o-'); title('Numerical Solution via ODE45');