用MATLAB求微分方程的阶跃响应和冲击响应的代码
时间: 2024-05-21 07:13:16 浏览: 69
用MATLAB求微分方程的解
下面是求微分方程的阶跃响应和冲击响应的MATLAB代码:
% 定义微分方程
syms t
eqn = diff(y(t),t,2) + 2*diff(y(t),t) + 2*y(t) == 3*heaviside(t);
% 求解微分方程的阶跃响应和冲击响应
y0 = 0; % 初始条件,y(0) = 0
yp0 = 0; % 初始条件,y'(0) = 0
ys = dsolve(eqn, y(0) == y0, diff(y(0)) == yp0);
ys_step = subs(ys, t, t - 1)*heaviside(t-1); % 阶跃响应
ys_impulse = diff(ys_step); % 冲击响应
% 绘制阶跃响应和冲击响应的图像
fplot(ys_step, [-5, 5], 'LineWidth', 2);
hold on;
fplot(ys_impulse, [-5, 5], 'LineWidth', 2);
legend('Step response', 'Impulse response');
title('Step and Impulse Responses of Differential Equation');
xlabel('t');
ylabel('y(t)');
阅读全文