view release on metacpan or search on metacpan
TaylorSeries.pm view on Meta::CPAN
# Create a clone of the expression object that we'll differentiate and prepare to find co-efficients.
my $diffExp = $self->clone;
my @coeffs = ();
my $coeffsFound = 0;
# Loop until we've found enough terms or we hit our maximum number of iterations.
my $numIters = 0;
while ($coeffsFound < $terms) {
# Evaluate.
my $coeff = $diffExp->evaluate($variable => $about);
return undef unless defined($coeff);
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Math/Cephes.pm view on Meta::CPAN
$sum = Math::Cephes::simpsn_wrap($f, $count-1, $h);
my $test = abs($sum - $sumold);
return $sum if ($test < $abs or abs($test/$sum) < $rel);
$sumold = $sum;
}
warn("Math::Cephes::simpson: Maximum number $nmax of iterations reached");
return undef;
}
sub bernum {
my $i = shift;
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Math/DifferenceSet/Planar.pm view on Meta::CPAN
The class methods
C<Math::DifferenceSet::Planar-E<gt>iterate_known_I<E<lt>typeE<gt>>_refs(@args)>
with I<E<lt>typeE<gt>> one of C<std>, C<lex>, or C<gap>, provide
iterators analogous to I<iterate>, but iterating over the reference
sets of the respective type rather than unspecified samples. Note that
these iterations may terminate sooner than I<iterate> and may even skip
some orders.
=item I<known_std_ref_min_order>
=item I<known_std_ref_max_order>
lib/Math/DifferenceSet/Planar.pm view on Meta::CPAN
already present, before it can be regarded as scientifically acceptable.
For each order, we used Singer's construction to generate a sample
set, which is provably valid, and iterated through its multiples
to find reference sets with their respective optimality properties.
As this was of course performed by computer programs and computers may
malfunction, repetitions or, even better, independent reiterations
will increase confidence in the results and weed out actual errors.
Verifying difference set properties using complete difference tables is
impractical for large sets. Verification using reference sets, on the
other hand, relies partly on conjectures. Therefore, we are still looking
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Math/EMA.pm view on Meta::CPAN
=head1 SYNOPSIS
use Math::EMA;
my $avg=Math::EMA->new(alpha=>0.926119, ema=>$initial_value);
$avg->set_param($iterations, $end_weight);
$avg->alpha=$new_alpha;
$avg->ema=$new_value;
$avg->add($some_value);
my $ema=$avg->ema;
lib/Math/EMA.pm view on Meta::CPAN
=head2 How to choose alpha?
The value of alpha determines how fast a given value vanes but it never
completely drops out. Assume you can define a limit say after 10
iterations the weight of a certain value should be 1% or 0.01. Then
_____
_10 / `
alpha = \ / 0.01 = exp( log(0.01) / 10 )
\/
lib/Math/EMA.pm view on Meta::CPAN
=head3 $obj-E<gt>ema
set or retrieve the current average
=head3 $obj-E<gt>set_param($iterations, $end_weight)
computes alpha from the passed values. After C<$iterations> new values a
certain value should have a weight of C<$end_weight> in the average.
=head1 SEE ALSO
L<http://en.wikipedia.org/wiki/Moving_average#Exponential_moving_average>
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Math/Erf/Approx.pm view on Meta::CPAN
=head1 BENCHMARKS
Benchmarking against L<Games::Go::Erf> (on a fairly underpowered netbook)...
Benchmark: timing 100000 iterations of GGE, MEA...
GGE: 6 wallclock secs ( 6.34 usr + 0.01 sys = 6.35 CPU) @ 15748.03/s (n=100000)
MEA: 3 wallclock secs ( 2.71 usr + 0.00 sys = 2.71 CPU) @ 36900.37/s (n=100000)
There are considerations other than raw speed though...
view all matches for this distribution
view release on metacpan or search on metacpan
benchmark.pl view on Meta::CPAN
use Benchmark qw(cmpthese);
use Math::Expression::Evaluator;
use Data::Dumper;
my $statement = '2 + a + 5 + (3+4)';
my $iterations = $ARGV[0] || 200;
sub with_optimize {
my $m = Math::Expression::Evaluator->new($statement);
$m->optimize;
for (1..$iterations){
$m->val({a => $_});
}
}
sub no_optimize {
my $m = Math::Expression::Evaluator->new($statement);
for (1..$iterations){
$m->val({a => $_});
}
}
sub compiled {
my $m = Math::Expression::Evaluator->new($statement);
my $c = $m->compiled();
for (1..$iterations){
$c->({a => $_});
}
}
sub opt_compiled {
my $m = Math::Expression::Evaluator->new($statement);
$m->optimize();
my $c = $m->compiled();
for (1..$iterations){
$c->({a => $_});
}
}
view all matches for this distribution
view release on metacpan or search on metacpan
Expression.pm view on Meta::CPAN
$self->PrintError("Loops not enabled, set property PermitLoops to do so");
return;
}
while(1) {
if($self->{MaxLoopCount} && ++$self->{LoopCount} > $self->{MaxLoopCount}) {
$self->PrintError("Loop exceeded maximum iterations: MaxLoopCount = $self->{MaxLoopCount}");
return;
}
# left is loop condition, right is body:
my @left = $self->EvalTree($tree->{left}, 0);
return $ret unless($left[-1]);
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Math/Fractal/Julia.pm view on Meta::CPAN
constant => [ $cx, $cy ]
=back
The default maximum number of iterations is 600.
The default limit is 5.
The default bounds is [-2.2, -1.1, 1.0, 1.1, 640, 480].
The default constant is [0.0, 0.0].
my $julia = Math::Fractal::Julia->new();
lib/Math/Fractal/Julia.pm view on Meta::CPAN
=item Return value: undefined
=back
Set the maximum number of iterations. The default value is 600.
Math::Fractal::Julia->set_max_iter($max);
$julia->set_max_iter($max);
lib/Math/Fractal/Julia.pm view on Meta::CPAN
=over 4
=item Arguments: $x, $y
=item Return value: The number of iterations needed to exceed the limit
or 0 if the the limit is not exceeded.
=back
This function translates the coordinates using the bounds and then
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Math/Fractal/Mandelbrot.pm view on Meta::CPAN
=head2 set_max_iter()
Math::Fractal::Mandelbrot->set_max_iter($max_iter);
Set the maximum number of iterations. 600 is the default and quite suitable
for the start image. When zooming in, this value should be increased to
not loose details.
=head2 set_limit()
lib/Math/Fractal/Mandelbrot.pm view on Meta::CPAN
=head2 set_epsilon()
Math::Fractal::Mandelbrot->set_epsilon($e);
The default value is 0.001. When the change between two iterations is less
than this number, the point is considered to be on the inside.
=head2 set_bounds()
Math::Fractal::Mandelbrot->set_bounds($x1,$y1,$x2,$y2,$w,$h);
lib/Math/Fractal/Mandelbrot.pm view on Meta::CPAN
my $iter = Math::Fractal::Mandelbrot->point($x,$y);
Calculates the value at the point C<$x> and C<$y>. The return value 0 means
the point is inside the fractal (typical the black area), any value >0 means
the number of iterations it took to find out that the point is on the outside.
$x and $y should be between 0 and C<w> and 0 and C<h>, respectively (see
L<set_bounds()>).
=head2 hor_line($x1,$y1,$l)
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Math/Function/Roots.pm view on Meta::CPAN
solution B<must> lie within [min,max].
=head2 I<epsilon> and I<max_iter> Parameters
Epsilon (I<e>) is used to set the desired accuracy. Less accurate
answers take fewer iterations and are therefore quicker to compute. In
general I<e> referres to the maximum distance from the given solution
to the actual solution. If you need 6 decimals of accuracy, then I<e>
= .000_000_1 is appropriate, this is the default. Calculating a few
decimals beyond what you need is generally recommended to prevent
compounding rounding errors. I<epsilon> is a named parameter to set
lib/Math/Function/Roots.pm view on Meta::CPAN
return $E;
}
=pod
Similar to epsilon, the maximum number of iterations an algorithm
should run for may be set with the I<max_iter> named parameter, or
globally with I<max_iter>(i). This maximum is normally used to catch
errors, i.e. when a given function doesn't converge, or when there is
a bug (nah...). Do not use this to control run-time, if you need an
answer faster, use a larger epsilon. The only reason to change this
lib/Math/Function/Roots.pm view on Meta::CPAN
=head1 PERFORMANCE CHECKING
=head2 last_iter( )
This will return the number of iterations used to find the last
result. This might help to give an indication on how an algorithm
performs on your data.
=cut
lib/Math/Function/Roots.pm view on Meta::CPAN
$a = $p;
$ay = $py;
}
}
carp "Maximum iterations: possible bad solution";
return $p;
}
=head2 fixed_point( I<fixed point function, guess> )
lib/Math/Function/Roots.pm view on Meta::CPAN
if( abs( $p - $last_p ) <= $E ){
return $p;
}
$last_p = $p;
}
carp "Maximum iterations: divergence likely";
return undef;
}
=head2 secant( I<function>, guess1, guess2 >)
lib/Math/Function/Roots.pm view on Meta::CPAN
return $p;
}
$p1 = $p;
}
carp "Maximum iterations: divergence likely";
return undef;
}
=head2 false_position( I<function, min, max> )
lib/Math/Function/Roots.pm view on Meta::CPAN
$b = $p;
$by = $py;
}
$last_py = $py;
}
carp "Maximum iterations: possible bad solution";
return $p;
}
=head2 find()
lib/Math/Function/Roots.pm view on Meta::CPAN
It will most likely return the root nearest your guess, but no
guarantees. Don't provide a range with more than one root in it, you
might find one, you might not. More information will give higher
performance and more control over which root is being found, but if
you don't know anything about the function, give it a try without a
guess. Settings from epsilon and maximum iterations apply as normal.
=cut
sub find(&;$$%){
my $f = shift;
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Math/GF.pm view on Meta::CPAN
return $p if $first_only;
push @retval, $p;
$n /= $p until $n % $p;
}
my $p = 5; # tentative divisor, will increase through iterations
my $top = int(sqrt($n) + MARGIN); # top attempt for divisor
my $d = 2; # increase for $p, alternates between 4 and 2
while ($p <= $top) {
if ($n % $p == 0) {
return $p if $first_only;
view all matches for this distribution
view release on metacpan or search on metacpan
X = ($mpz*X + $ui) mod (2 ** $m2exp). The low bits of X in this
algorithm are not very random. The least significant bit will have a
period no more than 2, and the second bit no more than 4, etc. For
this reason only the high half of each X is actually used.
When a random number of more than m2exp/2 bits is to be generated,
multiple iterations of the recurrence are used and the results
concatenated.
$state = fgmp_randinit_lc_2exp_size($ui);
This is the Math::GMPf interface to the gmp library function
'gmp_randinit_lc_2exp_size'.
view all matches for this distribution
view release on metacpan or search on metacpan
X = ($mpz*X + $ui) mod (2 ** $m2exp). The low bits of X in this
algorithm are not very random. The least significant bit will have a
period no more than 2, and the second bit no more than 4, etc. For
this reason only the high half of each X is actually used.
When a random number of more than m2exp/2 bits is to be generated,
multiple iterations of the recurrence are used and the results
concatenated.
$state = qgmp_randinit_lc_2exp_size($ui);
This is the Math::GMPq interface to the gmp library function
'gmp_randinit_lc_2exp_size'.
view all matches for this distribution
view release on metacpan or search on metacpan
X = ($mpz*X + $ui) mod (2 ** $m2exp). The low bits of X in this
algorithm are not very random. The least significant bit will have a
period no more than 2, and the second bit no more than 4, etc. For
this reason only the high half of each X is actually used.
When a random number of more than m2exp/2 bits is to be generated,
multiple iterations of the recurrence are used and the results
concatenated.
$state = zgmp_randinit_lc_2exp_size($ui);
This is the Math::GMPz interface to the gmp library function
'gmp_randinit_lc_2exp_size'.
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Math/GSL/Eigen.pm view on Meta::CPAN
@ISA = qw( Math::GSL::Eigen );
%OWNER = ();
%ITERATORS = ();
*swig_size_get = *Math::GSL::Eigenc::gsl_eigen_francis_workspace_size_get;
*swig_size_set = *Math::GSL::Eigenc::gsl_eigen_francis_workspace_size_set;
*swig_max_iterations_get = *Math::GSL::Eigenc::gsl_eigen_francis_workspace_max_iterations_get;
*swig_max_iterations_set = *Math::GSL::Eigenc::gsl_eigen_francis_workspace_max_iterations_set;
*swig_n_iter_get = *Math::GSL::Eigenc::gsl_eigen_francis_workspace_n_iter_get;
*swig_n_iter_set = *Math::GSL::Eigenc::gsl_eigen_francis_workspace_n_iter_set;
*swig_n_evals_get = *Math::GSL::Eigenc::gsl_eigen_francis_workspace_n_evals_get;
*swig_n_evals_set = *Math::GSL::Eigenc::gsl_eigen_francis_workspace_n_evals_set;
*swig_compute_t_get = *Math::GSL::Eigenc::gsl_eigen_francis_workspace_compute_t_get;
lib/Math/GSL/Eigen.pm view on Meta::CPAN
*swig_size_set = *Math::GSL::Eigenc::gsl_eigen_gen_workspace_size_set;
*swig_work_get = *Math::GSL::Eigenc::gsl_eigen_gen_workspace_work_get;
*swig_work_set = *Math::GSL::Eigenc::gsl_eigen_gen_workspace_work_set;
*swig_n_evals_get = *Math::GSL::Eigenc::gsl_eigen_gen_workspace_n_evals_get;
*swig_n_evals_set = *Math::GSL::Eigenc::gsl_eigen_gen_workspace_n_evals_set;
*swig_max_iterations_get = *Math::GSL::Eigenc::gsl_eigen_gen_workspace_max_iterations_get;
*swig_max_iterations_set = *Math::GSL::Eigenc::gsl_eigen_gen_workspace_max_iterations_set;
*swig_n_iter_get = *Math::GSL::Eigenc::gsl_eigen_gen_workspace_n_iter_get;
*swig_n_iter_set = *Math::GSL::Eigenc::gsl_eigen_gen_workspace_n_iter_set;
*swig_eshift_get = *Math::GSL::Eigenc::gsl_eigen_gen_workspace_eshift_get;
*swig_eshift_set = *Math::GSL::Eigenc::gsl_eigen_gen_workspace_eshift_set;
*swig_needtop_get = *Math::GSL::Eigenc::gsl_eigen_gen_workspace_needtop_get;
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Math/Gauss/XS.pm view on Meta::CPAN
This module just rewrites the L<Math::Gauss> module in XS. The precision and
exported function remain the same as in the original.
The benchmark results are
Benchmark: timing 30000000 iterations of pp/pdf, xs/pdf...
pp/pdf: 15 wallclock secs (14.99 usr + 0.00 sys = 14.99 CPU) @ 2001334.22/s (n=30000000)
xs/pdf: 2 wallclock secs ( 2.16 usr + 0.00 sys = 2.16 CPU) @ 13888888.89/s (n=30000000)
Benchmark: timing 30000000 iterations of pp/cdf, xs/cdf...
pp/cdf: 40 wallclock secs (38.93 usr + 0.00 sys = 38.93 CPU) @ 770613.92/s (n=30000000)
xs/cdf: 2 wallclock secs ( 2.22 usr + 0.00 sys = 2.22 CPU) @ 13513513.51/s (n=30000000)
Benchmark: timing 30000000 iterations of pp/inv_cdf, xs/inv_cdf...
pp/inv_cdf: 15 wallclock secs (16.02 usr + 0.00 sys = 16.02 CPU) @ 1872659.18/s (n=30000000)
xs/inv_cdf: 2 wallclock secs ( 2.18 usr + 0.00 sys = 2.18 CPU) @ 13761467.89/s (n=30000000)
=for Pod::Coverage cdf inv_cdf pdf
view all matches for this distribution
view release on metacpan or search on metacpan
src/triangle.c view on Meta::CPAN
lnextself(topleft);
printtriangle(m, b, &topleft);
printf(" and right ");
printtriangle(m, b, &horiz);
}
/* On the next iterations, consider the two edges that were */
/* exposed (this is, are now visible to the newly inserted */
/* vertex) by the edge flip. */
lprevself(horiz);
leftvertex = farvertex;
}
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Math/LOESS/_swig.pm view on Meta::CPAN
*swig_statistics_set = *Math::LOESS::_swigc::loess_control_statistics_set;
*swig_cell_get = *Math::LOESS::_swigc::loess_control_cell_get;
*swig_cell_set = *Math::LOESS::_swigc::loess_control_cell_set;
*swig_trace_hat_get = *Math::LOESS::_swigc::loess_control_trace_hat_get;
*swig_trace_hat_set = *Math::LOESS::_swigc::loess_control_trace_hat_set;
*swig_iterations_get = *Math::LOESS::_swigc::loess_control_iterations_get;
*swig_iterations_set = *Math::LOESS::_swigc::loess_control_iterations_set;
sub new {
my $pkg = shift;
my $self = Math::LOESS::_swigc::new_loess_control(@_);
bless $self, $pkg if defined($self);
}
view all matches for this distribution
view release on metacpan or search on metacpan
break_value */
double break_value;
double obj_bound; /* ## Objective function bound for speedup of
B&B */
int iter; /* The number of iterations in the simplex
solver (LP) */
int total_iter; /* The total number of iterations (B&B)
(ILP) */
int max_level; /* The Deepest B&B level of the last solution */
int total_nodes; /* total number of nodes processed in b&b */
double *solution; /* sum_alloc+1 :The Solution of the last LP,
0 = The Optimal Value,
view all matches for this distribution
view release on metacpan or search on metacpan
C abs(H) = HMIN or 10 consecutive failures occurred.
C On a return with KFLAG negative, the values of TN and
C the YH array are as of the beginning of the last
C step, and H is the last step size attempted.
C MAXORD = the maximum order of integration method to be allowed.
C MAXCOR = the maximum number of corrector iterations allowed.
C MSBP = maximum number of steps between PJAC calls (MITER .gt. 0).
C MXNCF = maximum number of convergence failures allowed.
C METH/MITER = the method flags. See description in driver.
C N = the number of first-order differential equations.
C The values of CCMAX, H, HMIN, HMXI, TN, JSTART, KFLAG, MAXORD,
Cdir$ ivdep
DO 210 I = I1,NQNYH
210 YH1(I) = YH1(I) + YH1(I+NYH)
215 CONTINUE
C-----------------------------------------------------------------------
C Up to MAXCOR corrector iterations are taken. A convergence test is
C made on the R.M.S. norm of each correction, weighted by the error
C weight vector EWT. The sum of the corrections is accumulated in the
C vector ACOR(i). The YH array is not altered in the corrector loop.
C-----------------------------------------------------------------------
220 M = 0
C ABS(H) = HMIN or 10 consecutive failures occurred.
C On a return with KFLAG negative, the values of TN and
C the YH array are as of the beginning of the last
C step, and H is the last step size attempted.
C MAXORD = the maximum order of integration method to be allowed.
C MAXCOR = the maximum number of corrector iterations allowed.
C MSBP = maximum number of steps between PJAC calls (MITER .gt. 0).
C MXNCF = maximum number of convergence failures allowed.
C METH = current method.
C METH = 1 means Adams method (nonstiff)
C METH = 2 means BDF method (stiff)
DO 210 I = I1,NQNYH
210 YH1(I) = YH1(I) + YH1(I+NYH)
215 CONTINUE
PNORM = DMNORM (N, YH1, EWT)
C-----------------------------------------------------------------------
C Up to MAXCOR corrector iterations are taken. A convergence test is
C made on the RMS-norm of each correction, weighted by the error
C weight vector EWT. The sum of the corrections is accumulated in the
C vector ACOR(i). The YH array is not altered in the corrector loop.
C-----------------------------------------------------------------------
220 M = 0
C rate constant is stored in CRATE, and this is used in the test.
C
C We first check for a change of iterates that is the size of
C roundoff error. If this occurs, the iteration has converged, and a
C new rate estimate is not formed.
C In all other cases, force at least two iterations to estimate a
C local Lipschitz constant estimate for Adams methods.
C On convergence, form PDEST = local maximum Lipschitz constant
C estimate. PDLAST is the most recent nonzero estimate.
C-----------------------------------------------------------------------
400 CONTINUE
C ABS(H) = HMIN or 10 consecutive failures occurred.
C On a return with KFLAG negative, the values of TN and
C the YH array are as of the beginning of the last
C step, and H is the last step size attempted.
C MAXORD = the maximum order of integration method to be allowed.
C MAXCOR = the maximum number of corrector iterations allowed.
C MSBP = maximum number of steps between DPKSET calls (MITER .gt. 0).
C MXNCF = maximum number of convergence failures allowed.
C METH/MITER = the method flags. See description in driver.
C N = the number of first-order differential equations.
C-----------------------------------------------------------------------
CDIR$ IVDEP
DO 210 I = I1,NQNYH
210 YH1(I) = YH1(I) + YH1(I+NYH)
215 CONTINUE
C-----------------------------------------------------------------------
C Up to MAXCOR corrector iterations are taken. A convergence test is
C made on the RMS-norm of each correction, weighted by the error
C weight vector EWT. The sum of the corrections is accumulated in the
C vector ACOR(i). The YH array is not altered in the corrector loop.
C-----------------------------------------------------------------------
220 M = 0
C scaled inner products of A*V(*,k) and V(*,i).
C
C IPVT = an integer array containg pivoting information.
C It is loaded in DHEFA and used in DHESL.
C
C LIOM = the number of iterations performed, and current
C order of the upper Hessenberg matrix HES.
C
C NPSL = the number of calls to PSOL.
C
C IFLAG = integer error flag:
C 0 means convergence in LIOM iterations, LIOM.le.MAXL.
C 1 means the convergence test did not pass in MAXL
C iterations, but the residual norm is .lt. 1,
C or .lt. norm(b) if MNEWT = 0, and so X is computed.
C 2 means the convergence test did not pass in MAXL
C iterations, residual .gt. 1, and X is undefined.
C 3 means there was a recoverable error in PSOL
C caused by the preconditioner being out of date.
C -1 means there was a nonrecoverable error in PSOL.
C
C-----------------------------------------------------------------------
C On return
C
C X = the final computed approximation to the solution
C of the system A*x = b.
C
C LGMR = the number of iterations performed and
C the current order of the upper Hessenberg
C matrix HES.
C
C NPSL = the number of calls to PSOL.
C
C Q = real array of length 2*MAXL containing the components
C of the Givens rotations used in the QR decomposition
C of HES. It is loaded in DHEQR and used in DHELS.
C
C IFLAG = integer error flag:
C 0 means convergence in LGMR iterations, LGMR .le. MAXL.
C 1 means the convergence test did not pass in MAXL
C iterations, but the residual norm is .lt. 1,
C or .lt. norm(b) if MNEWT = 0, and so x is computed.
C 2 means the convergence test did not pass in MAXL
C iterations, residual .gt. 1, and X is undefined.
C 3 means there was a recoverable error in PSOL
C caused by the preconditioner being out of date.
C -1 means there was a nonrecoverable error in PSOL.
C
C-----------------------------------------------------------------------
C On return
C
C X = the final computed approximation to the solution
C of the system A*x = b.
C
C LPCG = the number of iterations performed, and current
C order of the upper Hessenberg matrix HES.
C
C NPSL = the number of calls to PSOL.
C
C IFLAG = integer error flag:
C 0 means convergence in LPCG iterations, LPCG .le. MAXL.
C 1 means the convergence test did not pass in MAXL
C iterations, but the residual norm is .lt. 1,
C or .lt. norm(b) if MNEWT = 0, and so X is computed.
C 2 means the convergence test did not pass in MAXL
C iterations, residual .gt. 1, and X is undefined.
C 3 means there was a recoverable error in PSOL
C caused by the preconditioner being out of date.
C 4 means there was a zero denominator in the algorithm.
C The system matrix or preconditioner matrix is not
C sufficiently close to being symmetric pos. definite.
IF (MNEWT .GT. 0) RETURN
CALL DCOPY (N, R, 1, X, 1)
RETURN
C
20 ZTR = 0.0D0
C Loop point for PCG iterations. ---------------------------------------
30 CONTINUE
LPCG = LPCG + 1
CALL DCOPY (N, R, 1, Z, 1)
IER = 0
IF (JPRE .EQ. 0) GO TO 40
C On return
C
C X = the final computed approximation to the solution
C of the system A*x = b.
C
C LPCG = the number of iterations performed, and current
C order of the upper Hessenberg matrix HES.
C
C NPSL = the number of calls to PSOL.
C
C IFLAG = integer error flag:
C 0 means convergence in LPCG iterations, LPCG .le. MAXL.
C 1 means the convergence test did not pass in MAXL
C iterations, but the residual norm is .lt. 1,
C or .lt. norm(b) if MNEWT = 0, and so X is computed.
C 2 means the convergence test did not pass in MAXL
C iterations, residual .gt. 1, and X is undefined.
C 3 means there was a recoverable error in PSOL
C caused by the preconditioner being out of date.
C 4 means there was a zero denominator in the algorithm.
C the scaled matrix or scaled preconditioner is not
C sufficiently close to being symmetric pos. definite.
IF (MNEWT .GT. 0) RETURN
CALL DCOPY (N, R, 1, X, 1)
RETURN
C
20 ZTR = 0.0D0
C Loop point for PCG iterations. ---------------------------------------
30 CONTINUE
LPCG = LPCG + 1
CALL DCOPY (N, R, 1, Z, 1)
IER = 0
IF (JPRE .EQ. 0) GO TO 40
C UROUND = machine unit roundoff
C EWT, ITOL, ATOL = error weights and tolerance parameters
C as described in the driver routine, input.
C Y, TEMP = work arrays of length N.
C H0 = step size to be attempted, output.
C NITER = number of iterations (and of f evaluations) to compute H0,
C output.
C IER = the error flag, returned with the value
C IER = 0 if no trouble occurred, or
C IER = -1 if TOUT and t0 are considered too close to proceed.
C-----------------------------------------------------------------------
ENDIF
ITER = ITER + 1
C-----------------------------------------------------------------------
C Test the stopping conditions.
C Stop if the new and previous H values differ by a factor of .lt. 2.
C Stop if four iterations have been done. Also, stop with previous H
C if hnew/hg .gt. 2 after first iteration, as this probably means that
C the second derivative value is bad because of cancellation error.
C-----------------------------------------------------------------------
IF (ITER .GE. 4) GO TO 80
HRAT = HNEW/HG
C ABS(H) = HMIN or 10 consecutive failures occurred.
C On a return with KFLAG negative, the values of TN and
C the YH array are as of the beginning of the last
C step, and H is the last step size attempted.
C MAXORD = the maximum order of integration method to be allowed.
C MAXCOR = the maximum number of corrector iterations allowed.
C MSBP = maximum number of steps between DSETPK calls (MITER .gt. 0).
C MXNCF = maximum number of convergence failures allowed.
C METH/MITER = the method flags. See description in driver.
C N = the number of first-order differential equations.
C-----------------------------------------------------------------------
CDIR$ IVDEP
DO 210 I = I1,NQNYH
210 YH1(I) = YH1(I) + YH1(I+NYH)
215 CONTINUE
C-----------------------------------------------------------------------
C Up to MAXCOR corrector iterations are taken. A convergence test is
C made on the RMS-norm of each correction, weighted by the error
C weight vector EWT. The sum of the corrections is accumulated in the
C vector ACOR(i). The YH array is not altered in the corrector loop.
C Within the corrector loop, an estimated rate of convergence (ROC)
C and a stiffness ratio estimate (STIFF) are kept. Corresponding
C ABS(H) = HMIN or 10 consecutive failures occurred.
C On a return with KFLAG negative, the values of TN and
C the YH array are as of the beginning of the last
C step, and H is the last step size attempted.
C MAXORD = the maximum order of integration method to be allowed.
C MAXCOR = the maximum number of corrector iterations allowed.
C MSBP = maximum number of steps between PJAC calls.
C MXNCF = maximum number of convergence failures allowed.
C METH/MITER = the method flags. See description in driver.
C N = the number of first-order differential equations.
C-----------------------------------------------------------------------
CDIR$ IVDEP
DO 210 I = I1,NQNYH
210 YH1(I) = YH1(I) + YH1(I+NYH)
215 CONTINUE
C-----------------------------------------------------------------------
C Up to MAXCOR corrector iterations are taken. A convergence test is
C made on the RMS-norm of each correction, weighted by H and the
C error weight vector EWT. The sum of the corrections is accumulated
C in ACOR(i). The YH array is not altered in the corrector loop.
C-----------------------------------------------------------------------
220 M = 0
view all matches for this distribution
view release on metacpan or search on metacpan
demos/euler.p view on Meta::CPAN
#################################################################################
# This script requires Math::GMPq, Math::GMPz, and Math::MPFR. #
# It calculates the euler number e (2.7182818...), correct to $ARGV[0] bits. #
# The calculated value is displayed unless $ARGV[1] is both provided and false. #
# With each iteration of the for{} loop (below) we get closer and closer to #
# the actual value of e. Furthermore, with successive iterations of the for{} #
# loop, the values alternate between "less than e" and "greater than e". #
# Hence the actual (irrational) value of e is always between the values #
# calculated by successive iterations of the for{} loop. #
# #
# Of course, the simplest and most efficient way to get the value of e, to #
# $ARGV[0] bits is simply to do: #
# Rmpfr_exp($rop, Math::MPFR->new(1), MPFR_RNDN) #
# where $rop is a $ARGV[0]-bit precision Math::MPFR object. #
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Math/Matrix.pm view on Meta::CPAN
if ($abs_err_best <= $abs_tol || $rel_err_best <= $rel_tol) {
last;
} else {
# If we still haven't got the desired result, but have reached
# the maximum number of iterations, display a warning.
if ($iter == $max_iter) {
carp "mldiv() stopped because the maximum number of",
" iterations (max. iter = $max_iter) was reached without",
" converging to any of the desired tolerances (",
"rel_tol = ", $rel_tol, ", ",
"abs_tol = ", $abs_tol, ").",
" The best iterate (iter. = ", $iter_best, ") has",
" a relative residual of ", $rel_err_best, " and",
lib/Math/Matrix.pm view on Meta::CPAN
is satisfied, the algorithm terminates.
=head2 Stopping criteria
The algorithm stops when at least one of the errors are within the specified
tolerances or the maximum number of iterations is reached. If the maximum number
of iterations is reached, but noen of the errors are within the tolerances, a
warning is displayed and the best solution so far is returned.
=head2 Parameters
=over 4
=item MaxIter
The maximum number of iterations to perform. The value must be a positive
integer. The default is 20.
=item RelTol
The limit for the relative error. The value must be a non-negative. The default
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Math/MatrixReal.pm view on Meta::CPAN
my $dd = abs($d->[$m]) + abs($d->[$m+1]);
last if ((abs($e->[$m]) + $dd) == $dd);
}
if ($m != $l)
{
## why only allow 30 iterations?
croak("Too many iterations!") if ($iter++ >= 30);
my $g = ($d->[$l+1] - $d->[$l])
/ (2.0 * $e->[$l]);
my $r = _pythag($g, 1.0);
$g = $d->[$m] - $d->[$l]
+ $e->[$l] / ($g + (($g >= 0.0) ? abs($r) : -abs($r)));
lib/Math/MatrixReal.pm view on Meta::CPAN
my $dd = abs($d->[$m]) + abs($d->[$m+1]);
last if ((abs($e->[$m]) + $dd) == $dd);
}
if ($m != $l)
{
croak("Too many iterations!") if ($iter++ >= 30);
my $g = ($d->[$l+1] - $d->[$l])
/ (2.0 * $e->[$l]);
my $r = _pythag($g, 1.0);
$g = $d->[$m] - $d->[$l]
+ $e->[$l] / ($g + (($g >= 0.0) ? abs($r) : -abs($r)));
lib/Math/MatrixReal.pm view on Meta::CPAN
{'inverse' => sub { $matrix1->inverse(); },
'cofactor' => sub { (~$matrix1->cofactor)->each ( sub { (shift)/$det; } ) }
} );
Benchmark: timing 10 iterations of LR, cofactor, inverse...
inverse: 1 wallclock secs ( 0.56 usr + 0.00 sys = 0.56 CPU) @ 17.86/s (n=10)
cofactor: 36 wallclock secs (36.62 usr + 0.01 sys = 36.63 CPU) @ 0.27/s (n=10)
=item *
lib/Math/MatrixReal.pm view on Meta::CPAN
greater than by using an approximative (iterative) algorithm like one
of the three implemented here.
All three methods, GSM ("Global Step Method" or "Gesamtschrittverfahren"),
SSM ("Single Step Method" or "Einzelschrittverfahren") and RM ("Relaxation
Method" or "Relaxationsverfahren"), are fix-point iterations, that is, can
be described by an iteration function "C<x(t+1) = Phi( x(t) )>" which has
the property:
Phi(x) = x <==> A * x = b
view all matches for this distribution
view release on metacpan or search on metacpan
MatrixSparse.pm view on Meta::CPAN
C<< $matrix->jacobi($constant,$guess, $tol, $steps) >>
Uses Jacobi iteration to find and return the solution to the
system of equations $matrix * x = $constant, with initial guess
$constant, tolerance $tol, and maximum iterations $steps.
If $steps is undefined, the default value of 100 is used.
Care should be taken to ensure that $matrix is such that the
iteration actually converges.
MatrixSparse.pm view on Meta::CPAN
C<< $matrix->gaussseidel($constant,$guess, $tol, $steps) >>
Uses Gauss-Seidel iteration to find and return the solution to the
system of equations $matrix * x = $constant, with initial guess
$constant, tolerance $tol, and maximum
iterations $steps. This is equivalent to $matrix->SOR with
relaxation parameter 1.
Care should be taken to ensure that $matrix is such that the
iteration actually converges.
MatrixSparse.pm view on Meta::CPAN
C<< $matrix->SOR($constant,$guess, $relax, $tol, $steps) >>
Uses Successive Over-Relaxation to find and return the solution to the
system of equations $matrix * x = $constant, with initial guess
$constant, relaxation parameter $relax, tolerance $tol, and maximum
iterations $steps.
Care should be taken to ensure that $matrix is such that the
iteration actually converges.
=back
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Math/NLopt.pm view on Meta::CPAN
Returns an NLopt result code.
=head2 set_maxeval
$opt->set_maxeval( $max_iterations );
Returns an NLopt result code.
=head2 set_maxtime
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Math/NumSeq/AlphabeticalLengthSteps.pm view on Meta::CPAN
=for stopwords Ryde Math-NumSeq
=head1 NAME
Math::NumSeq::AlphabeticalLengthSteps -- iterations of length in characters
=head1 SYNOPSIS
use Math::NumSeq::AlphabeticalLengthSteps;
my $seq = Math::NumSeq::AlphabeticalLengthSteps->new;
view all matches for this distribution
view release on metacpan or search on metacpan
devel/haferman-carpet.pl view on Meta::CPAN
Array_1s_init1($n),
);
}
exit 0;
# num black cells after n iterations (9^(k+1) - (-5)^(k+1))/14 = 1,4,61,424
# Array1s(k+1) = 9^(k+1) - 5*Array1s(k)
# Array1s(0) = 1
# Array1s(1) = 9^1 - 5*1 = 4
# Array1s(2) = 9^2 - 5*(9^1 - 5*1)
# = 5^0*9^2 - 5^1*9^1 + 5^2*9^0
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Math/Numerical.pm view on Meta::CPAN
The function supports the following parameters:
=over
=item C<max_iterations>
How many iterations of our algorithm will be applied at most while trying to
find a root for the given function. This gives an order of magnitude of the
number of times that C<$func> will be evaluated. Defaults to I<100>.
=item C<do_bracket>
lib/Math/Numerical.pm view on Meta::CPAN
return 0;
}
sub find_root ($func, $x1, $x2, %params) {
my $do_bracket = $params{do_bracket} // 1;
my $max_iter = $params{max_iterations} // $DEFAULT_MAX_ITERATIONS;
my $f = _wrap_func($func);
my ($xa, $xb, $fa, $fb);
if ($do_bracket) {
($xa, $xb, $fa, $fb) = bracket($func, $x1, $x2, %params);
croak 'Canât bracket a root of the function' unless defined $xa;
lib/Math/Numerical.pm view on Meta::CPAN
The function supports the following parameters:
=over
=item C<max_iterations>
How many iterations of our algorithm will be applied at most while trying to
bracket the given function. This gives an order of magnitude of the number of
times that C<$func> will be evaluated. Defaults to I<100>.
=item C<do_outward>
lib/Math/Numerical.pm view on Meta::CPAN
sub bracket ($func, $x1, $x2 = undef, %params) {
if (!defined $x2 || $x1 == $x2) {
Readonly my $LARGISH_FACTOR => 1000;
$x2 += $LARGISH_FACTOR * $EPS;
}
my $max_iter = $params{max_iterations} // $DEFAULT_MAX_ITERATIONS;
croak 'max_iterations must be positive' if $max_iter <= 0;
my $f = _wrap_func($func);
my $f1 = $f->($x1);
my $inward_state;
view all matches for this distribution
view release on metacpan or search on metacpan
t/MyTestHelpers.pm view on Meta::CPAN
#
# use Exporter;
# use vars qw(@ISA @EXPORT_OK %EXPORT_TAGS);
# @ISA = ('Exporter');
# @EXPORT_OK = qw(findrefs
# main_iterations
# warn_suppress_gtk_icon
# glib_gtk_versions
# any_signal_connections
# nowarnings);
# %EXPORT_TAGS = (all => \@EXPORT_OK);
t/MyTestHelpers.pm view on Meta::CPAN
#-----------------------------------------------------------------------------
# Gtk/Glib helpers
# Gtk 2.16 can go into a hard loop on events_pending() / main_iteration_do()
# if dbus is not running, or something like that. In any case limiting the
# iterations is good for test safety.
#
sub main_iterations {
my $count = 0;
if (DEBUG) { MyTestHelpers::diag ("main_iterations() ..."); }
while (Gtk2->events_pending) {
$count++;
Gtk2->main_iteration_do (0);
if ($count >= 500) {
MyTestHelpers::diag ("main_iterations(): oops, bailed out after $count events/iterations");
return;
}
}
MyTestHelpers::diag ("main_iterations(): ran $count events/iterations");
}
# warn_suppress_gtk_icon() is a $SIG{__WARN__} handler which suppresses spam
# from Gtk trying to make you buy the hi-colour icon theme. Eg,
#
t/MyTestHelpers.pm view on Meta::CPAN
while (! $done) {
if (DEBUG >= 2) { MyTestHelpers::diag ("wait_for_event() iteration $count"); }
Gtk2->main_iteration;
$count++;
}
MyTestHelpers::diag ("wait_for_event(): '$signame' ran $count events/iterations\n");
$widget->signal_handler_disconnect ($sig_id);
Glib::Source->remove ($timer_id);
}
view all matches for this distribution
view release on metacpan or search on metacpan
Failed 16/82 test programs. 122/681 subtests failed.
XXX Our exception handler does not work as it should: the warning is already issued, so the error is empty.
Failed 16/82 test programs. 92/632 subtests failed. (without -O2 -s)
gclone() our tmp handlers ((x)->1), etc
Failed 16/82 test programs. 133/1249 subtests failed. (4 crashes; with -g)
We did not detach_stack() on restart. Now grows 6.7M on 1e5 iterations with 2.3.5 32bit windows (takes about 15min):
perl -Mblib -le "for (1..shift) {delete $INC{q(Math/Pari.pm)}; require Math::Pari; print sin Math::Pari::PARI(1)} END{warn 1; sleep 500}" 100000
XXX Probably worksv and workErrsv leaking???
XXX But this crashes with 100 (but not with 20):
perl -Mblib -wle "for (1..shift) {delete $INC{q(Math/Pari.pm)}; %Math::Pari::=(); require Math::Pari; $n=q(Math::Pari::PARI); *PARI = \&$n; print sin PARI(1)}" 100
To avoid warnings on redefinition, avoid function names in the script being resolved at compile time:
perl -Mblib -wle "for (1..shift) {delete $INC{q(Math/Pari.pm)}; %Math::Pari::=(); delete $::{PARI}; require Math::Pari; $n=q(Math::Pari::PARI); $N=q(PARI); *$N = \&$n; print sin &$N(1)}" 1000
but this cannot survive more than a few dozens of iterations... But this runs fine:
perl -wle "for (1..shift) {delete $INC{q(List/Util.pm)}; %List::Util:: = %Scalar::Util:: = %Sub::Util:: = (); $N=q(sum0); $n=qq(List::Util::$N); delete $::{$N}; require List::Util; *$N = \&$n; print 1 + &$N(1..10)}" 20000
The fix for -D_FORTIFY_SOURCE was not working. Redo.
2.030504
Patch for 2.5.0 was not updated. (Still not auto-applied.)
view all matches for this distribution