필터 지우기
필터 지우기

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