From 5d7df1f8472acf4d945634491f0bd1aceece4049 Mon Sep 17 00:00:00 2001 From: Michael Johnson Date: Sun, 15 Feb 2015 20:51:04 +0100 Subject: [PATCH 1/5] =?UTF-8?q?New=20Trigonometric=20and=20Hyperbolic=20fu?= =?UTF-8?q?nctions=20included.=20It=C2=B4s=20not=20totally=20polished.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- classes/src/functions/acoth.php | 27 +++++++++ classes/src/functions/coth.php | 26 +++++++++ classes/src/functions/gudermannian.php | 20 +++++++ classes/src/functions/haversine.php | 31 ++++++++++ classes/src/functions/inversegudermannian.php | 21 +++++++ classes/src/functions/inversehaversine.php | 27 +++++++++ classes/src/functions/tanh.php | 21 +++++++ examples/complexTest2.php | 17 ++++-- examples/complexTest3.php | 56 +++++++++++++++++++ 9 files changed, 241 insertions(+), 5 deletions(-) create mode 100644 classes/src/functions/acoth.php create mode 100644 classes/src/functions/coth.php create mode 100644 classes/src/functions/gudermannian.php create mode 100644 classes/src/functions/haversine.php create mode 100644 classes/src/functions/inversegudermannian.php create mode 100644 classes/src/functions/inversehaversine.php create mode 100644 classes/src/functions/tanh.php create mode 100644 examples/complexTest3.php diff --git a/classes/src/functions/acoth.php b/classes/src/functions/acoth.php new file mode 100644 index 0000000..7c61bd9 --- /dev/null +++ b/classes/src/functions/acoth.php @@ -0,0 +1,27 @@ +getImaginary() == 0.0) { + if ( ( $complex->getReal() == -1 ) || ( $complex->getReal() == 1 ) ) { + return INF; + } else { + $calc = clone $complex; + $complex = $complex->add( 1 ); + $calc = $calc->subtract( 1 ); + $complex = $complex->divideBy( $calc ); + $complex = ln( $complex ); + $complex = $complex->divideBy( 2 ); + return $complex; + } + } +} \ No newline at end of file diff --git a/classes/src/functions/coth.php b/classes/src/functions/coth.php new file mode 100644 index 0000000..e25eea5 --- /dev/null +++ b/classes/src/functions/coth.php @@ -0,0 +1,26 @@ +getImaginary() == 0.0) { + $calc = clone $complex; + $complex = cosh( $complex ); + $calc = sinh( $calc ); + + if ( $calc->getReal() != 0 ) { + $complex = $complex->divideBy( $calc ); + return $complex; + } else { + return null; + } + } +} \ No newline at end of file diff --git a/classes/src/functions/gudermannian.php b/classes/src/functions/gudermannian.php new file mode 100644 index 0000000..9d40692 --- /dev/null +++ b/classes/src/functions/gudermannian.php @@ -0,0 +1,20 @@ +getImaginary() == 0.0) { + $complex = exp( $complex ); + $complex = atan( $complex ); + $complex = $complex->multiply( 2 ); + $complex = $complex->add( -( M_PI/2 ) ); + return $complex; + } +} \ No newline at end of file diff --git a/classes/src/functions/haversine.php b/classes/src/functions/haversine.php new file mode 100644 index 0000000..be86d7f --- /dev/null +++ b/classes/src/functions/haversine.php @@ -0,0 +1,31 @@ +getImaginary() == 0.0) { + $complex = $complex->divideBy( 2 ); + $complex = sin( $complex ); + $complex = $complex->multiply( $complex ); + return $complex; + } +} \ No newline at end of file diff --git a/classes/src/functions/inversegudermannian.php b/classes/src/functions/inversegudermannian.php new file mode 100644 index 0000000..7c5982d --- /dev/null +++ b/classes/src/functions/inversegudermannian.php @@ -0,0 +1,21 @@ +getImaginary() == 0.0) { + $complex = $complex->divideBy( 2 ); + $complex = $complex->add( M_PI/4 ); + $complex = tan( $complex ); + $complex = ln( $complex ); + return $complex; + } +} \ No newline at end of file diff --git a/classes/src/functions/inversehaversine.php b/classes/src/functions/inversehaversine.php new file mode 100644 index 0000000..24afa56 --- /dev/null +++ b/classes/src/functions/inversehaversine.php @@ -0,0 +1,27 @@ +getImaginary() == 0.0 ) { + if (($complex->getReal() >= 0.0) && ($complex->getReal() <= 1.0)) { + $complex = sqrt( $complex ); + $complex = asin( $complex ); + $complex = $complex->multiply( 2 ); + return $complex; + } + } +} \ No newline at end of file diff --git a/classes/src/functions/tanh.php b/classes/src/functions/tanh.php new file mode 100644 index 0000000..be92a71 --- /dev/null +++ b/classes/src/functions/tanh.php @@ -0,0 +1,21 @@ +getImaginary() == 0.0) { + $calc = clone $complex; + $complex = sinh( $complex ); + $calc = cosh( $calc ); + $complex = $complex->divideBy( $calc ); + return $complex; + } +} \ No newline at end of file diff --git a/examples/complexTest2.php b/examples/complexTest2.php index 91c827a..9bf4aa3 100644 --- a/examples/complexTest2.php +++ b/examples/complexTest2.php @@ -4,7 +4,7 @@ include('../classes/Bootstrap.php'); -echo 'Function Examples', PHP_EOL; +echo "

