home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2000 May
/
Chip_2000-05_cd1.bin
/
zkuste
/
Perl
/
ActivePerl-5.6.0.613.msi
/
䆊䌷䈹䈙䏵-䞅䞆䞀㡆䞃䄦䠥
/
_438d8e6cceabef9dcf8fa2eca17c446d
< prev
next >
Wrap
Text File
|
2000-03-23
|
4KB
|
137 lines
<HTML>
<HEAD>
<TITLE>main/site/lib/Math/Approx.pm</TITLE>
<LINK REL="stylesheet" HREF="../../../Active.css" TYPE="text/css">
<LINK REV="made" HREF="mailto:">
</HEAD>
<BODY>
<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
<TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
<STRONG><P CLASS=block> main/site/lib/Math/Approx.pm</P></STRONG>
</TD></TR>
</TABLE>
<A NAME="__index__"></A>
<!-- INDEX BEGIN -->
<UL>
<LI><A HREF="#name">NAME</A></LI><LI><A HREF="#supportedplatforms">SUPPORTED PLATFORMS</A></LI>
<LI><A HREF="#methods">METHODS</A></LI>
<UL>
<LI><A HREF="#new (constructor)">new (constructor)</A></LI>
<LI><A HREF="#approx">approx</A></LI>
<LI><A HREF="#fit">fit</A></LI>
<LI><A HREF="#plot">plot</A></LI>
<LI><A HREF="#print">print</A></LI>
</UL>
<LI><A HREF="#example">EXAMPLE</A></LI>
<LI><A HREF="#see also">SEE ALSO</A></LI>
<LI><A HREF="#author">AUTHOR</A></LI>
</UL>
<!-- INDEX END -->
<HR>
<P>
<H1><A NAME="name">NAME</A></H1>
<P>Math::Approx</P>
<P>
<HR>
<H1><A NAME="supportedplatforms">SUPPORTED PLATFORMS</A></H1>
<UL>
<LI>Linux</LI>
<LI>Solaris</LI>
<LI>Windows</LI>
</UL>
<HR>
<H1><A NAME="methods">METHODS</A></H1>
<P>
<H2><A NAME="new (constructor)">new (constructor)</A></H2>
<PRE>
Math::Approx->new(\&poly, $degree, %data);</PRE>
<P>If the first argument to the constructor is a CODE reference, this is
used as the function to iterate over the data. Such a function must
take two arguments: The <EM>degree</EM> and the <EM>x</EM> value.</P>
<P>For interpolation with plain polynomials <EM>poly</EM> can be defined as:</P>
<PRE>
sub poly {
my($n,$x) = @_;
return $x ** $n;
}</PRE>
<P>If the first argument in the constructor is a FALSE value instead of a
CODE reference, then the above plain polynomial <EM>poly</EM> is used as the
iterator function.</P>
<P>The second argument is the maximum degree which should be used for
interpolation. Degrees start with <STRONG>0</STRONG>.</P>
<P>The rest of the arguments are treated as pairs of <STRONG>x</STRONG> and <STRONG>y</STRONG>
samples which should be approximated.</P>
<P>The constructor returns a Math::Approx reference.</P>
<P>
<H2><A NAME="approx">approx</A></H2>
<PRE>
$approximation->approx(17);</PRE>
<P>The method returns the approximated <STRONG>y</STRONG> value for the <STRONG>x</STRONG> value
given as argument.</P>
<P>
<H2><A NAME="fit">fit</A></H2>
<PRE>
$approximation->fit;</PRE>
<P>Returns the medim square error for the data points.</P>
<P>
<H2><A NAME="plot">plot</A></H2>
<PRE>
$approximation->plot("tmp/app");</PRE>
<P>Prints all data pairs and the corresponding approximation pairs into
the filename given as argument. The output is suitable for usage with
gnuplot(1).</P>
<P>
<H2><A NAME="print">print</A></H2>
<PRE>
$approximation->print;</PRE>
<P>Prints information about the approximation on <EM>STDOUT</EM></P>
<P>
<HR>
<H1><A NAME="example">EXAMPLE</A></H1>
<PRE>
use Math::Approx;
</PRE>
<PRE>
sub poly {
my($n,$x) = @_;
return $x ** $n;
}</PRE>
<PRE>
for (1..20) {
$x{$_} = sin($_/10)*cos($_/30)+0.3*rand;
}</PRE>
<PRE>
$a = new Math::Approx (\&poly, 5, %x);
$a->print;
$a->plot("math-approx-demo.out");
print "Fit: ", $a->fit, "\n";</PRE>
<P>
<HR>
<H1><A NAME="see also">SEE ALSO</A></H1>
<P>gnuplot(1).</P>
<P>
<HR>
<H1><A NAME="author">AUTHOR</A></H1>
<P>Ulrich Pfeifer <<EM><A HREF="mailto:pfeifer@wait.de">pfeifer@wait.de</A></EM>></P>
<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
<TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
<STRONG><P CLASS=block> main/site/lib/Math/Approx.pm</P></STRONG>
</TD></TR>
</TABLE>
</BODY>
</HTML>