Simulate a 2-input linear system with with ode45
Show older comments
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
Accepted Answer
More Answers (0)
Categories
Find more on Programming in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!