Function Examples


", PHP_EOL; $functions = [ 'abs', @@ -33,7 +33,14 @@ 'sin', 'sinh', 'sqrt', - 'theta' + 'theta', + 'acoth', + 'coth', + 'gudermannian', + 'haversine', + 'inversegudermannian', + 'inversehaversine', + 'tanh' ]; for($real = -3.5; $real <= 3.5; $real += 0.5) { @@ -42,11 +49,11 @@ $complexFunction = __NAMESPACE__ . '\\' . $function; $complex = new Complex($real, $imaginary); try { - echo $function, '(', $complex, ') = ', $complexFunction($complex), PHP_EOL; + echo $function, '(', $complex, ') = ', $complexFunction($complex), "
",PHP_EOL; } catch(\Exception $e) { - echo $function, '(', $complex, ') ERROR: ', $e->getMessage(), PHP_EOL; + echo $function, '(', $complex, ') ERROR: ', $e->getMessage(), "
", PHP_EOL; } } - echo PHP_EOL; + echo "
",PHP_EOL; } } diff --git a/examples/complexTest3.php b/examples/complexTest3.php new file mode 100644 index 0000000..ae99c01 --- /dev/null +++ b/examples/complexTest3.php @@ -0,0 +1,56 @@ +' . PHP_EOL; +echo "

Haversine


" . PHP_EOL; +for ( $i = -10; $i <= 10; $i++ ) { + echo ( $i ) . ': ' . $complexFunction2( $i ) . '
' . PHP_EOL; +} +unset($i); + +echo "

Inverse haversine


" . PHP_EOL; +for ( $i = -10; $i <= 10; $i++ ) { + echo ( $i ) . ': ' . $complexFunction3( $i ) . '
' . PHP_EOL; +} +unset($i); + +echo "

Gudermannian


" . PHP_EOL; +for ( $i = -10; $i <= 10; $i++ ) { + echo ( $i ) . ': ' . $complexFunction4( $i ) . '
' . PHP_EOL; +} +unset($i); + +echo "

InverseGudermannian


" . PHP_EOL; +for ( $i = -10; $i <= 10; $i++ ) { + echo ( $i ) . ': ' . $complexFunction5( $i ) . '
' . PHP_EOL; +} +unset($i); + +echo "

ArcCoth


" . PHP_EOL; +for ( $i = -10; $i <= 10; $i++ ) { + echo ( $i ) . ': ' . $complexFunction6( $i ) . '
' . PHP_EOL; +} +unset($i); + +echo "

Coth


