IMCSCH.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  3. require __DIR__ . '/../../Header.php';
  4. $category = 'Engineering';
  5. $functionName = 'IMCSCH';
  6. $description = 'Returns the hyperbolic cosecant of a complex number in x + yi or x + yj text format';
  7. $helper->titles($category, $functionName, $description);
  8. // Create new PhpSpreadsheet object
  9. $spreadsheet = new Spreadsheet();
  10. $worksheet = $spreadsheet->getActiveSheet();
  11. // Add some data
  12. $testData = [
  13. ['3+4i'],
  14. ['5-12i'],
  15. ['3.25+7.5i'],
  16. ['3.25-12.5i'],
  17. ['-3.25+7.5i'],
  18. ['-3.25-7.5i'],
  19. ['0-j'],
  20. ['0-2.5j'],
  21. ['0+j'],
  22. ['0+1.25j'],
  23. [4],
  24. [-2.5],
  25. ];
  26. $testDataCount = count($testData);
  27. $worksheet->fromArray($testData, null, 'A1', true);
  28. for ($row = 1; $row <= $testDataCount; ++$row) {
  29. $worksheet->setCellValue('B' . $row, '=IMCSCH(A' . $row . ')');
  30. }
  31. // Test the formulae
  32. for ($row = 1; $row <= $testDataCount; ++$row) {
  33. $helper->log(sprintf(
  34. '(E%d): The Hyperbolic Cosecant of %s is %s',
  35. $row,
  36. $worksheet->getCell('A' . $row)->getValue(),
  37. $worksheet->getCell('B' . $row)->getCalculatedValue(),
  38. ));
  39. }