Question:
How to solve 2nd Order IVP in MATLAB?
Answer:
Initial value problems can be solved symbolically in MATLAB by using built-in command "dsolve". The graphs can be decorated with LaTeX interpreter
clear all; clc; close all syms y(t) d2y = diff(y,t,2); dy = diff(y,t); eqn = d2y + 2*dy + 10 == t^2; cond1 = y(0) == 0; cond2 = dy(0) == 0; sol = dsolve(eqn,[cond1 cond2]) fplot(sol); ylim([-40 10]); xlim([-2 10]); grid on; xlabel('t'); ylabel('y(t)'); legend('$\frac{d^2y}{dt^2} + 2dy + 10 =t^2$','Interpreter','latex')
OUTPUT
sol = t^3/6 - (19*exp(-2*t))/8 - t^2/4 - (19*t)/4 + 19/8
0 Comments