Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
39
Task/Arithmetic-Complex/PowerShell/arithmetic-complex-1.psh
Normal file
39
Task/Arithmetic-Complex/PowerShell/arithmetic-complex-1.psh
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
class Complex {
|
||||
[Double]$x
|
||||
[Double]$y
|
||||
Complex() {
|
||||
$this.x = 0
|
||||
$this.y = 0
|
||||
}
|
||||
Complex([Double]$x, [Double]$y) {
|
||||
$this.x = $x
|
||||
$this.y = $y
|
||||
}
|
||||
[Double]abs2() {return $this.x*$this.x + $this.y*$this.y}
|
||||
[Double]abs() {return [math]::sqrt($this.abs2())}
|
||||
static [Complex]add([Complex]$m,[Complex]$n) {return [Complex]::new($m.x+$n.x, $m.y+$n.y)}
|
||||
static [Complex]mul([Complex]$m,[Complex]$n) {return [Complex]::new($m.x*$n.x - $m.y*$n.y, $m.x*$n.y + $n.x*$m.y)}
|
||||
[Complex]mul([Double]$k) {return [Complex]::new($k*$this.x, $k*$this.y)}
|
||||
[Complex]negate() {return $this.mul(-1)}
|
||||
[Complex]conjugate() {return [Complex]::new($this.x, -$this.y)}
|
||||
[Complex]inverse() {return $this.conjugate().mul(1/$this.abs2())}
|
||||
[String]show() {
|
||||
if(0 -ge $this.y) {
|
||||
return "$($this.x)+$($this.y)i"
|
||||
} else {
|
||||
return "$($this.x)$($this.y)i"
|
||||
}
|
||||
}
|
||||
static [String]show([Complex]$other) {
|
||||
return $other.show()
|
||||
}
|
||||
}
|
||||
$m = [complex]::new(3, 4)
|
||||
$n = [complex]::new(7, 6)
|
||||
"`$m: $($m.show())"
|
||||
"`$n: $($n.show())"
|
||||
"`$m + `$n: $([complex]::show([complex]::add($m,$n)))"
|
||||
"`$m * `$n: $([complex]::show([complex]::mul($m,$n)))"
|
||||
"negate `$m: $($m.negate().show())"
|
||||
"1/`$m: $([complex]::show($m.inverse()))"
|
||||
"conjugate `$m: $([complex]::show($m.conjugate()))"
|
||||
16
Task/Arithmetic-Complex/PowerShell/arithmetic-complex-2.psh
Normal file
16
Task/Arithmetic-Complex/PowerShell/arithmetic-complex-2.psh
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
function show([System.Numerics.Complex]$c) {
|
||||
if(0 -le $c.Imaginary) {
|
||||
return "$($c.Real)+$($c.Imaginary)i"
|
||||
} else {
|
||||
return "$($c.Real)$($c.Imaginary)i"
|
||||
}
|
||||
}
|
||||
$m = [System.Numerics.Complex]::new(3, 4)
|
||||
$n = [System.Numerics.Complex]::new(7, 6)
|
||||
"`$m: $(show $m)"
|
||||
"`$n: $(show $n)"
|
||||
"`$m + `$n: $(show ([System.Numerics.Complex]::Add($m,$n)))"
|
||||
"`$m * `$n: $(show ([System.Numerics.Complex]::Multiply($m,$n)))"
|
||||
"negate `$m: $(show ([System.Numerics.Complex]::Negate($m)))"
|
||||
"1/`$m: $(show ([System.Numerics.Complex]::Reciprocal($m)))"
|
||||
"conjugate `$m: $(show ([System.Numerics.Complex]::Conjugate($m)))"
|
||||
Loading…
Add table
Add a link
Reference in a new issue