Non-Pivoting Gaussian Elimination Exceeding Rows help?

Evening,
But seriously, lets cut to the chase, Walter,
I don't understand why my non-pivoting Guassian elim. loop is saying that my position 1 exceeds my array bound of 4.
Here is the code:
function Aa = gaussq(A, b)
A
n = 100;
for j = 1: 1: n
p = A(j,j)
for i = j+1: 1: n
M = A(i,j)/p
A(i,:) = A(i,:) - M*A(j,:)
b(i) = b(i) - M*b(j)
end
end
end
The input:
gaussq( [1 1 1 0; -1 1 0 1; -1 2 1 1; 0 0 1 2], [1;2;3;3])
The error:
"Index in position 1 exceeds array bounds (must not exceed 4)."
How are my rows reaching 5? Doesn't it reset after the nested for loop is done with the 1st column (after two iterations)?

 Réponse acceptée

Yakub Shalmiyev
Yakub Shalmiyev le 1 Oct 2018

0 votes

Yes, hello young scholar, it is I, Walter Roberson, Master of Matlab You see, you freakin' goombaya, you were doing too many iterations by setting n = 100. that is all, thanks

Plus de réponses (1)

Walter Roberson
Walter Roberson le 29 Mar 2019

0 votes

Your n should not be greater than min(size(A,1),size(A,2))

3 commentaires

Well thank you for the answer, although unneeded and extremely delayed.
How did you even find this question still? haha
Cheers
You had tagged it with my name and I was cleaning up tags.
You are a boon to MATlabians Walter,
Thank you

Connectez-vous pour commenter.

Catégories

Tags

Aucun tag saisi pour le moment.

Community Treasure Hunt

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

Start Hunting!

Translated by