<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://mediawiki.zeropage.org/index.php?action=history&amp;feed=atom&amp;title=CubicSpline%2F1002%2FLuDecomposition.py</id>
	<title>CubicSpline/1002/LuDecomposition.py - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://mediawiki.zeropage.org/index.php?action=history&amp;feed=atom&amp;title=CubicSpline%2F1002%2FLuDecomposition.py"/>
	<link rel="alternate" type="text/html" href="https://mediawiki.zeropage.org/index.php?title=CubicSpline/1002/LuDecomposition.py&amp;action=history"/>
	<updated>2026-05-15T09:46:26Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.39.8</generator>
	<entry>
		<id>https://mediawiki.zeropage.org/index.php?title=CubicSpline/1002/LuDecomposition.py&amp;diff=31023&amp;oldid=prev</id>
		<title>imported&gt;Unknown at 05:23, 7 February 2021</title>
		<link rel="alternate" type="text/html" href="https://mediawiki.zeropage.org/index.php?title=CubicSpline/1002/LuDecomposition.py&amp;diff=31023&amp;oldid=prev"/>
		<updated>2021-02-07T05:23:03Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt; from Numeric import *&lt;br /&gt;
 from ArrayPrinter import *&lt;br /&gt;
 &lt;br /&gt;
 class LuDecomposition:&lt;br /&gt;
 	def __init__(self, aSquareArray):&lt;br /&gt;
 		assert len(aSquareArray) == len(aSquareArray[0])&lt;br /&gt;
 		self.array = aSquareArray&lt;br /&gt;
 		self.n = len(aSquareArray)&lt;br /&gt;
 &lt;br /&gt;
 		self.l = self.makeEmptySquareMatrix(self.n)&lt;br /&gt;
 		self.u = self.makeEmptySquareMatrix(self.n)&lt;br /&gt;
 &lt;br /&gt;
 		for i in range(self.n):&lt;br /&gt;
 			self.u[i][i] = 1.0&lt;br /&gt;
 &lt;br /&gt;
 	def makeEmptySquareMatrix(self, n):&lt;br /&gt;
 		matrix = []&lt;br /&gt;
 		for i in range(0,n):&lt;br /&gt;
 			row = []&lt;br /&gt;
 			for j in range(0,n):&lt;br /&gt;
 				row.append(0.0)&lt;br /&gt;
 			matrix.append(row)&lt;br /&gt;
 		return matrix&lt;br /&gt;
 &lt;br /&gt;
 	def perform(self):&lt;br /&gt;
 		for i in range(self.n):&lt;br /&gt;
 			self._writeL(i)&lt;br /&gt;
 			self._writeU(i)&lt;br /&gt;
 		return self.l, self.u&lt;br /&gt;
 &lt;br /&gt;
 	def _writeL(self, aCol):&lt;br /&gt;
 		for eachRow in range(aCol, self.n):&lt;br /&gt;
 			self.l[eachRow][aCol] = self.array[eachRow][aCol] - self._minusForWriteL(eachRow, aCol)&lt;br /&gt;
 &lt;br /&gt;
 	def _minusForWriteL(self, aRow, aCol):&lt;br /&gt;
 		totalMinus = 0&lt;br /&gt;
 		for n in range(0, aCol):&lt;br /&gt;
 			totalMinus += self.l[aRow][n] * self.u[n][aCol]&lt;br /&gt;
 		return totalMinus&lt;br /&gt;
 &lt;br /&gt;
 	def _writeU(self, aRow):&lt;br /&gt;
 		for eachCol in range(aRow+1, self.n):&lt;br /&gt;
 			self.u[aRow][eachCol] = float(self.array[aRow][eachCol] - self._minusForWriteU(eachCol, aRow)) / float(self.l[aRow][aRow]) &lt;br /&gt;
 &lt;br /&gt;
 	def _minusForWriteU(self, aCol, aRow):&lt;br /&gt;
 		totalMinus = 0&lt;br /&gt;
 		for n in range(0, aRow):&lt;br /&gt;
 			totalMinus += self.l[aRow][n] * self.u[n][aCol]&lt;br /&gt;
 		return totalMinus&lt;br /&gt;
 &lt;br /&gt;
 	def _getL(self): &lt;br /&gt;
 		return self.l&lt;br /&gt;
 &lt;br /&gt;
 	def _getU(self):&lt;br /&gt;
 		return self.u&lt;br /&gt;
 &lt;br /&gt;
 if __name__==&amp;quot;__main__&amp;quot;:&lt;br /&gt;
 		a = [[1.0,2.0,3.0],[4.0,5.0,6.0],[7.0,8.0,9.0]]&lt;br /&gt;
 		l, u = LuDecomposition(a).perform()&lt;br /&gt;
 		print &amp;quot;array : &amp;quot;&lt;br /&gt;
 		print array2string(array(a))&lt;br /&gt;
 		print &amp;quot;Lu Decomposition - L&amp;quot; &lt;br /&gt;
 		print array2string(array(l))&lt;br /&gt;
 		print &amp;quot;Lu Decomposition - U&amp;quot;&lt;br /&gt;
 		print array2string(array(u))&lt;/div&gt;</summary>
		<author><name>imported&gt;Unknown</name></author>
	</entry>
</feed>