ERFC.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  3. require __DIR__ . '/../../Header.php';
  4. $category = 'Engineering';
  5. $functionName = 'ERFC';
  6. $description = 'Returns the complementary ERF function integrated between x and infinity';
  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. [0],
  14. [0.5],
  15. [1],
  16. [-1],
  17. ];
  18. $testDataCount = count($testData);
  19. $worksheet->fromArray($testData, null, 'A1', true);
  20. for ($row = 1; $row <= $testDataCount; ++$row) {
  21. $worksheet->setCellValue('C' . $row, '=ERFC(A' . $row . ')');
  22. }
  23. // Test the formulae
  24. for ($row = 1; $row <= $testDataCount; ++$row) {
  25. $helper->log(sprintf(
  26. '(E%d): %s The complementary error function integrated by %f and infinity is %f',
  27. $row,
  28. $worksheet->getCell('C' . $row)->getValue(),
  29. $worksheet->getCell('A' . $row)->getValue(),
  30. $worksheet->getCell('C' . $row)->getCalculatedValue(),
  31. ));
  32. }