How to use lsim() function for solving and plotting Initial Value Response

I am wondering how I can use the lsim() function to solve and plot the Initial Value Response solution to a state space representation problem.
Code:
clear all close all clc
t = [0:0.01:10] x0 = [1;-1] [t,y] = lsim(@sysP1,u,t,x0)
Function:
function dx = sysP1(t, x) A = [0 1; -5 -2]; B = [0;1]; K = [-1 1]; u = K*x; dx = A*x + B*u; end

 採用された回答

Star Strider
Star Strider 2017 年 10 月 2 日
To use lsim, you would have to configure your system with state feedback using the feedback (link) function or more appropriately, the reg (link) or related functions (linked to in that page).
You can easily use the code for your system as it exists with ode45:
function dx = sysP1(t, x)
A = [0 1; -5 -2]; B = [0;1]; K = [-1 1];
u = K*x;
dx = A*x + B*u;
end
t = [0:0.01:10]
x0 = [1;-1]
[t,y] = ode45(@sysP1,t,x0);
figure(1)
plot(t, y)
grid

4 件のコメント

Nick Alden
Nick Alden 2017 年 10 月 2 日
Thank you for your help, however my task is to make use of the lsim function. I deleted my sysP1 code and now have a sys = ss(A,B,C,D) representation.
Star Strider
Star Strider 2017 年 10 月 2 日
My pleasure.
You then need to use reg (or one of its friends) to produce your system with state feedback. Since this is apparently a homework problem, I’ll leave that for you to sort. (It’s fairly straightforward.)
Nick Alden
Nick Alden 2017 年 10 月 2 日
Thank you!
Star Strider
Star Strider 2017 年 10 月 2 日
As always, my pleasure!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMathematics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by