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
Iteration 1 —————
a2 = 3×3
1.0000 0.0100 0.0000
-0.0000 1.0000 0.0100
-0.0048 -0.0004 0.9993
b2 = 3×1
0.0000
0.0000
0.0100
Iteration 2 —————
a2 =
a2(:,:,1) =
1.0000 0.0100 0.0000
-0.0000 1.0000 0.0100
-0.0048 -0.0004 0.9993
a2(:,:,2) =
1.0000 0.0100 0.0000
-0.0000 1.0000 0.0100
-0.0049 -0.0004 1.0000
b2 =
b2(:,:,1) =
0.0000
0.0000
0.0100
b2(:,:,2) =
0.0000
0.0000
0.0100
Iteration 3 —————
a2 =
a2(:,:,1) =
1.0000 0.0100 0.0000
-0.0000 1.0000 0.0100
-0.0048 -0.0004 0.9993
a2(:,:,2) =
1.0000 0.0100 0.0000
-0.0000 1.0000 0.0100
-0.0049 -0.0004 1.0000
a2(:,:,3) =
1.0000 0.0100 0.0001
-0.0000 1.0000 0.0100
-0.0048 -0.0004 1.0007
b2 =
b2(:,:,1) =
0.0000
0.0000
0.0100
b2(:,:,2) =
0.0000
0.0000
0.0100
b2(:,:,3) =
0.0000
0.0001
0.0100
Iteration 4 —————
a2 =
a2(:,:,1) =
1.0000 0.0100 0.0000
-0.0000 1.0000 0.0100
-0.0048 -0.0004 0.9993
a2(:,:,2) =
1.0000 0.0100 0.0000
-0.0000 1.0000 0.0100
-0.0049 -0.0004 1.0000
a2(:,:,3) =
1.0000 0.0100 0.0001
-0.0000 1.0000 0.0100
-0.0048 -0.0004 1.0007
a2(:,:,4) =
1.0000 0.0100 0.0000
0 0.9995 0.0100
0 -0.0981 0.9995
b2 =
b2(:,:,1) =
0.0000
0.0000
0.0100
b2(:,:,2) =
0.0000
0.0000
0.0100
b2(:,:,3) =
0.0000
0.0001
0.0100
b2(:,:,4) =
0.0000
0.0000
0.0100
Iteration 5 —————
a2 =
a2(:,:,1) =
1.0000 0.0100 0.0000
-0.0000 1.0000 0.0100
-0.0048 -0.0004 0.9993
a2(:,:,2) =
1.0000 0.0100 0.0000
-0.0000 1.0000 0.0100
-0.0049 -0.0004 1.0000
a2(:,:,3) =
1.0000 0.0100 0.0001
-0.0000 1.0000 0.0100
-0.0048 -0.0004 1.0007
a2(:,:,4) =
1.0000 0.0100 0.0000
0 0.9995 0.0100
0 -0.0981 0.9995
a2(:,:,5) =
1.0000 0.0100 0.0000
0 0.9995 0.0100
0 -0.0981 0.9995
b2 =
b2(:,:,1) =
0.0000
0.0000
0.0100
b2(:,:,2) =
0.0000
0.0000
0.0100
b2(:,:,3) =
0.0000
0.0001
0.0100
b2(:,:,4) =
0.0000
0.0000
0.0100
b2(:,:,5) =
0.0000
0.0000
0.0100
Iteration 6 —————
a2 =
a2(:,:,1) =
1.0000 0.0100 0.0000
-0.0000 1.0000 0.0100
-0.0048 -0.0004 0.9993
a2(:,:,2) =
1.0000 0.0100 0.0000
-0.0000 1.0000 0.0100
-0.0049 -0.0004 1.0000
a2(:,:,3) =
1.0000 0.0100 0.0001
-0.0000 1.0000 0.0100
-0.0048 -0.0004 1.0007
a2(:,:,4) =
1.0000 0.0100 0.0000
0 0.9995 0.0100
0 -0.0981 0.9995
a2(:,:,5) =
1.0000 0.0100 0.0000
0 0.9995 0.0100
0 -0.0981 0.9995
a2(:,:,6) =
1.0000 0.0100 0.0000
0 0.9995 0.0100
0 -0.0981 0.9995
b2 =
b2(:,:,1) =
0.0000
0.0000
0.0100
b2(:,:,2) =
0.0000
0.0000
0.0100
b2(:,:,3) =
0.0000
0.0001
0.0100
b2(:,:,4) =
0.0000
0.0000
0.0100
b2(:,:,5) =
0.0000
0.0000
0.0100
b2(:,:,6) =
0.0000
0.0000
0.0100
Iteration 7 —————
a2 =
a2(:,:,1) =
1.0000 0.0100 0.0000
-0.0000 1.0000 0.0100
-0.0048 -0.0004 0.9993
a2(:,:,2) =
1.0000 0.0100 0.0000
-0.0000 1.0000 0.0100
-0.0049 -0.0004 1.0000
a2(:,:,3) =
1.0000 0.0100 0.0001
-0.0000 1.0000 0.0100
-0.0048 -0.0004 1.0007
a2(:,:,4) =
1.0000 0.0100 0.0000
0 0.9995 0.0100
0 -0.0981 0.9995
a2(:,:,5) =
1.0000 0.0100 0.0000
0 0.9995 0.0100
0 -0.0981 0.9995
a2(:,:,6) =
1.0000 0.0100 0.0000
0 0.9995 0.0100
0 -0.0981 0.9995
a2(:,:,7) =
1.0000 0.0100 0.0001
0.0000 1.0000 0.0100
0.0048 -0.0004 1.0007
b2 =
b2(:,:,1) =
0.0000
0.0000
0.0100
b2(:,:,2) =
0.0000
0.0000
0.0100
b2(:,:,3) =
0.0000
0.0001
0.0100
b2(:,:,4) =
0.0000
0.0000
0.0100
b2(:,:,5) =
0.0000
0.0000
0.0100
b2(:,:,6) =
0.0000
0.0000
0.0100
b2(:,:,7) =
0.0000
0.0001
0.0100
Iteration 8 —————
a2 =
a2(:,:,1) =
1.0000 0.0100 0.0000
-0.0000 1.0000 0.0100
-0.0048 -0.0004 0.9993
a2(:,:,2) =
1.0000 0.0100 0.0000
-0.0000 1.0000 0.0100
-0.0049 -0.0004 1.0000
a2(:,:,3) =
1.0000 0.0100 0.0001
-0.0000 1.0000 0.0100
-0.0048 -0.0004 1.0007
a2(:,:,4) =
1.0000 0.0100 0.0000
0 0.9995 0.0100
0 -0.0981 0.9995
a2(:,:,5) =
1.0000 0.0100 0.0000
0 0.9995 0.0100
0 -0.0981 0.9995
a2(:,:,6) =
1.0000 0.0100 0.0000
0 0.9995 0.0100
0 -0.0981 0.9995
a2(:,:,7) =
1.0000 0.0100 0.0001
0.0000 1.0000 0.0100
0.0048 -0.0004 1.0007
a2(:,:,8) =
1.0000 0.0100 0.0000
0.0000 1.0000 0.0100
0.0049 -0.0004 1.0000
b2 =
b2(:,:,1) =
0.0000
0.0000
0.0100
b2(:,:,2) =
0.0000
0.0000
0.0100
b2(:,:,3) =
0.0000
0.0001
0.0100
b2(:,:,4) =
0.0000
0.0000
0.0100
b2(:,:,5) =
0.0000
0.0000
0.0100
b2(:,:,6) =
0.0000
0.0000
0.0100
b2(:,:,7) =
0.0000
0.0001
0.0100
b2(:,:,8) =
0.0000
0.0000
0.0100
Iteration 9 —————
a2 =
a2(:,:,1) =
1.0000 0.0100 0.0000
-0.0000 1.0000 0.0100
-0.0048 -0.0004 0.9993
a2(:,:,2) =
1.0000 0.0100 0.0000
-0.0000 1.0000 0.0100
-0.0049 -0.0004 1.0000
a2(:,:,3) =
1.0000 0.0100 0.0001
-0.0000 1.0000 0.0100
-0.0048 -0.0004 1.0007
a2(:,:,4) =
1.0000 0.0100 0.0000
0 0.9995 0.0100
0 -0.0981 0.9995
a2(:,:,5) =
1.0000 0.0100 0.0000
0 0.9995 0.0100
0 -0.0981 0.9995
a2(:,:,6) =
1.0000 0.0100 0.0000
0 0.9995 0.0100
0 -0.0981 0.9995
a2(:,:,7) =
1.0000 0.0100 0.0001
0.0000 1.0000 0.0100
0.0048 -0.0004 1.0007
a2(:,:,8) =
1.0000 0.0100 0.0000
0.0000 1.0000 0.0100
0.0049 -0.0004 1.0000
a2(:,:,9) =
1.0000 0.0100 0.0000
0.0000 1.0000 0.0100
0.0048 -0.0004 0.9993
b2 =
b2(:,:,1) =
0.0000
0.0000
0.0100
b2(:,:,2) =
0.0000
0.0000
0.0100
b2(:,:,3) =
0.0000
0.0001
0.0100
b2(:,:,4) =
0.0000
0.0000
0.0100
b2(:,:,5) =
0.0000
0.0000
0.0100
b2(:,:,6) =
0.0000
0.0000
0.0100
b2(:,:,7) =
0.0000
0.0001
0.0100
b2(:,:,8) =
0.0000
0.0000
0.0100
b2(:,:,9) =
0.0000
0.0000
0.0100
Iteration 10 —————
a2 =
a2(:,:,1) =
1.0000 0.0100 0.0000
-0.0000 1.0000 0.0100
-0.0048 -0.0004 0.9993
a2(:,:,2) =
1.0000 0.0100 0.0000
-0.0000 1.0000 0.0100
-0.0049 -0.0004 1.0000
a2(:,:,3) =
1.0000 0.0100 0.0001
-0.0000 1.0000 0.0100
-0.0048 -0.0004 1.0007
a2(:,:,4) =
1.0000 0.0100 0.0000
0 0.9995 0.0100
0 -0.0981 0.9995
a2(:,:,5) =
1.0000 0.0100 0.0000
0 0.9995 0.0100
0 -0.0981 0.9995
a2(:,:,6) =
1.0000 0.0100 0.0000
0 0.9995 0.0100
0 -0.0981 0.9995
a2(:,:,7) =
1.0000 0.0100 0.0001
0.0000 1.0000 0.0100
0.0048 -0.0004 1.0007
a2(:,:,8) =
1.0000 0.0100 0.0000
0.0000 1.0000 0.0100
0.0049 -0.0004 1.0000
a2(:,:,9) =
1.0000 0.0100 0.0000
0.0000 1.0000 0.0100
0.0048 -0.0004 0.9993
a2(:,:,10) =
1.0000 0.0100 0.0000
0 0.9999 0.0099
0 -0.0133 0.9746
b2 =
b2(:,:,1) =
0.0000
0.0000
0.0100
b2(:,:,2) =
0.0000
0.0000
0.0100
b2(:,:,3) =
0.0000
0.0001
0.0100
b2(:,:,4) =
0.0000
0.0000
0.0100
b2(:,:,5) =
0.0000
0.0000
0.0100
b2(:,:,6) =
0.0000
0.0000
0.0100
b2(:,:,7) =
0.0000
0.0001
0.0100
b2(:,:,8) =
0.0000
0.0000
0.0100
b2(:,:,9) =
0.0000
0.0000
0.0100
b2(:,:,10) =
0.0000
0.0000
0.0099
.