@@ -157,34 +157,47 @@ PMMatrixTest >> testDimension [
157157PMMatrixTest >> testEigenvalues [
158158 " Code Example 8.15"
159159
160- | m charPol roots eigenvalues finder |
161- m := PMMatrix rows: #(#(3 -2 0) #(-2 7 1) #(0 1 5) ).
162- charPol := PMPolynomial coefficients: #(82 -66 15 -1) .
163- roots := charPol roots asSortedCollection asArray reverse.
164- finder := PMJacobiTransformation matrix: m.
160+ | matrix expectedEigenvalues eigenvalues finder |
161+
162+ matrix := PMMatrix rows: #(
163+ (3 -2 0)
164+ (- 2 7 1 )
165+ (0 1 5 )).
166+
167+ expectedEigenvalues := #(8.105482616526306 4.776537928330764 2.1179794551429305) .
168+
169+ finder := PMJacobiTransformation matrix: matrix.
165170 finder desiredPrecision: 1.0e-09 .
171+
166172 eigenvalues := finder evaluate.
167- self assert: eigenvalues size equals: 3 .
168- self assert: ((roots at: 1 ) - (eigenvalues at: 1 )) abs < 1.0e-09 .
169- self assert: ((roots at: 2 ) - (eigenvalues at: 2 )) abs < 1.0e-09 .
170- self assert: ((roots at: 3 ) - (eigenvalues at: 3 )) abs < 1.0e-09
173+
174+ eigenvalues with: expectedEigenvalues do: [ :actual :expected |
175+ self assert: actual closeTo: expected ].
171176]
172177
173178{ #category : #' linear algebra' }
174179PMMatrixTest >> testEigenvaluesLargest [
175180 " Code Example 8.13"
176181
177- | m charPol roots eigenvalue finder |
178- m := PMMatrix rows: #(#(3 -2 0) #(-2 7 1) #(0 1 5) ).
179- charPol := PMPolynomial coefficients: #(82 -66 15 -1) .
180- roots := charPol roots asSortedCollection asArray reverse.
181- finder := PMLargestEigenValueFinder matrix: m.
182+ | matrix expectedEigenvalues firstEigenvalue secondEigenvalue finder |
183+
184+ matrix := PMMatrix rows: #(
185+ (3 -2 0)
186+ (- 2 7 1 )
187+ (0 1 5 )).
188+
189+ expectedEigenvalues := #(8.105482616526306 4.776537928330764 2.1179794551429305) .
190+
191+ finder := PMLargestEigenValueFinder matrix: matrix.
182192 finder desiredPrecision: 1.0e-08 .
183- eigenvalue := finder evaluate.
184- self assert: ((roots at: 1 ) - eigenvalue) abs < 1.0e-08 .
193+
194+ firstEigenvalue := finder evaluate.
195+
185196 finder := finder nextLargestEigenValueFinder.
186- eigenvalue := finder evaluate.
187- self assert: ((roots at: 2 ) - eigenvalue) abs < 1.0e-08
197+ secondEigenvalue := finder evaluate.
198+
199+ self assert: firstEigenvalue closeTo: expectedEigenvalues first.
200+ self assert: secondEigenvalue closeTo: expectedEigenvalues second.
188201]
189202
190203{ #category : #tests }
@@ -215,6 +228,30 @@ PMMatrixTest >> testIdentityMatrix [
215228 self assert: identityMatrix equals: expectedIdentityMatrix.
216229]
217230
231+ { #category : #' linear algebra' }
232+ PMMatrixTest >> testInversePureCRLSingularMatrixError [
233+
234+ self
235+ should: [ (PMSymmetricMatrix rows: #((1 2 3) (2 2 2 )(3 2 1 ))) inversePureCRL ]
236+ raise: PMSingularMatrixError .
237+ ]
238+
239+ { #category : #' linear algebra' }
240+ PMMatrixTest >> testInversePureLUPSingularMatrixError [
241+
242+ self
243+ should: [ (PMSymmetricMatrix rows: #((1 2 3) (2 2 2 )(3 2 1 ))) inversePureLUP ]
244+ raise: PMSingularMatrixError .
245+ ]
246+
247+ { #category : #' linear algebra' }
248+ PMMatrixTest >> testInverseSingularMatrixError [
249+
250+ self
251+ should: [ (PMMatrix rows: #((1 2 3) (3 4 6 ))) inverse ]
252+ raise: PMSingularMatrixError .
253+ ]
254+
218255{ #category : #tests }
219256PMMatrixTest >> testIsRealOnComplexMatrix [
220257 | matrix |
@@ -757,22 +794,6 @@ PMMatrixTest >> testSimpleMatrixOperations [
757794 self assert: m transpose * m equals: m squared
758795]
759796
760- { #category : #' linear algebra' }
761- PMMatrixTest >> testSingularMatrixError [
762- |h f |
763- h: = PMHistogram new .
764- h freeExtent: true .
765- 1 to: 3 do: [:i | h accumulate: i ].
766- f: = PMLeastSquareFit histogram: h distributionClass: PMTriangularDistribution .
767- self should: [ f evaluate ] raise: PMSingularMatrixError .
768- " and not something completely incomprehensible"
769- " also here:"
770- self should: [ f errorMatrix ] raise: PMSingularMatrixError .
771- self should: [(PMMatrix rows: #((1 2 3) (3 4 6 )))inverse] raise: PMSingularMatrixError .
772- self should: [(PMSymmetricMatrix rows: #((1 2 3) (2 2 2 )(3 2 1 )))inversePureLUP] raise: PMSingularMatrixError .
773- self should: [(PMSymmetricMatrix rows: #((1 2 3) (2 2 2 )(3 2 1 )))inversePureCRL] raise: PMSingularMatrixError .
774- ]
775-
776797{ #category : #tests }
777798PMMatrixTest >> testSkalarMultiplication [
778799 | a r |
0 commit comments