MATLAB如何解非线性微分方程组
来源:学生作业帮 编辑:搜搜做题作业网作业帮 分类:综合作业 时间:2024/06/14 11:13:59
MATLAB如何解非线性微分方程组
dx/dt=450/sqrt(1+((120-y)/(90*t-x))^2)
dy/dt=450/sqrt(1+((90*t-x)/(120-y))^2)
x(0)=0,y(0)=0
运行出来的结果是什么?
dx/dt=450/sqrt(1+((120-y)/(90*t-x))^2)
dy/dt=450/sqrt(1+((90*t-x)/(120-y))^2)
x(0)=0,y(0)=0
运行出来的结果是什么?
![MATLAB如何解非线性微分方程组](/uploads/image/z/4119649-25-9.jpg?t=MATLAB%E5%A6%82%E4%BD%95%E8%A7%A3%E9%9D%9E%E7%BA%BF%E6%80%A7%E5%BE%AE%E5%88%86%E6%96%B9%E7%A8%8B%E7%BB%84)
function [t,x]=solv(tspan)
% argument
% tspan stands for time span
x0 =[0,0];
[t,x]=ode45(@odefun,tspan,x0);
subplot(2,1,1),plot(t,x(:,1),'-'),title('P');
subplot(2,1,2),plot(t,x(:,2),'-'),title('y');
end
function dx=odefun(t,x)
dx=zeros(2,1);
if abs(90*t-x(1))<eps
dx(1)=0;
else
dx(1)=450/sqrt(1+((120-x(2))/(90*t-x(1)))^2);
end
if abs(120-x(2))<eps
dx(2)=0;
else
dx(2)=450/sqrt(1+((90*t-x(1))/(120-x(2)))^2);
end
end
matlab只能给出数值解,所谓数值解也就是指定有限点上的函数取值,一般没法用显式的函数表达式来描述.
将上述代码保存为solv.m,运行[t,x]=solv([0:0.01:1])便能得到[0:1]区间上函数取值.
![](http://img.wesiedu.com/upload/5/70/5709f35d39709eb33f12ce2a37432d84.jpg)
% argument
% tspan stands for time span
x0 =[0,0];
[t,x]=ode45(@odefun,tspan,x0);
subplot(2,1,1),plot(t,x(:,1),'-'),title('P');
subplot(2,1,2),plot(t,x(:,2),'-'),title('y');
end
function dx=odefun(t,x)
dx=zeros(2,1);
if abs(90*t-x(1))<eps
dx(1)=0;
else
dx(1)=450/sqrt(1+((120-x(2))/(90*t-x(1)))^2);
end
if abs(120-x(2))<eps
dx(2)=0;
else
dx(2)=450/sqrt(1+((90*t-x(1))/(120-x(2)))^2);
end
end
matlab只能给出数值解,所谓数值解也就是指定有限点上的函数取值,一般没法用显式的函数表达式来描述.
将上述代码保存为solv.m,运行[t,x]=solv([0:0.01:1])便能得到[0:1]区间上函数取值.
![](http://img.wesiedu.com/upload/5/70/5709f35d39709eb33f12ce2a37432d84.jpg)