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

3 ビュー (過去 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
Walter Roberson
Walter Roberson 2017 年 10 月 20 日
Your code assumes that K is square and that M is a vector.

サインインしてコメントする。

回答 (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 Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by