<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: C Gaussian Elimination Implementation</title>
	<atom:link href="http://silveiraneto.net/2008/12/09/c-gaussian-elimination-implementation/feed/" rel="self" type="application/rss+xml" />
	<link>http://silveiraneto.net/2008/12/09/c-gaussian-elimination-implementation/</link>
	<description></description>
	<lastBuildDate>Fri, 09 Mar 2012 04:14:35 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Done</title>
		<link>http://silveiraneto.net/2008/12/09/c-gaussian-elimination-implementation/comment-page-1/#comment-6322</link>
		<dc:creator>Done</dc:creator>
		<pubDate>Sun, 07 Nov 2010 11:09:26 +0000</pubDate>
		<guid isPermaLink="false">http://silveiraneto.net/?p=1896#comment-6322</guid>
		<description>full of error</description>
		<content:encoded><![CDATA[<p>full of error</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Done</title>
		<link>http://silveiraneto.net/2008/12/09/c-gaussian-elimination-implementation/comment-page-1/#comment-6321</link>
		<dc:creator>Done</dc:creator>
		<pubDate>Sun, 07 Nov 2010 10:55:57 +0000</pubDate>
		<guid isPermaLink="false">http://silveiraneto.net/?p=1896#comment-6321</guid>
		<description>have you declared the variable &#039;line&#039;?

 for (row=0; row&lt;ROWS; line++) // causes error.</description>
		<content:encoded><![CDATA[<p>have you declared the variable &#8216;line&#8217;?</p>
<p> for (row=0; row&lt;ROWS; line++) // causes error.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: T</title>
		<link>http://silveiraneto.net/2008/12/09/c-gaussian-elimination-implementation/comment-page-1/#comment-3501</link>
		<dc:creator>T</dc:creator>
		<pubDate>Mon, 16 Feb 2009 05:21:21 +0000</pubDate>
		<guid isPermaLink="false">http://silveiraneto.net/?p=1896#comment-3501</guid>
		<description>I&#039;m not the only one who finds amusement in the irony of the C version being shorter and clearer than the Python one, am I?</description>
		<content:encoded><![CDATA[<p>I&#8217;m not the only one who finds amusement in the irony of the C version being shorter and clearer than the Python one, am I?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: A</title>
		<link>http://silveiraneto.net/2008/12/09/c-gaussian-elimination-implementation/comment-page-1/#comment-3256</link>
		<dc:creator>A</dc:creator>
		<pubDate>Mon, 22 Dec 2008 17:32:31 +0000</pubDate>
		<guid isPermaLink="false">http://silveiraneto.net/?p=1896#comment-3256</guid>
		<description>I&#039;ll do just a observation: if A and B are matrixes, the operation B/A doesn&#039;t exist. You have to do B*inv(A), in fact if C = inv(A) then C(i,j) = 1/A(i,j) because A is a digonal matrix.

Merry Christmas for everyone!!!
God will help us more in next year!</description>
		<content:encoded><![CDATA[<p>I&#8217;ll do just a observation: if A and B are matrixes, the operation B/A doesn&#8217;t exist. You have to do B*inv(A), in fact if C = inv(A) then C(i,j) = 1/A(i,j) because A is a digonal matrix.</p>
<p>Merry Christmas for everyone!!!<br />
God will help us more in next year!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Silveira</title>
		<link>http://silveiraneto.net/2008/12/09/c-gaussian-elimination-implementation/comment-page-1/#comment-3201</link>
		<dc:creator>Silveira</dc:creator>
		<pubDate>Thu, 11 Dec 2008 16:42:54 +0000</pubDate>
		<guid isPermaLink="false">http://silveiraneto.net/?p=1896#comment-3201</guid>
		<description>Cool! I&#039;ve pasted here:
&lt;pre&gt;
		import sys



		#############

		# Buggy Gauss Elimination

		# (Zero division is not checked)

		#



		def det(rows):

			 v = None

			 

			 if len(rows) == 2:

				  r1 = rows[0]

				  r2 = rows[1]

				  v = r1[0] * r2[1] - r1[1] * r2[0]

			 else:

				  firstRow = rows[0]

				  aboveRows = rows[1:]        

				  subDets = []



				  # At time I din&#039;t know the existence of enumerate

				  for c in range(0, len(firstRow)):

				      subMatrix = []

				      for ar in aboveRows:

				          subRow = []

				          for c2 in range(0, len(ar)):

				              if c != c2:

				                  subRow.append(ar[c2])

				          subMatrix.append(subRow)

				      subDets.append(det(subMatrix) * firstRow[c])

				      

				  evens = [subDets[e] for e in range(0, len(subDets), 2)]

				  odds = [subDets[e] for e in range(1, len(subDets), 2)]



				  v = reduce(lambda x, y: x+y, evens) - reduce(lambda x, y: x+y, odds)        



			 return v

				      

		#non-recursive                

		def solveSystem(rows):

			 if det(rows) == 0:

				  return None

			 

			 zerorColumnNth = 0

			 solvedSystem = rows

			 

			 for workRowNth in range(0, len(rows)-1):

				  for prodRowNth in range(workRowNth+1, len(rows)):

				      workRow = solvedSystem[workRowNth]

				      prodRow = solvedSystem[prodRowNth]

				      

				      mul = -prodRow[zerorColumnNth] / workRow[zerorColumnNth] 

				      newProdRow = map(lambda a, b: a + b, map(lambda x: x*mul, workRow), prodRow)

				      solvedSystem[prodRowNth] = newProdRow

				      

				  zerorColumnNth += 1

				  

			 return solvedSystem

		 

		#recursive   

		def solveSystem2(rows):    

			 def solveLoop(rows, workNth, prodNth, zeroColumn, nrows):            

				  if prodNth &lt; nrows:            

				      workRow = rows[workNth]

				      prodRow = rows[prodNth]

			 

				      mul = -prodRow[zeroColumn] / workRow[zeroColumn] 

				      rows[prodNth] = map(lambda a, b: a + b, map(lambda x: x*mul, workRow), prodRow)

				      return solveLoop(rows, workNth, prodNth+1, zeroColumn, nrows)

				  else:

				      if workNth = 0:

				      row = rs[nth] 

				      vt = [vals[v]*row[v] for v in range(nth+1, len(row)-1)]                

				      if len(vt) &gt; 0:

				          coff = -reduce(lambda a, b: a+b,  vt)

				      else:

				          coff = 0

				          

				      vals[nth] = (coff + row[len(row)-1])/row[nth]

				          

				      return retroLoop(rs, nth-1, vals)

				  return vals

			 

			 nrows = len(rows)

			 return retroLoop(rows, nrows-1, [0 for i in range(0, nrows)])



		if __name__ == &#039;__main__&#039;:

			 try:        

				  f = open(sys.argv[1], &#039;r&#039;)

			 except IOError, msg:

				  print(msg)

				  sys.exit(1)

				  

			 rows = []

			 

			 for line in f:

				  if line != &#039;\n&#039;:

				      atoms = line.split(&#039; &#039;)

				      r = []

				      for a in atoms:

				          r.append(float(a))

				      rows.append(r)



			 f.close();

			 

			 maxColumn = 0

			 for r in rows:

				  cs = len(r)

				  if cs &gt; maxColumn:

				      maxColumn = cs

			 

			 for r in rows:

				  cs = len(r)

				  if cs != maxColumn:

				      print(&quot;Matrix nao quad&quot;)

				      sys.exit(1)



			 ss = solveSystem2(rows)

			 r = retroSub(ss)

			 

			 print(r)



		##############

		# Sample input file:

		#

		# 10 2 3 4 5

		# 6 17 8 9 10

		# 11 12 23 14 15

		# 16 17 18 29 20



		# Should output:

		# [0.28248587570621464, 0.24858757062146891, 0.24293785310734467, 0.23728813559322035]

&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>Cool! I&#8217;ve pasted here:</p>
<pre>
		import sys

		#############

		# Buggy Gauss Elimination

		# (Zero division is not checked)

		#

		def det(rows):

			 v = None

			 if len(rows) == 2:

				  r1 = rows[0]

				  r2 = rows[1]

				  v = r1[0] * r2[1] - r1[1] * r2[0]

			 else:

				  firstRow = rows[0]

				  aboveRows = rows[1:]        

				  subDets = []

				  # At time I din't know the existence of enumerate

				  for c in range(0, len(firstRow)):

				      subMatrix = []

				      for ar in aboveRows:

				          subRow = []

				          for c2 in range(0, len(ar)):

				              if c != c2:

				                  subRow.append(ar[c2])

				          subMatrix.append(subRow)

				      subDets.append(det(subMatrix) * firstRow[c])

				  evens = [subDets[e] for e in range(0, len(subDets), 2)]

				  odds = [subDets[e] for e in range(1, len(subDets), 2)]

				  v = reduce(lambda x, y: x+y, evens) - reduce(lambda x, y: x+y, odds)        

			 return v

		#non-recursive                

		def solveSystem(rows):

			 if det(rows) == 0:

				  return None

			 zerorColumnNth = 0

			 solvedSystem = rows

			 for workRowNth in range(0, len(rows)-1):

				  for prodRowNth in range(workRowNth+1, len(rows)):

				      workRow = solvedSystem[workRowNth]

				      prodRow = solvedSystem[prodRowNth]

				      mul = -prodRow[zerorColumnNth] / workRow[zerorColumnNth] 

				      newProdRow = map(lambda a, b: a + b, map(lambda x: x*mul, workRow), prodRow)

				      solvedSystem[prodRowNth] = newProdRow

				  zerorColumnNth += 1

			 return solvedSystem

		#recursive   

		def solveSystem2(rows):    

			 def solveLoop(rows, workNth, prodNth, zeroColumn, nrows):            

				  if prodNth &lt; nrows:            

				      workRow = rows[workNth]

				      prodRow = rows[prodNth]

				      mul = -prodRow[zeroColumn] / workRow[zeroColumn] 

				      rows[prodNth] = map(lambda a, b: a + b, map(lambda x: x*mul, workRow), prodRow)

				      return solveLoop(rows, workNth, prodNth+1, zeroColumn, nrows)

				  else:

				      if workNth = 0:

				      row = rs[nth] 

				      vt = [vals[v]*row[v] for v in range(nth+1, len(row)-1)]                

				      if len(vt) &gt; 0:

				          coff = -reduce(lambda a, b: a+b,  vt)

				      else:

				          coff = 0

				      vals[nth] = (coff + row[len(row)-1])/row[nth]

				      return retroLoop(rs, nth-1, vals)

				  return vals

			 nrows = len(rows)

			 return retroLoop(rows, nrows-1, [0 for i in range(0, nrows)])

		if __name__ == '__main__':

			 try:        

				  f = open(sys.argv[1], 'r')

			 except IOError, msg:

				  print(msg)

				  sys.exit(1)

			 rows = []

			 for line in f:

				  if line != '\n':

				      atoms = line.split(' ')

				      r = []

				      for a in atoms:

				          r.append(float(a))

				      rows.append(r)

			 f.close();

			 maxColumn = 0

			 for r in rows:

				  cs = len(r)

				  if cs &gt; maxColumn:

				      maxColumn = cs

			 for r in rows:

				  cs = len(r)

				  if cs != maxColumn:

				      print("Matrix nao quad")

				      sys.exit(1)

			 ss = solveSystem2(rows)

			 r = retroSub(ss)

			 print(r)

		##############

		# Sample input file:

		#

		# 10 2 3 4 5

		# 6 17 8 9 10

		# 11 12 23 14 15

		# 16 17 18 29 20

		# Should output:

		# [0.28248587570621464, 0.24858757062146891, 0.24293785310734467, 0.23728813559322035]
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: otavio</title>
		<link>http://silveiraneto.net/2008/12/09/c-gaussian-elimination-implementation/comment-page-1/#comment-3198</link>
		<dc:creator>otavio</dc:creator>
		<pubDate>Thu, 11 Dec 2008 13:12:31 +0000</pubDate>
		<guid isPermaLink="false">http://silveiraneto.net/?p=1896#comment-3198</guid>
		<description>Hi, nice work. Just for language war, some time ago I&#039;ve done a python version:
http://pastebin.com/f17960864</description>
		<content:encoded><![CDATA[<p>Hi, nice work. Just for language war, some time ago I&#8217;ve done a python version:<br />
<a href="http://pastebin.com/f17960864" rel="nofollow">http://pastebin.com/f17960864</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Silveira</title>
		<link>http://silveiraneto.net/2008/12/09/c-gaussian-elimination-implementation/comment-page-1/#comment-3186</link>
		<dc:creator>Silveira</dc:creator>
		<pubDate>Tue, 09 Dec 2008 14:49:38 +0000</pubDate>
		<guid isPermaLink="false">http://silveiraneto.net/?p=1896#comment-3186</guid>
		<description>sombriks, I also wrote a parallel version of gaussian elimination using MPI. My idea now is to benchmark them.</description>
		<content:encoded><![CDATA[<p>sombriks, I also wrote a parallel version of gaussian elimination using MPI. My idea now is to benchmark them.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sombriks</title>
		<link>http://silveiraneto.net/2008/12/09/c-gaussian-elimination-implementation/comment-page-1/#comment-3182</link>
		<dc:creator>sombriks</dc:creator>
		<pubDate>Tue, 09 Dec 2008 12:05:36 +0000</pubDate>
		<guid isPermaLink="false">http://silveiraneto.net/?p=1896#comment-3182</guid>
		<description>nice, i remember what is it now, heh.

where will you apply it??</description>
		<content:encoded><![CDATA[<p>nice, i remember what is it now, heh.</p>
<p>where will you apply it??</p>
]]></content:encoded>
	</item>
</channel>
</rss>

