<?xml version="1.0" encoding="windows-1252"?>
<node id="280731" title="Re: numeric computing" created="2003-08-04 12:34:11" updated="2004-12-15 11:08:30">
<type id="11">
note</type>
<author id="196557">
chunlou</author>
<data>
<field name="doctext">
&lt;p&gt;It happens that there's [cpan://Statistics::LTU]. In general, look for the solution that lets Perl interface with other external software.&lt;/p&gt;

&lt;p&gt;
[cpan://Inline::Octave] may be useful.
&lt;/p&gt;
&lt;p&gt;[cpan://Pari] (a number theory package) may also be of use.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.omegahat.org/"&gt;Omegahat&lt;/a&gt; has a bunch of bi-directional interfaces for general programming languages and math software.&lt;/p&gt;


&lt;p&gt;
[cpan://Math::MatrixReal] can solve linear equations alright. It can't deal with eigensystem in general, only the symmetric case. But it's not hard to implement your own power method to find &lt;i&gt;real&lt;/i&gt; (as opposed to complex) eigen values.
&lt;/p&gt;

&lt;code&gt;
use constant eps =&gt; 0.00001;   
my $m;   

sub eigen {
	$m = shift;   # assume a Math::MatrixReal object
	return _eigen(-1e300, $m-&gt;column(1)-&gt;each(sub{1}));	  
}
sub _eigen {
	my $v = $_[1]; 
	$v = $m*$v;   
	my $eigen = $v-&gt;norm_max();   
	$v = $v*(1/$eigen);  
	abs($eigen - $_[0]) &gt; eps ? _eigen($eigen,$v) : return($eigen,$v);
}
&lt;/code&gt;

&lt;p&gt;
&lt;br&gt;
__________________&lt;br&gt;
Caveat. Power method may go on forever if no real eigenvalues exist unless you explicitly limit the number of iteration.
&lt;/p&gt;
</field>
<field name="root_node">
280561</field>
<field name="parent_node">
280561</field>
</data>
</node>
