| … | |
… | |
| 1321 | |
1321 | |
| 1322 | set_default_options( \%opt, |
1322 | set_default_options( \%opt, |
| 1323 | 'var' => $functVarDefault, |
1323 | 'var' => $functVarDefault, |
| 1324 | 'params' => [], |
1324 | 'params' => [], |
| 1325 | 'limits' => [[$functLLimitDefault, $functULimitDefault]], |
1325 | 'limits' => [[$functLLimitDefault, $functULimitDefault]], |
|
|
1326 | 'test_points' => undef, |
| 1326 | 'mode' => 'std', |
1327 | 'mode' => 'std', |
| 1327 | 'tolType' => (defined($opt{tol}) ) ? 'absolute' : 'relative', |
1328 | 'tolType' => (defined($opt{tol}) ) ? 'absolute' : 'relative', |
| 1328 | 'tol' => .01, # default mode should be relative, to obtain this tol must not be defined |
1329 | 'tol' => .01, # default mode should be relative, to obtain this tol must not be defined |
| 1329 | 'relTol' => $functRelPercentTolDefault, |
1330 | 'relTol' => $functRelPercentTolDefault, |
| 1330 | 'numPoints' => $functNumOfPoints, |
1331 | 'numPoints' => $functNumOfPoints, |
| … | |
… | |
| 1373 | 'var' => $out_options{'var'}, |
1374 | 'var' => $out_options{'var'}, |
| 1374 | 'limits' => $out_options{'limits'}, |
1375 | 'limits' => $out_options{'limits'}, |
| 1375 | 'tolerance' => $tol, |
1376 | 'tolerance' => $tol, |
| 1376 | 'tolType' => $tolType, |
1377 | 'tolType' => $tolType, |
| 1377 | 'numPoints' => $out_options{'numPoints'}, |
1378 | 'numPoints' => $out_options{'numPoints'}, |
|
|
1379 | 'test_points' => $out_options{'test_points'}, |
| 1378 | 'mode' => $out_options{'mode'}, |
1380 | 'mode' => $out_options{'mode'}, |
| 1379 | 'maxConstantOfIntegration' => $out_options{'maxConstantOfIntegration'}, |
1381 | 'maxConstantOfIntegration' => $out_options{'maxConstantOfIntegration'}, |
| 1380 | 'zeroLevel' => $out_options{'zeroLevel'}, |
1382 | 'zeroLevel' => $out_options{'zeroLevel'}, |
| 1381 | 'zeroLevelTol' => $out_options{'zeroLevelTol'}, |
1383 | 'zeroLevelTol' => $out_options{'zeroLevelTol'}, |
| 1382 | 'params' => $out_options{'params'}, |
1384 | 'params' => $out_options{'params'}, |
| … | |
… | |
| 1697 | my $numPoints = $func_params{'numPoints'}; |
1699 | my $numPoints = $func_params{'numPoints'}; |
| 1698 | my $mode = $func_params{'mode'}; |
1700 | my $mode = $func_params{'mode'}; |
| 1699 | my $maxConstantOfIntegration = $func_params{'maxConstantOfIntegration'}; |
1701 | my $maxConstantOfIntegration = $func_params{'maxConstantOfIntegration'}; |
| 1700 | my $zeroLevel = $func_params{'zeroLevel'}; |
1702 | my $zeroLevel = $func_params{'zeroLevel'}; |
| 1701 | my $zeroLevelTol = $func_params{'zeroLevelTol'}; |
1703 | my $zeroLevelTol = $func_params{'zeroLevelTol'}; |
|
|
1704 | my $ra_test_points = $func_params{'test_points'}; |
| 1702 | |
1705 | |
| 1703 | |
1706 | |
| 1704 | # Check that everything is defined: |
1707 | # Check that everything is defined: |
| 1705 | $func_params{debug} = 0 unless defined($func_params{debug}); |
1708 | $func_params{debug} = 0 unless defined($func_params{debug}); |
| 1706 | $mode = 'std' unless defined($mode); |
1709 | $mode = 'std' unless defined($mode); |
| 1707 | my @VARS = get_var_array( $var ); |
1710 | my @VARS = get_var_array( $var ); |
| 1708 | my @limits = get_limits_array( $ra_limits ); |
1711 | my @limits = get_limits_array( $ra_limits ); |
| 1709 | my @PARAMS = (); |
1712 | my @PARAMS = (); |
| 1710 | @PARAMS = @{$func_params{'params'}} if defined($func_params{'params'}); |
1713 | @PARAMS = @{$func_params{'params'}} if defined($func_params{'params'}); |
|
|
1714 | |
|
|
1715 | my (@evaluation_points); |
|
|
1716 | if(defined($ra_test_points)) { |
|
|
1717 | # see if this is the standard format |
|
|
1718 | if( ref($ra_test_points->[0]) eq 'ARRAY') { |
|
|
1719 | $numPoints = scalar(@{$ra_test_points->[0]}); |
|
|
1720 | # now a little sanity check |
|
|
1721 | my $j; |
|
|
1722 | for $j (@{$ra_test_points}) { |
|
|
1723 | warn "Test points do not give the same number of values for each variable" |
|
|
1724 | unless(scalar(@{$j}) == $numPoints); |
|
|
1725 | } |
|
|
1726 | warn "Test points do not match the number of variables" |
|
|
1727 | unless scalar(@{$ra_test_points}) == scalar(@VARS); |
|
|
1728 | } else { # we are got the one-variable format |
|
|
1729 | $ra_test_points = [$ra_test_points]; |
|
|
1730 | $numPoints = scalar($ra_test_points->[0]); |
|
|
1731 | } |
|
|
1732 | # The input format for test points is the transpose of what is used |
|
|
1733 | # internally below, so take care of that now. |
|
|
1734 | my ($j1, $j2); |
|
|
1735 | for ($j1=0; $j1<scalar(@{$ra_test_points}); $j1++) { |
|
|
1736 | for ($j2=0; $j2<scalar(@{$ra_test_points->[$j1]}); $j2++) { |
|
|
1737 | $evaluation_points[$j2][$j1] = $ra_test_points->[$j1][$j2]; |
|
|
1738 | } |
|
|
1739 | } |
|
|
1740 | } # end of handling of user supplied evaluation points |
| 1711 | |
1741 | |
| 1712 | if ($mode eq 'antider' ) { |
1742 | if ($mode eq 'antider' ) { |
| 1713 | # doctor the equation to allow addition of a constant |
1743 | # doctor the equation to allow addition of a constant |
| 1714 | my $CONSTANT_PARAM = 'Q'; # unfortunately parameters must be single letters. |
1744 | my $CONSTANT_PARAM = 'Q'; # unfortunately parameters must be single letters. |
| 1715 | # There is the possibility of conflict here. |
1745 | # There is the possibility of conflict here. |
| … | |
… | |
| 1764 | store_in =>'rf_correct_ans', |
1794 | store_in =>'rf_correct_ans', |
| 1765 | debug => $func_params{debug}); |
1795 | debug => $func_params{debug}); |
| 1766 | my $correct_eqn_sub = $rh_correct_ans->{rf_correct_ans}; |
1796 | my $correct_eqn_sub = $rh_correct_ans->{rf_correct_ans}; |
| 1767 | warn $rh_correct_ans->{error_message} if $rh_correct_ans->{error_flag}; |
1797 | warn $rh_correct_ans->{error_message} if $rh_correct_ans->{error_flag}; |
| 1768 | |
1798 | |
|
|
1799 | if(not defined($ra_test_points)) { |
| 1769 | #create the evaluation points |
1800 | #create the evaluation points |
| 1770 | my $random_for_answers = new PGrandom($main::PG_original_problemSeed); |
1801 | my $random_for_answers = new PGrandom($main::PG_original_problemSeed); |
| 1771 | my $NUMBER_OF_STEPS_IN_RANDOM = 1000; # determines the granularity of the random_for_answers number generator |
1802 | my $NUMBER_OF_STEPS_IN_RANDOM = 1000; # determines the granularity of the random_for_answers number generator |
| 1772 | my (@evaluation_points); |
|
|
| 1773 | for( my $count = 0; $count < @PARAMS+1+$numPoints; $count++ ) { |
1803 | for( my $count = 0; $count < @PARAMS+1+$numPoints; $count++ ) { |
| 1774 | my (@vars,$iteration_limit); |
1804 | my (@vars,$iteration_limit); |
| 1775 | for( my $i = 0; $i < @VARS; $i++ ) { |
1805 | for( my $i = 0; $i < @VARS; $i++ ) { |
| 1776 | my $iteration_limit = 10; |
1806 | my $iteration_limit = 10; |
| 1777 | while ( 0 < --$iteration_limit ) { # make sure that the endpoints of the interval are not included |
1807 | while ( 0 < --$iteration_limit ) { # make sure that the endpoints of the interval are not included |
| 1778 | $vars[$i] = $random_for_answers->random($limits[$i][0], $limits[$i][1], abs($limits[$i][1] - $limits[$i][0])/$NUMBER_OF_STEPS_IN_RANDOM ); |
1808 | $vars[$i] = $random_for_answers->random($limits[$i][0], $limits[$i][1], abs($limits[$i][1] - $limits[$i][0])/$NUMBER_OF_STEPS_IN_RANDOM ); |
| 1779 | last if $vars[$i]!=$limits[$i][0] and $vars[$i]!=$limits[$i][1]; |
1809 | last if $vars[$i]!=$limits[$i][0] and $vars[$i]!=$limits[$i][1]; |
| 1780 | } |
1810 | } |
| 1781 | warn "Unable to properly choose evaluation points for this function in the interval ( $limits[$i][0] , $limits[$i][1] )" |
1811 | warn "Unable to properly choose evaluation points for this function in the interval ( $limits[$i][0] , $limits[$i][1] )" |
| 1782 | if $iteration_limit == 0; |
1812 | if $iteration_limit == 0; |
| 1783 | }; |
1813 | }; |
| 1784 | |
1814 | |
| 1785 | push(@evaluation_points,\@vars); |
1815 | push(@evaluation_points,\@vars); |
|
|
1816 | } |
| 1786 | } |
1817 | } |
| 1787 | my $evaluation_points = Matrix->new_from_array_ref(\@evaluation_points); |
1818 | my $evaluation_points = Matrix->new_from_array_ref(\@evaluation_points); |
| 1788 | |
1819 | |
| 1789 | #my $COEFFS = determine_param_coeffs($correct_eqn_sub,$evaluation_points[0],$numOfParameters); |
1820 | #my $COEFFS = determine_param_coeffs($correct_eqn_sub,$evaluation_points[0],$numOfParameters); |
| 1790 | #warn "coeff", join(" | ", @{$COEFFS}); |
1821 | #warn "coeff", join(" | ", @{$COEFFS}); |