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 ";