testFunctions.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace Complex;
  3. include('../classes/Bootstrap.php');
  4. echo 'Function Examples', PHP_EOL;
  5. $functions = array(
  6. 'abs',
  7. 'acos',
  8. 'acosh',
  9. 'acsc',
  10. 'acsch',
  11. 'argument',
  12. 'asec',
  13. 'asech',
  14. 'asin',
  15. 'asinh',
  16. 'conjugate',
  17. 'cos',
  18. 'cosh',
  19. 'csc',
  20. 'csch',
  21. 'exp',
  22. 'inverse',
  23. 'ln',
  24. 'log2',
  25. 'log10',
  26. 'rho',
  27. 'sec',
  28. 'sech',
  29. 'sin',
  30. 'sinh',
  31. 'sqrt',
  32. 'theta'
  33. );
  34. for ($real = -3.5; $real <= 3.5; $real += 0.5) {
  35. for ($imaginary = -3.5; $imaginary <= 3.5; $imaginary += 0.5) {
  36. foreach ($functions as $function) {
  37. $complexFunction = __NAMESPACE__ . '\\' . $function;
  38. $complex = new Complex($real, $imaginary);
  39. try {
  40. echo $function, '(', $complex, ') = ', $complexFunction($complex), PHP_EOL;
  41. } catch (\Exception $e) {
  42. echo $function, '(', $complex, ') ERROR: ', $e->getMessage(), PHP_EOL;
  43. }
  44. }
  45. echo PHP_EOL;
  46. }
  47. }