|PGnumericalmacros.pl||topic started 5/22/2000; 9:56:06 PM
last post 5/22/2000; 9:56:06 PM
|Michael Gage - PGnumericalmacros.pl
5/22/2000; 9:56:06 PM (reads: 950, responses: 0)
Numerical methods for the PG language
Plotting a list of points (piecewise linear interpolation)
Horner polynomial/ Newton polynomial
Usege: $fn = horner([x0,x1,x2],[q0,q1,q2]);
Generates a subroutine which evaluates a polynomial passing through the points
Usage: $poly = hermit([x0,x1...],[y0,y1...],[yp0,yp1,...]);
Generates a subroutine which evaluates a polynomial passing through the specified points with the specified derivatives: (x0,y0,yp0) ... The polynomial will be of high degree and may wobble unexpectedly. Use the Hermite splines described below and in Hermite.pm for most graphing purposes.
Usage: $spline = hermit_spline([x0,x1...],[y0,y1...],[yp0,yp1,...]);
&$spline(45) evaluates to a number.
Generates a subroutine which evaluates a piecewise cubic polynomial passing through the specified points with the specified derivatives: (x0,y0,yp0) ...
An object oriented version of this is defined in Hermite.pm
Cubic spline approximation
Where the x and y value arrays come from the function to be approximated. The function reference will take a single value x and produce value y.
$y = &$fun_ref($x);
The string contains
and can be placed in the header of the HTML output using
Numerical Integration methods
Integration by trapezoid rule
Usage: trapezoid(function_reference, start, end, steps=>30 );
Implements the trapezoid rule using 30 intervals between 'start' and 'end'. The first three arguments are required. The final argument (number of steps) is optional and defaults to 30.
Romberg method of integration
Usage: romberg(function_reference, x0, x1, level);
Implements the Romberg integration routine through 'level' recursive steps. Level defaults to 6.
Usage: inv_romberg(function_reference, a, value);
Finds b such that the integral of the function from a to b is equal to value. Assumes that the function is continuous and doesn't take on the zero value. Uses Newton's method of approximating roots of equations, and Romberg to evaluate definite integrals.
File path = /ww/webwork/pg/macros/PGnumericalmacros.pl