在MATLAB中分别用数值计算、符号计算和Simulink仿真方法求解方程: 𝑥′′+0.2𝑥′+0.4𝑥=0.2𝑢(𝑡),其中u(t)是单位阶跃函数。 x(0)=0 and x′(0)=0
时间: 2024-06-08 16:12:49 浏览: 114
数值计算方法:
首先将二阶微分方程转换为一阶微分方程组:
$\begin{cases} x_1' = x_2 \\ x_2' = -0.4x_1 - 0.2x_2 + 0.2u(t) \end{cases}$
其中 $x_1 = x$,$x_2 = x'$。
然后采用欧拉法进行数值计算,MATLAB代码如下:
```
function [t,x] = numerical_solve()
h = 0.001; % 步长
t = 0:h:10; % 时间范围
x = zeros(2,length(t)); % 初始化
x(:,1) = [0;0]; % 初值
for i = 2:length(t)
u = 0.2*(t(i)>0); % 单位阶跃函数
x(:,i) = x(:,i-1) + h*[x(2,i-1); -0.4*x(1,i-1)-0.2*x(2,i-1)+0.2*u];
end
end
```
符号计算方法:
采用MATLAB的符号计算工具箱,代码如下:
```
syms x(t) u(t)
Dx = diff(x,t);
ode = diff(x,t,2) + 0.2*Dx + 0.4*x == 0.2*u;
cond = [x(0) == 0, Dx(0) == 0];
xSol(t) = dsolve(ode, cond);
u(t) = heaviside(t); % 单位阶跃函数
ezplot(xSol,[0,10]);
```
Simulink仿真方法:
建立Simulink模型,将二阶微分方程转换成一阶微分方程组,模型如下图所示:

其中,Subsystem1用于计算状态方程,Subsystem2用于计算输出方程,Step用于产生单位阶跃函数,Scope用于显示结果。
MATLAB代码如下:
```
open_system('simulink_solve')
sim('simulink_solve', [0, 10]);
```
三种方法求解的结果如下图所示:

阅读全文
相关推荐












