MATLAB: How to solve this? As i’m getting error when i run this.

linear equation

a=[3 7 -2 3 -1; 4 0 0 0 5; 0 0 5 -4 1; 2 0 9 4 3; 0 0 0 5 8];
b=[37;40;12;14;20];
c=[a b]
np=size(c);
n=np(2);
for k=1:n
for m=k+1:n+1
c(k,m)=c(k,m)/c(k,k);
end
c(k,k)=1;
for l=1:n
if l~=k
for m=k+1:n+1
c(l,m)=c(l,m)-c(l,k)*c(k,m);
end
c(l,k)=0;
end
end
end
c
Error as shown: Index exceeds matrix dimensions.
Error in line 9 c(k,m)=c(k,m)/c(k,k);
Solving the linear equation without using "rref".

Best Answer

Message (red text):
Index exceeds matrix dimensions.
Error in [script name] (line ##)
c(k,m)=c(k,m)/c(k,k);
When your code crashes, your ā€˜cā€™ matrix has size (5x6) and ā€˜m=7ā€™.
Related Question