Results 1 to 11 of 11
Like Tree1Likes
  • 1 Post By JosAH

Thread: summation of a series

  1. #1
    Join Date
    Jun 2014
    Location
    Dhaka
    Posts
    5
    Rep Power
    0

    Default summation of a series

    I have given a series like this..
    10+13+16+19+....+50;
    now I've to find the summation for this.
    I did it like following bt its not correct..
    public static void main(String[] args){
    int i=0,k=10, sum=0;
    k=k+2;
    for(i=10;i<=50;i++){
    sum=sum+k;
    }
    System.out.println(" "+sum);
    }

  2. #2
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,030
    Rep Power
    6

    Default Re: summation of a series

    Well this already looks a bit strange:

    Java Code:
    public static void main(String[] args){
    int i=0,k=10, sum=0;   // k = 10
    k=k+2;  // and then it is increased to 12 ?
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,617
    Rep Power
    5

    Default Re: summation of a series

    You can also use the increment in your loop. Make it i += 3;

    Also, note that each term is simply 3 more than the previous. So the difference of the last and the second term would be
    (n + k3) - (n + 3) where k is the number of terms after the first. So the difference is (k-1)3 which is divisible by three.
    Since 50 - 13 = 37 is not divisible by 3 your series does not make sense (i.e. 50 is not in the series). With a little thought
    you could also derive a general formula for calculating the sum.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,529
    Blog Entries
    7
    Rep Power
    20

    Default Re: summation of a series

    Quote Originally Posted by jim829 View Post
    Since 50 - 13 = 37 is not divisible by 3 your series does not make sense (i.e. 50 is not in the series).
    Strictly speaking, that is not true; just because 50 doesn't fit a reason of induction, only shows that the reasoning doesn't describe the series ... it's the OP's turn to fully describe the series, i.e. 10,13,16 .. 50 doesn't cut it.

    kind regards,

    Jos (nitpicker ;-)
    gimbal2 likes this.
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,617
    Rep Power
    5

    Default Re: summation of a series

    Well, I did make an assumption.

    Student: What's the next value in this series: 1,3,5,7,?
    Prof: 129282
    Student: What series is that?
    Prof: The one that has 129282 following 1,3,5,7.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  6. #6
    pbj
    pbj is offline Member
    Join Date
    Jun 2014
    Posts
    15
    Rep Power
    0

    Default Re: summation of a series

    op,
    I'm no rocket surgeon, but I have to say I think your series is a little wacky. I thought the series would be:
    13 16 19 22 25 28 31 34 37 40 43 46 49 52
    but then again I'm not much of a math guy. It looks like you just keep adding three to it, so I'm not seeking what k does, I think you'd only need i for your series. i+=3 in a do...while loop would probably do the trick.

  7. #7
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,617
    Rep Power
    5

    Default Re: summation of a series

    Check out posts #3 and #4 of this thread.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  8. #8
    superhaNds is offline Senior Member
    Join Date
    Apr 2013
    Location
    Sweden
    Posts
    264
    Rep Power
    2

    Default Re: summation of a series

    if you just add 3 to every term, fix your loop as Jim829 said.

    Or : 1 + 4 + ... + (3n - 2) = n(3n - 1) / 2

  9. #9
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,529
    Blog Entries
    7
    Rep Power
    20

    Default Re: summation of a series

    Quote Originally Posted by superhaNds View Post
    if you just add 3 to every term, fix your loop as Jim829 said.

    Or : 1 + 4 + ... + (3n - 2) = n(3n - 1) / 2
    That still doesn't fit the funny ending of the series (10, 13, 16 ... 49, 50)

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  10. #10
    superhaNds is offline Senior Member
    Join Date
    Apr 2013
    Location
    Sweden
    Posts
    264
    Rep Power
    2

    Default Re: summation of a series

    Quote Originally Posted by JosAH View Post
    That still doesn't fit the funny ending of the series (10, 13, 16 ... 49, 50)

    kind regards,

    Jos
    Of course not. That means that they don't add 3 to every term, in which case they can ignore the post.
    I don't know what fits that series.

  11. #11
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,529
    Blog Entries
    7
    Rep Power
    20

    Default Re: summation of a series

    Quote Originally Posted by superhaNds View Post
    Of course not. That means that they don't add 3 to every term, in which case they can ignore the post.
    I don't know what fits that series.
    I do, but it's ugly: for the (x, y) points (0, 10), (1, 13), (2, 16) ... (13, 49), (14, 50) construct a Lagrange (interpolation) polynomial and voila.
    link: http://en.wikipedia.org/wiki/Lagrange_polynomial

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. summation in java using for loops
    By java157 in forum New To Java
    Replies: 3
    Last Post: 03-17-2011, 08:33 AM
  2. Summation Problem
    By a7x75 in forum New To Java
    Replies: 8
    Last Post: 02-05-2010, 05:38 AM
  3. Fibonacci summation problem
    By xcallmejudasx in forum New To Java
    Replies: 3
    Last Post: 12-01-2009, 06:28 PM
  4. (Help) Quotient summation with prime numbers
    By SapphireSpark in forum New To Java
    Replies: 27
    Last Post: 10-24-2008, 08:28 AM
  5. (Help) Fraction Summation and Exponents
    By SapphireSpark in forum New To Java
    Replies: 19
    Last Post: 10-09-2008, 04:01 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •