How do you generalize a function with matrix dimensions increasing?
조회 수: 3 (최근 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
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!