How do you generalize a function with matrix dimensions increasing?

조회 수: 3 (최근 30일)
Doug
Doug 2012년 7월 31일
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