diff options
-rw-r--r-- | ChangeLog | 1 | ||||
-rw-r--r-- | src/math/matrix.php | 3 | ||||
-rw-r--r-- | tests/dataset_average_test.php | 38 |
3 files changed, 41 insertions, 1 deletions
@@ -8,6 +8,7 @@ - Added feature #9647: Add render to output method - Fixed issue #9612: Element links for SVG image in the legend require you to click on exactly the text. +- Fixed issue #9588: Wrong polynoms build from data - Fixed issue #9586: No data rendered with string keys on date axis. - Fixed issue #9583: Data typecasting should only be done in axis - Fixed issue #9568: Devision by zero warning diff --git a/src/math/matrix.php b/src/math/matrix.php index 0bd415b..94d4ccf 100644 --- a/src/math/matrix.php +++ b/src/math/matrix.php @@ -339,6 +339,7 @@ class ezcGraphMatrix { // Build complete equatation $equatation = new ezcGraphMatrix( $this->rows, $columns = ( $this->columns + 1 ) ); + for ( $i = 0; $i < $this->rows; ++$i ) { for ( $j = 0; $j < $this->columns; ++$j ) @@ -357,7 +358,7 @@ class ezcGraphMatrix { if ( $equatation->get( $j, $i ) == 0 ) { - $factor = 0; + continue; } else { diff --git a/tests/dataset_average_test.php b/tests/dataset_average_test.php index 6ab21c6..c5a7695 100644 --- a/tests/dataset_average_test.php +++ b/tests/dataset_average_test.php @@ -120,6 +120,44 @@ class ezcGraphDataSetAverageTest extends ezcTestCase ); } + public function testCreateDatasetFromDataset4() + { + $points = array(); + for ( $x = -1; $x <= 5; ++$x ) + { + $points[$x] = pow( $x - 2, 3 ) - .21 * pow( $x - 2, 2 ) + .2 * ( $x - 2 ) - 2.45; + } + + $arrayDataSet = new ezcGraphArrayDataSet( $points ); + + $averageDataSet = new ezcGraphDataSetAveragePolynom( $arrayDataSet, 3 ); + $polynom = $averageDataSet->getPolynom(); + + $this->assertEquals( + '1.00 * x^3 + -6.21 * x^2 + 13.04 * x + -11.69', + $polynom->__toString() + ); + } + + public function testCreateDatasetFromDataset5() + { + $points = array(); + for ( $x = -3; $x <= 3; ++$x ) + { + $points[$x] = pow( $x, 3 ) - .21 * pow( $x, 2 ) + .2 * $x - 2.45; + } + + $arrayDataSet = new ezcGraphArrayDataSet( $points ); + + $averageDataSet = new ezcGraphDataSetAveragePolynom( $arrayDataSet, 3 ); + $polynom = $averageDataSet->getPolynom(); + + $this->assertEquals( + 'x^3 + -0.21 * x^2 + 0.20 * x + -2.45', + $polynom->__toString() + ); + } + public function testCreateDatasetFromDatasetLowOrder() { $arrayDataSet = new ezcGraphArrayDataSet( array( -1 => 2, 1 => 2, 3 => 10 ) ); |