diff --git a/src/Math-AutomaticDifferenciation/PMDualNumber.class.st b/src/Math-AutomaticDifferenciation/PMDualNumber.class.st index 6033766d7..678819c22 100644 --- a/src/Math-AutomaticDifferenciation/PMDualNumber.class.st +++ b/src/Math-AutomaticDifferenciation/PMDualNumber.class.st @@ -137,7 +137,7 @@ PMDualNumber >> asInteger [ PMDualNumber >> conjugated [ ^ self class value: self value conjugated - eps: self eps asComplex conjugated + eps: self eps asComplex complexConjugate ] { #category : #'mathematical functions' } diff --git a/src/Math-Complex/PMComplex.class.st b/src/Math-Complex/PMComplex.class.st index ad1b0debb..50593e8bd 100644 --- a/src/Math-Complex/PMComplex.class.st +++ b/src/Math-Complex/PMComplex.class.st @@ -169,18 +169,18 @@ PMComplex >> - anObject [ ] { #category : #arithmetic } -PMComplex >> / anObject [ +PMComplex >> / aNumber [ "Answer the result of dividing receiver by aNumber" | a b c d newReal newImaginary | - anObject isComplexNumber ifTrue: + aNumber isComplexNumber ifTrue: [a := self real. b := self imaginary. - c := anObject real. - d := anObject imaginary. + c := aNumber real. + d := aNumber imaginary. newReal := ((a * c) + (b * d)) / ((c * c) + (d * d)). newImaginary := ((b * c) - (a * d)) / ((c * c) + (d * d)). - ^ PMComplex real: newReal imaginary: newImaginary]. - ^ anObject adaptToComplex: self andSend: #/. + ^ self class real: newReal imaginary: newImaginary]. + ^ aNumber adaptToComplex: self andSend: #/. ] { #category : #comparing } @@ -403,11 +403,24 @@ PMComplex >> asComplex [ ^self ] +{ #category : #arithmetic } +PMComplex >> complexConjugate [ + + ^ self class real: real imaginary: imaginary negated +] + { #category : #arithmetic } PMComplex >> conjugated [ + "Return the complex conjugate of this complex number." - ^self class real: real imaginary: imaginary negated + self + deprecated: 'Use #complexConjugate instead' + on: '3 April 2022' + in: + 'Pharo-9.0.0+build.1575.sha.9bb5f998e8a6d016ec7abde3ed09c4a60c0b4551 (64 Bit)'. + + ^ self complexConjugate ] { #category : #'mathematical functions' } @@ -694,14 +707,15 @@ PMComplex >> sinh [ { #category : #'mathematical functions' } PMComplex >> sqrt [ + "Return the square root of the receiver with a positive imaginary part." | u v | - (imaginary = 0 and: [real >= 0]) - ifTrue: [^self class real: real sqrt imaginary: 0]. + (imaginary = 0 and: [ real >= 0 ]) ifTrue: [ + ^ self class real: real sqrt imaginary: 0 ]. v := (self abs - real / 2) sqrt. u := imaginary / 2 / v. - ^self class real: u imaginary: v + ^ self class real: u imaginary: v ] { #category : #'mathematical functions' } diff --git a/src/Math-Complex/PMComplex.extension.st b/src/Math-Complex/PMComplex.extension.st index 5cf918b4d..efe456833 100644 --- a/src/Math-Complex/PMComplex.extension.st +++ b/src/Math-Complex/PMComplex.extension.st @@ -17,13 +17,6 @@ PMComplex >> productWithVector: aVector [ ^ aVector collect: [ :each | each * self ] ] -{ #category : #'*Math-Complex' } -PMComplex >> random [ - "analog to Number>>random. However, the only bound is that the abs of the produced complex is less than the length of the receive. The receiver effectively defines a disc within which the random element can be produced." - ^ self class random * self - -] - { #category : #'*Math-Complex' } PMComplex class >> random [ "Answers a random number with abs between 0 and 1." @@ -31,6 +24,13 @@ PMComplex class >> random [ ^ self abs: 1.0 random arg: 2 * Float pi random ] +{ #category : #'*Math-Complex' } +PMComplex >> random [ + "analog to Number>>random. However, the only bound is that the abs of the produced complex is less than the length of the receive. The receiver effectively defines a disc within which the random element can be produced." + ^ self class random * self + +] + { #category : #'*Math-Complex' } PMComplex >> subtractToPolynomial: aPolynomial [ ^ aPolynomial addNumber: self negated diff --git a/src/Math-Tests-AutomaticDifferenciation/PMDualNumberTest.class.st b/src/Math-Tests-AutomaticDifferenciation/PMDualNumberTest.class.st index 3809029b6..1298678fc 100644 --- a/src/Math-Tests-AutomaticDifferenciation/PMDualNumberTest.class.st +++ b/src/Math-Tests-AutomaticDifferenciation/PMDualNumberTest.class.st @@ -89,7 +89,7 @@ PMDualNumberTest >> testConjugated [ self assert: a value equals: z value absSquared. self assert: a eps - equals: z eps asComplex conjugated * z value + (z value asComplex conjugated * z eps) + equals: z eps asComplex complexConjugate * z value + (z value asComplex conjugated * z eps) ] { #category : #tests } diff --git a/src/Math-Tests-Complex/PMComplexTest.class.st b/src/Math-Tests-Complex/PMComplexTest.class.st index 93dc7b80b..04cb73aaa 100644 --- a/src/Math-Tests-Complex/PMComplexTest.class.st +++ b/src/Math-Tests-Complex/PMComplexTest.class.st @@ -194,12 +194,14 @@ PMComplexTest >> testComplexCollection [ ] { #category : #tests } -PMComplexTest >> testConjugated [ - | c cc | - c := 5 - 6 i. - cc := c conjugated. - self assert: cc real equals: c real. - self assert: cc imaginary equals: c imaginary negated +PMComplexTest >> testComplexConjugate [ + | z complexConjugateOfZ expected | + z := 5 - 6 i. + + complexConjugateOfZ := z complexConjugate . + + expected := 5 + 6 i. + self assert: complexConjugateOfZ equals: expected. ] { #category : #tests } @@ -486,7 +488,7 @@ PMComplexTest >> testNumberAsComplex [ minusOne := -1 asComplex. self assert: minusOne real equals: -1. self assert: minusOne imaginary equals: 0. - self assert: minusOne conjugated equals: minusOne. + self assert: minusOne complexConjugate equals: minusOne. self assert: minusOne sqrt equals: 1 i ]