I have created code for banded gauss elimination method but on running it gives an error of index exceeds matrix dimensions

3 Ansichten (letzte 30 Tage)
function x = gauss_elimination(K,M);
ln = length(M); x = zeros(ln,1);
for n=1:ln-1
for i=n+1:ln
m = K(i,n)/K(n,n);
for j=n+1:ln
K(i,j) = K(i,j)-m*K(n,j);
end
M(i) = M(i)-m*M(n);
end
end
x(ln) = M(ln)/K(ln,ln);
for i=ln-1:-1:1
S = M(i);
for j=i+1:ln
S = S-K(i,j)*x(j);
end
x(i) = S/K(i,i);
end
end
%%another function created to call gauss elimination function in it
clc
clear
%Two additional matrices A and B were added for checking the gauss elimination
%function:
A= [ 170.4105 37.9473 -113.8420 -37.9473;
37.9473 69.2176 -37.9473 -12.6491;
-113.8420 -37.9473 120.9131 45.0184;
-37.9473 -12.6491 45.0184 19.7202];
B = [0; 0; 0; -1000];
K = xlsread('HW05_Coef.xlsx');
M = csvread('HW05_Const.csv');
gauss_elimination(K,M)
  4 Kommentare
Haseeb Ahmed Janjua
Haseeb Ahmed Janjua am 20 Okt. 2017
Bearbeitet: Haseeb Ahmed Janjua am 20 Okt. 2017
it gives me the error of index exceeds matrix dimensions when im reading matrix from csv files And my K in csv file is 1092x1 and M is 1092x46

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Martin Olafsen
Martin Olafsen am 20 Okt. 2017
You use the length of M to iterate through the matrices, even though the amount of rows is different from the amount of columns in K.

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by