Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/Math-Matrix/PMMatrix.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,27 @@ PMMatrix >> qrFactorizationWithPivoting [
^ Array with: q with: r with: pivot
]

{ #category : #operation }
PMMatrix >> raisedTo: aPower [

" Answers the receiver raised to a power, aPower .
If aPower is negative, inverse of the receiver is raised to the absolute value of aPower."

|aRaisedPMMatrix|

self assert: self isSquare description: 'Matrix should be square'.

aPower < 0 ifTrue: [
^ self inverse raisedTo: aPower abs ].

aRaisedPMMatrix := PMMatrix identity: self numberOfRows.

1 to: aPower do: [ :each |
aRaisedPMMatrix := aRaisedPMMatrix * self ].

^ aRaisedPMMatrix
]

{ #category : #'as yet unclassified' }
PMMatrix >> rank [
^ ((self numberOfRows < self numberOfColumns
Expand Down
50 changes: 50 additions & 0 deletions src/Math-Tests-Matrix/PMMatrixTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,56 @@ PMMatrixTest >> testPrintOn [
m printOn: stream
]

{ #category : #tests }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are great tests! Well done. My only suggestions are formatting to Arrange Act Assert.

PMMatrixTest >> testRaisedToNegativeInteger [

|aPMMatrix expected|

aPMMatrix := PMMatrix rows: #(#(3 1) #(1 1)).

aPMMatrix := aPMMatrix raisedTo: -2.

expected := PMMatrix rows: #(#(0.5 -1) #(-1 2.5)).
self assert: aPMMatrix equals: expected.
]

{ #category : #tests }
PMMatrixTest >> testRaisedToNonSquareMatrix [

|aPMMatrix|

aPMMatrix := PMMatrix rows: #(#(3 1 4) #(1 1 2)).

self should: [ aPMMatrix raisedTo: 3 ] raise: AssertionFailure.

]

{ #category : #tests }
PMMatrixTest >> testRaisedToPositiveInteger [

|aPMMatrix expected|

aPMMatrix := PMMatrix rows: #(#(3 1) #(1 1)).

aPMMatrix := aPMMatrix raisedTo: 3.

expected := PMMatrix rows: #(#(34 14) #(14 6)).
self assert: aPMMatrix equals: expected.
]

{ #category : #tests }
PMMatrixTest >> testRaisedToZero [

|aPMMatrix expected|

aPMMatrix := PMMatrix rows: #(#(3 1) #(1 1)).

aPMMatrix := aPMMatrix raisedTo: 0.

expected := PMMatrix rows: #( #(1 0) #(0 1)).
self assert: aPMMatrix equals: expected.
]

{ #category : #comparing }
PMMatrixTest >> testRowsColumns [
| a |
Expand Down