MATLAB如何求解常微分方程组?ode45函数的使用
matlab求解常微分方程(组)---dsolve、ode系列函数详解(含例程)
1dsolve
https://ww2.mathworks.cn/help/symbolic/dsolve.html
digits(3)
syms x(t) u(t)
a=-2;
u(t)=1;
eqn = diff(x,t) == a*x+u;
cond = x(0)==1;
S = dsolve(eqn,cond)
fplot(S,[0,2])
vpa(subs(S,t,2))
2ode45
https://ww2.mathworks.cn/help/matlab/ref/ode45.html
% dydt+f(t)y(t)=g(t)
% myode.m
function dydt = myode(t,y,ft,f,gt,g)
f = interp1(ft,f,t); % Interpolate the data set (ft,f) at time t
g = interp1(gt,g,t); % Interpolate the data set (gt,g) at time t
dydt = -f.*y + g; % Evaluate ODE at time t
% dydt+f(t)y(t)=g(t)
tspan = [0 5];
ft = tspan;
f = ft.*0+2;
gt = tspan;
g = gt.*0+1;
y0 = 1;
opts = odeset('RelTol',1e-2,'AbsTol',1e-4);
[t,y] = ode45(@(t,y) myode(t,y,ft,f,gt,g), tspan, y0, opts);
plot(t,y)
数学