MATLAB如何解非线性微分方程组

2025-05-08 23:03:42
推荐回答(1个)
回答1:

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))

 dx(1)=0;

else

 dx(1)=450/sqrt(1+((120-x(2))/(90*t-x(1)))^2);

end

if abs(120-x(2))

 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]区间上函数取值.