Hello Perl Monks,

I am trying to program series equation in Perl and solve for the 'x' at the end.

my equation is

$c = 1 or 0; - different value(0 or 1) for each for loop

$q is given value - different value each for loop though

for ($i=1; $i<1000; i++) { $sum_equ ={(1-$c[$i])(1-2*$q[$i])}/(-2*$q[$i]*$x +$x +$q[$i]) + +{$c[$i]*(2*$q[$i] -1)}/(2*$q[$i]*$x-$x+1) }

$c values determines which part of valued to be added.

I am hoping '$sum_equ' contains sum of all equations and set the final equations as zero, then solve for the $x value at the end.

for example...

I have 1000 iterations to to be begin with $sum_equ = 0;

when i=0; $sum_equ = (1 - 2*10)/(-2*10*$x +$x +10); when i=1; $sum_equ = (1 - 2*10)/(-2*10*$x +$x +10) +(2*5 -1)/(2* +5*$x-$x+1); ..... when i=999; $sum_equ = (1 - 2*10)/(-2*10*$x +$x +10) +(2*5 -1)/( +2*5*$x-$x+1)+ ....... + (2*22 -1)/(2*22*$x-$x+1);

then $sum_equ = 0

Solve for $x value

pseudo code would be... I am stuck at what functions to use or how to implement it...

for ($i=1;$i<1000;$i++) { if ($c==1) { $sum_equ = $sum_equ + (1 - 2*$q[$i]/(-2*$q[$i] +*$x +$x +$q[$i] ); } elsif ($c ==0) { $sum_equ = $sum_equ + (2*$q[$i] -1)/(2*$q[$i]* +$x-$x+1); } # End of if } #end of for

I would greatly appreciate any comments or opinion.

Thank you so much.

2018-03-22 Athanasius Added code tags and removed paragraph tags from within code


In reply to Solve for 'x' in series by sbae

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.