" . PHP_EOL; +for ( $i = -10; $i <= 10; $i++ ) { + echo ( $i ) . ': ' . $complexFunction7( $i ) . '
' . PHP_EOL; +} +unset($i); + +echo "

Tanh


" . PHP_EOL; +for ( $i = -10; $i <= 10; $i++ ) { + echo ( $i ) . ': ' . $complexFunction8( $i ) . '
' . PHP_EOL; +} +unset($i); \ No newline at end of file From 1c280bf3949c8a3afbc32b12cb62c3ccaf164ba5 Mon Sep 17 00:00:00 2001 From: ephod Date: Sun, 15 Feb 2015 21:01:05 +0100 Subject: [PATCH 2/5] Update README.md --- README.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ed65083..3939c33 100644 --- a/README.md +++ b/README.md @@ -58,4 +58,14 @@ Planned additional functionality, but still to implement * coth (hyperbolic cotangent) * acoth (inverse hyperbolic cotangent) * pow (power) - \ No newline at end of file + +--- +Functions added +- tanh (hyperbolic tangent) +- coth (hyperbolic cotangent) +- acoth (inverse hyperbolic cotangent) +- gudermannian () Hyperbolic +- inversegudermannian () Hyperbolic +- haversine () Trigonometric +- inversehaversine () Trigonometric + From 758a89e12036ceed76ee9f5a871550835dc20db5 Mon Sep 17 00:00:00 2001 From: Michael Johnson Date: Sun, 15 Feb 2015 21:28:39 +0100 Subject: [PATCH 3/5] ArcTanh added. --- classes/src/functions/atanh.php | 46 +++++++++++++++++++++++++++++++++ examples/complexTest2.php | 3 ++- examples/complexTest3.php | 13 ++++++++++ 3 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 classes/src/functions/atanh.php diff --git a/classes/src/functions/atanh.php b/classes/src/functions/atanh.php new file mode 100644 index 0000000..31870d8 --- /dev/null +++ b/classes/src/functions/atanh.php @@ -0,0 +1,46 @@ +getImaginary() == 0.0) { + if ( ( $complex->getReal() == -1 ) || ( $complex->getReal() == 1 ) ){ + return INF; + } else { + $calc = clone $complex; + + $complex->add( 1 ); + $complex = ln( $complex ); + + $calc = $calc->multiply( -1 ); + $calc = $calc->add( 1 ); + $calc = ln( $calc ); + + $complex = $complex->subtract( $calc ); + $complex = $complex->divideBy( 2 ); + + return $complex; + } + } +} diff --git a/examples/complexTest2.php b/examples/complexTest2.php index 9bf4aa3..b9a88c7 100644 --- a/examples/complexTest2.php +++ b/examples/complexTest2.php @@ -40,7 +40,8 @@ 'haversine', 'inversegudermannian', 'inversehaversine', - 'tanh' + 'tanh', + 'atanh' ]; for($real = -3.5; $real <= 3.5; $real += 0.5) { diff --git a/examples/complexTest3.php b/examples/complexTest3.php index ae99c01..7a0b711 100644 --- a/examples/complexTest3.php +++ b/examples/complexTest3.php @@ -10,6 +10,7 @@ $complexFunction6 = __NAMESPACE__ . '\\' . 'acoth'; $complexFunction7 = __NAMESPACE__ . '\\' . 'coth'; $complexFunction8 = __NAMESPACE__ . '\\' . 'tanh'; +$complexFunction9 = __NAMESPACE__ . '\\' . 'atanh'; echo $complexFunction1( 9 ) . '
' . PHP_EOL; @@ -53,4 +54,16 @@ for ( $i = -10; $i <= 10; $i++ ) { echo ( $i ) . ': ' . $complexFunction8( $i ) . '
' . PHP_EOL; } +unset($i); + +echo "

Tanh


" . PHP_EOL; +for ( $i = -10; $i <= 10; $i++ ) { + echo ( $i ) . ': ' . $complexFunction8( $i ) . '
' . PHP_EOL; +} +unset($i); + +echo "

ArcTanh


