Generate a loop with Guassian Elimination for multiple values of one variable

2 Ansichten (letzte 30 Tage)
Josh
Josh am 12 Feb. 2016
Bearbeitet: Marc am 12 Feb. 2016
I'm trying to generate a loop that solves a system of equations in the matrix form Ax=b that has a solution vector x that then populates a 15 column solution matrix using all 401 possible values for F1. I've transposed my solution vector x but it currently only populates as a 1x15 with the final value of F1 which is 200.
F1 = 0:0.5:200;
F2 = 55;
F3 = 35;
%input left side of equilibrium equations
A = [1 1 0 0 0 0 0 0 0 0 0 0 0 0 0;
1 0 0 (1/sqrt(2)) 0 0 0 0 0 0 0 0 0 0 0;
0 0 0 1 (1/sqrt(2)) 0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 (3/sqrt(13)) 1 0 0 0 0 0 0 0 0;
0 0 -1 0 1 (2/sqrt(13)) 0 0 0 0 0 0 0 0 0;
0 0 0 0 -1 0 0 1 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 1 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 (3/sqrt(13)) 1 0 0 0 0;
0 0 0 0 0 0 0 -1 0 -(2/sqrt(13)) 0 1 0 0 0;
0 0 0 0 0 0 0 0 0 0 0 0 (1/sqrt(2)) -(2/sqrt(5)) 0;
0 0 0 0 0 0 0 0 0 0 -1 0 -(1/sqrt(2)) (1/sqrt(5)) 0;
0 0 0 0 0 -(2/sqrt(13)) 0 0 0 (2/sqrt(13)) 0 0 0 (2/sqrt(5)) -(2/sqrt(5));
0 0 0 0 0 -(3/sqrt(13)) 0 0 -1 -(3/sqrt(13)) 0 0 0 -(1/sqrt(5)) -(1/sqrt(5));
0 0 0 -(1/sqrt(2)) 0 0 0 0 0 0 0 0 0 0 (2/sqrt(5));
0 0 0 -(1/sqrt(2)) 0 0 -1 0 0 0 0 0 0 0 (1/sqrt(5))];
%setup loop to solve equilibrium equations
for n = 1:length(F1);
%input right side of equilibrium equations
b = [F1(n)+F2+F3;
0;
0;
F1(n);
0;
0;
F2;
F3;
0;
0;
0;
0;
0;
0;
0];
x = (A\b)';
end

Antworten (1)

Marc
Marc am 12 Feb. 2016
Bearbeitet: Marc am 12 Feb. 2016
All you are missing is preallocation of your solution matrix outside the loop.
solnMat = zeros(length(F1),15);
Inside the loop you can put your x's into solnMat
solnMat(i,:) = x;
Should give you a big solution matrix with all 401 x's.

Kategorien

Mehr zu Mathematics and Optimization finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by