use Math::Calculus::NewtonRaphson;
use strict;
use warnings;
my $exp = Math::Calculus::NewtonRaphson->new();
$exp->addVariable('x'); # our variable in the equations
$exp->setExpression('x+3*x-x^2');
if( $exp->getError() ){ print "got error, ".$exp->getError()."\n"; exit(1) }
my $result = $exp->newtonRaphson('x', 0);
print "result: ".$result."\n";
####
library(rSymPy)
x <- Var("x")
sympy("solve(3+3*x-x*x, x)")
####
[1] "[3/2 - 21**(1/2)/2, 3/2 + 21**(1/2)/2]"
####
use strict;
use warnings;
my $i;
my @q = map { rand() } (1..1000); # your 1000 'q' coefficients as just random numbers here
my @c = map { rand() } (1..1000); # your 1000 'c' coefficients as just random numbers here
my ($a1, $a2, $a3);
my $sum_equ = "";
for ($i=1; $i<1000; $i++) {
$a1 = (1-$c[$i])*(1-2*$q[$i]);
$a2 = -2*$q[$i];
$a3 = $c[$i]*(2*$q[$i] -1);
# concatenate the equation of this time with the total equation:
$sum_equ = $sum_equ . "($a1/($a2 * x + x + $q[$i]) + $a3/(2*q[$i]*x-x+1)) + ";
}
$sum_equ =~ s/\+\s*$//; # remove last +
print "library(rSymPy)\n\
x <- Var('x')\n\
sympy('solve($sum_equ, x)')\n
";
####
perl equ.pl | R