当前位置: 首页 > 工具软件 > ODE > 使用案例 >

关于ode和不同写法

充培
2023-12-01

 

 

% clc, clear, close all
%%%%%% 离散写法
clc, clear, close all
x0=[-10;0.5];t_final=20;
dt = 0.01;
tmax = t_final/dt;
KK = -1*[395  396 -18 -18 -18];
x1(1)=-10;x2(1)=0.5;
   for k=1:(tmax)    
      %xx(k)=[x1(k) x2(k) x1(k)*x1(k) x1(k)*x2(k) x2(k)*x2(k)];
      u(k)= KK*[x1(k) x2(k) x1(k)*x1(k) x1(k)*x2(k) x2(k)*x2(k)]';
      x1(k+1) = x1(k)+dt*x2(k);
      x2(k+1) = x2(k)+dt*(-0.2404*x2(k)*x2(k)-0.25382+0.0017857*u(k));        
      time(k)=k;
    end
figure;
%plot(x1(1:tmax));
 plot(time,x1(1:tmax),'b');
 hold on
 plot(time,x2(1:tmax),'y');
% % 
% 
% 
% 
clc, clear, close all
h_opt=odeset;

t_final=20;
x0=[-10;0.5]
K = [280	1120];
KK = [280 1120 10 -10 -5];
KK = [-261  249 20 20 20];
KK = [395  396 -18 -18 -18];
  
[t1,y1]=ode45(@(t1,y1) vdp_eq1(t1,y1,KK),[0,t_final],x0);
figure
plot(t1,y1(:,1),'b');
hold on
plot(t1,y1(:,2),'r');

function sys=vdp_eq1(t,x,KK)
  xx = [x(1); x(2);x(1)^2; x(2)^2;x(1)*x(2)];
  u(1) = -KK*xx;
  sys(1,1)=x(2);
  sys(2,1)=-0.2404*x(2)*x(2)-0.25382+0.0017857*u(1);
  %sys(2,1)=-0.2404*x(2)-0.25382+0.0017857*u(1);
end 

 

 类似资料: