美文网首页
Matlab使用ode45求解高阶微分方程

Matlab使用ode45求解高阶微分方程

作者: Ahellop | 来源:发表于2018-12-11 23:04 被阅读0次

原问题为利用ode45求解下面微分方程:

\frac{dx_{1}}{dt}=x_{2}

\frac{dx_{2}}{dt}=7\times (1-x_{1}^2)x_{2}-x_{1}

初值为x_{1}(0)=1,x_{2}(0)=0

可以转为二阶微分方程

利用Matlab求解,下面为源代码

functionMyode45

tspan = [2,4];              %求解区间

y0 = [1 0];                   %y0的初值形式为行向量

[t,x] = ode45(@odefun,tspan,y0);   %使用ode45求解微分方程

plot(t,x(:,1),'-o',t,x(:,2),'-*')  %作图

legend('y1','y‘')

title('y'' ''=-y-7y''y1^2+7')

xlabel('t')

ylabel('y')

function y =odefun(~,x) % 定义ode45函数的参数odefun

y = zeros(2,1);        % 创建列向量

y(1) = x(2);            % 表达式1:dx1/dt=x2 => y(1) =x1'=x(2)

y(2) = 7*(1-x(1)^2)*x(2)-x(1); % 表达式2:dx2/dt=7(1-x1^2)x2-x1 => y(2)=x2'=7*(1-x(1)^2)*x(2)-x(1) 

end

end

相关文章

网友评论

      本文标题:Matlab使用ode45求解高阶微分方程

      本文链接:https://www.haomeiwen.com/subject/cueyhqtx.html