Borrar filtros
Borrar filtros

Writing a code with the size of the (square) matrix increasing in dimensions

2 visualizaciones (últimos 30 días)
I'm trying to write a code to solve for shift factors. The problem I'm having is that what I need will require the code to solve for 2 variables then 3 then 4 but without the previous variables changing. I need a general code that will first solve 2 variables (2x2 matrix) then 3 variables with the first 2 the same (3x3 matrix) then 4 variables with the first 3 the same (4x4 matrix) and so on. How would I solve for this where the size of the matrix increases and the previously solved variables remain constants?
Here's what I have so far but I need a loop of some sort to make it general.
SP = xlsread('Shift Factor Data',-1);
SPj = SP(1:end);
MCC = xlsread('Shift Factor Data',-1);
MCCj = MCC(1:end);
A = [SPj(1,1) M(1,1); SPj(1,1) SPj(2,1)];
B = [-MCCj(1,1); -MCCj(2,1)];
Shift_Factor = A\B
C = [SPj(1,1) 0 0; SPj(1,1) SPj(2,1) 0; SPj(1,1) SPj(2,1) SPj(3,1)];
D = [-MCCj(1,1); -MCCj(2,1); -MCCj(3,1)];
SF = C\D

Respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by