ERF.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  3. require __DIR__ . '/../../Header.php';
  4. $category = 'Engineering';
  5. $functionName = 'ERF';
  6. $description = 'Returns the error function integrated between lower_limit and upper_limit';
  7. $helper->titles($category, $functionName, $description);
  8. // Create new PhpSpreadsheet object
  9. $spreadsheet = new Spreadsheet();
  10. $worksheet = $spreadsheet->getActiveSheet();
  11. // Add some data
  12. $testData1 = [
  13. [0.745],
  14. [1],
  15. [1.5],
  16. [-2],
  17. ];
  18. $testData2 = [
  19. [0, 1.5],
  20. [1, 2],
  21. [-2, 1],
  22. ];
  23. $testDataCount1 = count($testData1);
  24. $testDataCount2 = count($testData2);
  25. $testData2StartRow = $testDataCount1 + 1;
  26. $worksheet->fromArray($testData1, null, 'A1', true);
  27. $worksheet->fromArray($testData2, null, "A{$testData2StartRow}", true);
  28. for ($row = 1; $row <= $testDataCount1; ++$row) {
  29. $worksheet->setCellValue('C' . $row, '=ERF(A' . $row . ')');
  30. }
  31. for ($row = $testDataCount1 + 1; $row <= $testDataCount2 + $testDataCount1; ++$row) {
  32. $worksheet->setCellValue('C' . $row, '=ERF(A' . $row . ', B' . $row . ')');
  33. }
  34. // Test the formulae
  35. $helper->log('ERF() With a single argument');
  36. for ($row = 1; $row <= $testDataCount1; ++$row) {
  37. $helper->log(sprintf(
  38. '(C%d): %s The error function integrated between 0 and %f is %f',
  39. $row,
  40. $worksheet->getCell('C' . $row)->getValue(),
  41. $worksheet->getCell('A' . $row)->getValue(),
  42. $worksheet->getCell('C' . $row)->getCalculatedValue(),
  43. ));
  44. }
  45. $helper->log('ERF() With two arguments');
  46. for ($row = $testDataCount1 + 1; $row <= $testDataCount2 + $testDataCount1; ++$row) {
  47. $helper->log(sprintf(
  48. '(C%d): %s The error function integrated between %f and %f is %f',
  49. $row,
  50. $worksheet->getCell('C' . $row)->getValue(),
  51. $worksheet->getCell('A' . $row)->getValue(),
  52. $worksheet->getCell('B' . $row)->getValue(),
  53. $worksheet->getCell('C' . $row)->getCalculatedValue(),
  54. ));
  55. }