Accessing A and B matrices from discrete state space
Show older comments
I have written a code to convert continuous time state space models to discrete time using 'tustin' metod. I want to access A and B matrices for each the discretized models. I can access from command window but I want to use them for a later portion of the code. My current code is not giving me10 discretized A and B matrices. Kindly help
clc;
clear all;
A1(:,:,1) =[ 0 1.0000 0;0 0 1.0000; -0.4768 -0.0375 -0.0715];%updated the A matrices, -20 t0 20
A1(:,:,2) =[0 1.0000 0;0 0 1.0000; -0.4875 -0.0383 0];
A1(:,:,3) =[0 1.0000 0;0 0 1.0000; -0.4768 -0.0375 0.0715];
A1(:,:,4) =[0 1.0000 0;0 0 1.0000;0 -9.8100 0];
A1(:,:,5) =[0 1.0000 0;0 0 1.0000;0 -9.8100 0];
A1(:,:,6) =[0 1.0000 0;0 0 1.0000;0 -9.8100 0];
A1(:,:,7) =[0 1.0000 0;0 0 1.0000; 0.4768 -0.0375 0.0715];
A1(:,:,8) =[0 1.0000 0;0 0 1.0000; 0.4875 -0.0383 0];
A1(:,:,9) =[ 0 1.0000 0;0 0 1.0000; 0.4768 -0.0375 -0.0715];
A1(:,:,10)=[0 1.0000 0;0 0 1.0000; 0 -1.3438 -2.5664];
B1=[0;0;1];
C1=[1 0 0];
D1=0;
dt=0.01;
for i=1:10
sys1=ss(A1(:,:,i),B1,C1,D1);
sys2=c2d(sys1,dt,'tustin');
a2(:,:,i)=sys2.a
b2(:,:,i)=sys2.b
end
2 Comments
It seems to do what you want when I run it.
Is there something I am missing here?
clc;
clear all;
A1(:,:,1) =[ 0 1.0000 0;0 0 1.0000; -0.4768 -0.0375 -0.0715];%updated the A matrices, -20 t0 20
A1(:,:,2) =[0 1.0000 0;0 0 1.0000; -0.4875 -0.0383 0];
A1(:,:,3) =[0 1.0000 0;0 0 1.0000; -0.4768 -0.0375 0.0715];
A1(:,:,4) =[0 1.0000 0;0 0 1.0000;0 -9.8100 0];
A1(:,:,5) =[0 1.0000 0;0 0 1.0000;0 -9.8100 0];
A1(:,:,6) =[0 1.0000 0;0 0 1.0000;0 -9.8100 0];
A1(:,:,7) =[0 1.0000 0;0 0 1.0000; 0.4768 -0.0375 0.0715];
A1(:,:,8) =[0 1.0000 0;0 0 1.0000; 0.4875 -0.0383 0];
A1(:,:,9) =[ 0 1.0000 0;0 0 1.0000; 0.4768 -0.0375 -0.0715];
A1(:,:,10)=[0 1.0000 0;0 0 1.0000; 0 -1.3438 -2.5664];
B1=[0;0;1];
C1=[1 0 0];
D1=0;
dt=0.01;
for i=1:10
fprintf('Iteration %2d —————',i)
sys1=ss(A1(:,:,i),B1,C1,D1);
sys2{i}=c2d(sys1,dt,'tustin');
a2(:,:,i)=sys2{i}.a
b2(:,:,i)=sys2{i}.b
end
.
Accepted Answer
More Answers (0)
Categories
Find more on Creating and Concatenating Matrices 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!