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 个评论
回答(1 个)
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!