" . PHP_EOL; +for ( $i = -10; $i <= 10; $i++ ) { + echo ( $i ) . ': ' . $complexFunction9( $i ) . '
' . PHP_EOL; +} unset($i); \ No newline at end of file From c6755b2fe50770aa41060d8ad118500def1e47b5 Mon Sep 17 00:00:00 2001 From: ephod Date: Sun, 15 Feb 2015 21:29:56 +0100 Subject: [PATCH 4/5] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 3939c33..741f5eb 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,7 @@ Planned additional functionality, but still to implement --- Functions added - tanh (hyperbolic tangent) +- atanh (inverse hyperbolic tangent) - coth (hyperbolic cotangent) - acoth (inverse hyperbolic cotangent) - gudermannian () Hyperbolic From 9898045be68616786be6482a9997a5fe819b37f1 Mon Sep 17 00:00:00 2001 From: Michael Johnson Date: Mon, 16 Feb 2015 08:57:48 +0100 Subject: [PATCH 5/5] PHP Docs modified. --- classes/src/functions/acoth.php | 19 +++++++++++---- classes/src/functions/atanh.php | 24 ++++++++----------- classes/src/functions/coth.php | 19 +++++++++++---- classes/src/functions/gudermannian.php | 20 ++++++++++++---- classes/src/functions/haversine.php | 18 +++++++------- classes/src/functions/inversegudermannian.php | 21 +++++++++++----- classes/src/functions/inversehaversine.php | 20 +++++++++------- classes/src/functions/tanh.php | 17 +++++++++---- examples/complexTest3.php | 19 ++++++--------- 9 files changed, 107 insertions(+), 70 deletions(-) diff --git a/classes/src/functions/acoth.php b/classes/src/functions/acoth.php index 7c61bd9..ebd2f7e 100644 --- a/classes/src/functions/acoth.php +++ b/classes/src/functions/acoth.php @@ -1,17 +1,26 @@ getImaginary() == 0.0) { + if ( $complex->getImaginary() == 0.0 ) { if ( ( $complex->getReal() == -1 ) || ( $complex->getReal() == 1 ) ) { return INF; } else { diff --git a/classes/src/functions/atanh.php b/classes/src/functions/atanh.php index 31870d8..b5e902a 100644 --- a/classes/src/functions/atanh.php +++ b/classes/src/functions/atanh.php @@ -1,30 +1,26 @@ getImaginary() == 0.0) { + if ( $complex->getImaginary() == 0.0 ) { if ( ( $complex->getReal() == -1 ) || ( $complex->getReal() == 1 ) ){ return INF; } else { diff --git a/classes/src/functions/coth.php b/classes/src/functions/coth.php index e25eea5..0e19b78 100644 --- a/classes/src/functions/coth.php +++ b/classes/src/functions/coth.php @@ -1,17 +1,26 @@ getImaginary() == 0.0) { + if ( $complex->getImaginary() == 0.0 ) { $calc = clone $complex; $complex = cosh( $complex ); $calc = sinh( $calc ); diff --git a/classes/src/functions/gudermannian.php b/classes/src/functions/gudermannian.php index 9d40692..415c27b 100644 --- a/classes/src/functions/gudermannian.php +++ b/classes/src/functions/gudermannian.php @@ -1,16 +1,26 @@ getImaginary() == 0.0) { + if ( $complex->getImaginary() == 0.0 ) { $complex = exp( $complex ); $complex = atan( $complex ); $complex = $complex->multiply( 2 ); diff --git a/classes/src/functions/haversine.php b/classes/src/functions/haversine.php index be86d7f..42eae81 100644 --- a/classes/src/functions/haversine.php +++ b/classes/src/functions/haversine.php @@ -1,28 +1,26 @@ getImaginary() == 0.0) { + if ( $complex->getImaginary() == 0.0 ) { $complex = $complex->divideBy( 2 ); $complex = sin( $complex ); $complex = $complex->multiply( $complex ); diff --git a/classes/src/functions/inversegudermannian.php b/classes/src/functions/inversegudermannian.php index 7c5982d..29da00b 100644 --- a/classes/src/functions/inversegudermannian.php +++ b/classes/src/functions/inversegudermannian.php @@ -1,17 +1,26 @@ getImaginary() == 0.0) { + if ( $complex->getImaginary() == 0.0 ) { $complex = $complex->divideBy( 2 ); $complex = $complex->add( M_PI/4 ); $complex = tan( $complex ); diff --git a/classes/src/functions/inversehaversine.php b/classes/src/functions/inversehaversine.php index 24afa56..c052479 100644 --- a/classes/src/functions/inversehaversine.php +++ b/classes/src/functions/inversehaversine.php @@ -1,23 +1,27 @@ getImaginary() == 0.0 ) { - if (($complex->getReal() >= 0.0) && ($complex->getReal() <= 1.0)) { + if ( ( $complex->getReal() >= 0.0 ) && ( $complex->getReal() <= 1.0 ) ) { $complex = sqrt( $complex ); $complex = asin( $complex ); $complex = $complex->multiply( 2 ); diff --git a/classes/src/functions/tanh.php b/classes/src/functions/tanh.php index be92a71..efbd79c 100644 --- a/classes/src/functions/tanh.php +++ b/classes/src/functions/tanh.php @@ -1,17 +1,24 @@ getImaginary() == 0.0) { + if ( $complex->getImaginary() == 0.0 ) { $calc = clone $complex; $complex = sinh( $complex ); $calc = cosh( $calc ); diff --git a/examples/complexTest3.php b/examples/complexTest3.php index 7a0b711..543c32f 100644 --- a/examples/complexTest3.php +++ b/examples/complexTest3.php @@ -7,13 +7,14 @@ $complexFunction3 = __NAMESPACE__ . '\\' . 'inversehaversine'; $complexFunction4 = __NAMESPACE__ . '\\' . 'gudermannian'; $complexFunction5 = __NAMESPACE__ . '\\' . 'inversegudermannian'; -$complexFunction6 = __NAMESPACE__ . '\\' . 'acoth'; -$complexFunction7 = __NAMESPACE__ . '\\' . 'coth'; +$complexFunction6 = __NAMESPACE__ . '\\' . 'coth'; +$complexFunction7 = __NAMESPACE__ . '\\' . 'acoth'; $complexFunction8 = __NAMESPACE__ . '\\' . 'tanh'; $complexFunction9 = __NAMESPACE__ . '\\' . 'atanh'; echo $complexFunction1( 9 ) . '
' . PHP_EOL; + echo "

