How to solve a second order linear differential equation with a heaviside function

4 次查看(过去 30 天)
I want to numerically solve the LDE (Linear Differential Equation) by integrating it numerically according to a flow diagram (see attached file). I have tried my best to come up with a script, but it does not give the correct answer.
clear all;
close all;
syms y(t) x(t) t
Dy = diff(y,t); D2y = diff(y,t,2); old = sympref ('HeavisideAtOrigin', 1);
cond = [y(0)==0, Dy(0)==0, D2y(0)==0];
eqn = diff(y,t,2) + 3*diff(y,t,1) + 2*y == heaviside(t);
ySol(t) = dsolve (eqn)

回答(1 个)

Lateef Adewale Kareem
Since its a second order differential equation, there is no need for y''(0)
and since you want to solve numerically, you can try this
Dy = diff(y,t); D2y = diff(y,t,2); old = sympref ('HeavisideAtOrigin', 1);
cond = [0, 0];
eqn = @(t,y) [y(2); -3*y(2)-2*y(1) + heaviside(t)]; [T,Y] = ode45(eqn,[0,20],cond)
visualize
plot(T,Y)

类别

Help CenterFile Exchange 中查找有关 Calculus 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by