How do you generalize a function with matrix dimensions increasing?

2 次查看(过去 30 天)
This is the code I have. Is there any way to generalize the matrix A so it increases from a 1x1 to a 2x2 then a 3x3 and so on instead of writing out each matrix separately? I don't understand how to create a general code to create a matrix that increases as show below...
SP = xlsread('Shift Factor Data',-1);
SPj = SP(1:end);
MCC = xlsread('Shift Factor Data',-1);
MCCj = MCC(1:end);
A1 = SPj(1,1);
B1 = -MCCj(1,1);
X1 = A1\B1;
A2 = [SPj(1,1) 0; SPj(1,1) SPj(2,1)];
B2 = [-MCCj(1,1); -MCCj(2,1)];
X2 = A2\B2;
A3 = [SPj(1,1) 0 0; SPj(1,1) SPj(2,1) 0; SPj(1,1) SPj(2,1) SPj(3,1)];
B3 = [-MCCj(1,1); -MCCj(2,1); -MCCj(3,1)];
X3 = A3\B3;
A4 = [SPj(1,1) 0 0 0; SPj(1,1) SPj(2,1) 0 0; SPj(1,1) SPj(2,1) SPj(3,1) 0; SPj(1,1) SPj(2,1) SPj(3,1) SPj(4,1)];
B4 = [-MCCj(1,1); -MCCj(2,1); -MCCj(3,1); -MCCj(4,1)];
X4 = A4\B4
[m,n] = size(A4);
Abar = A4(:,1:n-1);
Xbar = X4(1:n-1,:);
X = (B4-(Abar*Xbar))/(A4(:,n));
Shift_Factor = X(n,n)

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by