精选问答
用matlab解微分方程组dx/dt=x-y-x(x^2+y^2)dy/dt=x+y-y(x^2+y^2)x(0)=2y(0)1

2020-04-29

用matlab解微分方程组
dx/dt=x-y-x(x^2+y^2)
dy/dt=x+y-y(x^2+y^2)
x(0)=2
y(0)1
优质解答
[x,y]=dsolve('Dx=x-y-x*(x^2+y^2)','Dy=x+y-y*(x^2+y^2)','x(0)=2','y(0)=1')
得到的结果是解析解没有找到.
用数值解.
在Matlab下输入:edit,然后将下面两行百分号之间的内容,复制进去,保存
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function y=zhidao_rk4_5(t,x)
%x,y变量分别用x(1),x(2)表示
y=[x(1)-x(2)-x(1)*(x(1)^2+x(2)^2);x(1)+x(2)-x(2)*(x(1)^2+x(2)^2)];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
在Matlab下面输入:
t_end=10;
x0=[2;1];
[t,x]=ode45('zhidao_rk4_5',[0,t_end],x0);
plot(t,x);
legend('x','y');
xlabel('t');
figure;
plot(x(:,1),x(:,2));
xlabel('x');
ylabel('y');
[x,y]=dsolve('Dx=x-y-x*(x^2+y^2)','Dy=x+y-y*(x^2+y^2)','x(0)=2','y(0)=1')
得到的结果是解析解没有找到.
用数值解.
在Matlab下输入:edit,然后将下面两行百分号之间的内容,复制进去,保存
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function y=zhidao_rk4_5(t,x)
%x,y变量分别用x(1),x(2)表示
y=[x(1)-x(2)-x(1)*(x(1)^2+x(2)^2);x(1)+x(2)-x(2)*(x(1)^2+x(2)^2)];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
在Matlab下面输入:
t_end=10;
x0=[2;1];
[t,x]=ode45('zhidao_rk4_5',[0,t_end],x0);
plot(t,x);
legend('x','y');
xlabel('t');
figure;
plot(x(:,1),x(:,2));
xlabel('x');
ylabel('y');
相关问答