Haversine


" . PHP_EOL; for ( $i = -10; $i <= 10; $i++ ) { echo ( $i ) . ': ' . $complexFunction2( $i ) . '
' . PHP_EOL; @@ -32,19 +33,19 @@ } unset($i); -echo "

InverseGudermannian


" . PHP_EOL; +echo "

Inverse Gudermannian


" . PHP_EOL; for ( $i = -10; $i <= 10; $i++ ) { echo ( $i ) . ': ' . $complexFunction5( $i ) . '
' . PHP_EOL; } unset($i); -echo "

ArcCoth


" . PHP_EOL; +echo "

Coth


" . PHP_EOL; for ( $i = -10; $i <= 10; $i++ ) { echo ( $i ) . ': ' . $complexFunction6( $i ) . '
' . PHP_EOL; } unset($i); -echo "

Coth


" . PHP_EOL; +echo "

ArcCoth


" . PHP_EOL; for ( $i = -10; $i <= 10; $i++ ) { echo ( $i ) . ': ' . $complexFunction7( $i ) . '
' . PHP_EOL; } @@ -56,14 +57,8 @@ } unset($i); -echo "

Tanh


" . PHP_EOL; -for ( $i = -10; $i <= 10; $i++ ) { - echo ( $i ) . ': ' . $complexFunction8( $i ) . '
' . PHP_EOL; -} -unset($i); - echo "

ArcTanh


" . PHP_EOL; for ( $i = -10; $i <= 10; $i++ ) { echo ( $i ) . ': ' . $complexFunction9( $i ) . '
' . PHP_EOL; } -unset($i); \ No newline at end of file +unset($i);