matlab中求微分方程
时间: 2023-11-21 17:58:45 浏览: 102
以下是在Matlab中求微分方程的方法:
1.使用ode45函数求解微分方程
```matlab
% 定义微分方程
fun = @(t,x) 2*sin(t)-4*x;
% 定义初始条件
x0 = 0;
% 定义时间范围
tspan = [0 10];
% 求解微分方程
[t,x] = ode45(fun,tspan,x0);
% 绘制图像
plot(t,x);
xlabel('t');
ylabel('x');
grid on;
```
2.使用dsolve函数求解微分方程
```matlab
% 定义微分方程
syms x(t)
eqn = diff(x,t) == 2*sin(t)-4*x;
% 定义初始条件
cond = x(0) == 0;
% 求解微分方程
xSol(t) = dsolve(eqn,cond);
% 绘制图像
fplot(xSol,[0 10]);
xlabel('t');
ylabel('x');
grid on;
```
阅读全文
相关推荐




