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) |
NAMENumerical methods for the PG language
SYNPOSIS
DESCRIPTION
Interpolation methods
Plotting a list of points (piecewise linear interpolation)Usage: plot_list([x0,y0,x1,y1,...]); plot_list([x0,x1,x2...], [y0,y1,y2,...]);
Horner polynomial/ Newton polynomialUsege: $fn = horner([x0,x1,x2],[q0,q1,q2]); Generates a subroutine which evaluates a polynomial passing through the points
Hermite polynomialsUsage: $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.
Hermite splinesUsage: $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 approximationUsage: 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); You can also generate javaScript which defines a cubic spline: $function_string = javaScript_cubic_spline(~~@_x_values, ~~@y_values, The string contains <SCRIPT LANGUAGE="JavaScript"> and can be placed in the header of the HTML output using HEADER_TEXT($function_string);
Numerical Integration methods
Integration by trapezoid ruleUsage: 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 integrationUsage: romberg(function_reference, x0, x1, level); Implements the Romberg integration routine through 'level' recursive steps. Level defaults to 6.
Inverse RombergUsage: 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 |