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

1 vue (au cours des 30 derniers jours)
Josh
Josh le 12 Fév 2016
Modifié(e) : Marc le 12 Fév 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

Réponses (1)

Marc
Marc le 12 Fév 2016
Modifié(e) : Marc le 12 Fév 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.

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by