Simulate a 2-input linear system with with ode45

조회 수: 1 (최근 30일)
Tianyi Zhu
Tianyi Zhu 2020년 10월 16일
댓글: Tianyi Zhu 2020년 10월 17일
Hello everyone,
I am new to ode45, I know how I should use ode45 to simulate a SISO system, but now I am trying to use it on a 2-input 2-output system.
The state space equations are as followed:
And here is my code trying to define the odefunction, the plot is not matching the result using lsim(), so it should not be correct.
t = [0 50]
x0 = [0 0 0 0 0];
[t,y] = ode45(@odefun,t,x0);
plot (t,y,'green');
grid on;
function dxdt = odefun(t,x)
x1 = x(1);
x2 = x(2);
x3 = x(3);
%input u
u1 =10;
u2 =10;
dxdt = zeros(5,1);
dxdt(1) = -1/6*x1-1/3*x3+1/6*u1+1/3*u2;
dxdt(2) = x3;
dxdt(3) = 0.5*x1-0.5*x2-0.5*x3;
dxdt(4) = x1-x2-x3;
dxdt(5) = 0.5*u1 -0.5*x1;
end

채택된 답변

Alan Stevens
Alan Stevens 2020년 10월 17일
More like this:
tspan = [0 50];
x0 = [0; 0; 0];
u = [10; 10];
[t,x] = ode45(@(t,x) odefun(t,x,u),tspan,x0);
x = x';
My = [1 -1 -1; -1/2 0 0];
Ky = [0 0; 1/2 0];
y = My*x + Ky*u;
plot (t,y,'green');
grid on;
function dxdt = odefun(~,x,u)
M = [-1/6 0 -1/3; 0 0 1; 1/2 -1/2 -1/2];
K = [1/6 1/3; 0 0; 0 0];
dxdt = M*x + K*u;
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by