From 9d9e43be2b8fbdc443e1a12e91bb6cd617926322 Mon Sep 17 00:00:00 2001 From: DurieuxPol Date: Fri, 20 Feb 2026 11:01:31 +0100 Subject: [PATCH 1/2] handle special case for single value matrix --- src/Math-Matrix/PMMatrix.class.st | 2 ++ src/Math-Matrix/PMSingleValueMatrixHelper.class.st | 13 +++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 src/Math-Matrix/PMSingleValueMatrixHelper.class.st diff --git a/src/Math-Matrix/PMMatrix.class.st b/src/Math-Matrix/PMMatrix.class.st index 5a57326..125e781 100644 --- a/src/Math-Matrix/PMMatrix.class.st +++ b/src/Math-Matrix/PMMatrix.class.st @@ -498,6 +498,8 @@ PMMatrix >> eigen [ matrix eigen values. matrix eigen vectors." + self numberOfColumns == 1 & self numberOfRows == 1 ifTrue: [ ^ PMSingleValueMatrixHelper matrix: self ]. + self isSymmetric ifTrue: [ ^ self asSymmetricMatrix eigen ] ifFalse: [ self error: 'Eigenvalues and eigenvectors of non-symmetric matrix are currently not supported' ] diff --git a/src/Math-Matrix/PMSingleValueMatrixHelper.class.st b/src/Math-Matrix/PMSingleValueMatrixHelper.class.st new file mode 100644 index 0000000..34dfdb5 --- /dev/null +++ b/src/Math-Matrix/PMSingleValueMatrixHelper.class.st @@ -0,0 +1,13 @@ +Class { + #name : 'PMSingleValueMatrixHelper', + #superclass : 'PMJacobiTransformationHelper', + #category : 'Math-Matrix', + #package : 'Math-Matrix' +} + +{ #category : 'initialization' } +PMSingleValueMatrixHelper >> initialize: aSingleValueMatrix [ + + eigenvalues := Array with: (aSingleValueMatrix at: 1 at: 1). + eigenvectors := PMVector with: (PMVector ones: 1) +] From 2e645ab3c3fbfd24f27540d2937063c74abfc8db Mon Sep 17 00:00:00 2001 From: DurieuxPol Date: Fri, 20 Feb 2026 11:10:17 +0100 Subject: [PATCH 2/2] test --- src/Math-Matrix-Tests/PMMatrixTest.class.st | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/Math-Matrix-Tests/PMMatrixTest.class.st b/src/Math-Matrix-Tests/PMMatrixTest.class.st index 57e7c84..8e82e8b 100644 --- a/src/Math-Matrix-Tests/PMMatrixTest.class.st +++ b/src/Math-Matrix-Tests/PMMatrixTest.class.st @@ -163,6 +163,22 @@ PMMatrixTest >> testDimension [ ] +{ #category : 'linear algebra' } +PMMatrixTest >> testEigenForSingleValueMatrix [ + + | matrix expectedEigenvalues eigenvalues expectedEigenvectors eigenvectors | + matrix := PMMatrix rows: #( #( 3 ) ). + + expectedEigenvalues := #( 3 ). + expectedEigenvectors := PMVector with: (PMVector ones: 1). + + eigenvalues := matrix eigen values. + eigenvectors := matrix eigen vectors. + + eigenvalues with: expectedEigenvalues do: [ :actual :expected | self assert: actual closeTo: expected ]. + eigenvectors with: expectedEigenvectors do: [ :actual :expected | self assert: actual closeTo: expected ] +] + { #category : 'linear algebra' } PMMatrixTest >> testEigenvalues [ "Code Example 8.15"