Saturday, October 10, 2009

matlab : sample Gauss Elimination


A = [ 2 1 -1 8; -3 -1 2 -11; -2 1 2 -3]

m = 3
n = 4

i = 1

adds=0 %just counting the additions
mults=0 % just counting the multiplications

while i < m
j = i+1
while j <= m
temp = -(A(j,i)/A(i,i))
k = i
while k <= n
A(j,k) = A(j,k) + A(i,k)*temp
adds=adds+1
mults=mults+1
k=k+1
end
j=j+1
end
i=i+1
end
A

No comments:

Post a Comment