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

1 次查看(过去 30 天)
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 个评论
Haseeb Ahmed Janjua
Haseeb Ahmed Janjua 2017-10-20
编辑:Haseeb Ahmed Janjua 2017-10-20
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

请先登录,再进行评论。

回答(1 个)

Martin Olafsen
Martin Olafsen 2017-10-20
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.

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by