Results 1 to 3 of 3

Thread: Sum sequence

  1. #1
    Aero is offline Member
    Join Date
    Sep 2011
    Posts
    14
    Rep Power
    0

    Default Sum sequence

    This one is bugging me for a while, perhaps somebody can give me a tip.

    This assigment is split in 3 parts:

    1. Create a row with an interval using doubles
    2. Create a row with a function using the same doubles in that interval
    3. Calculate the som of every point in the function on that interval

    In short a Riemann sum using a lower bound and an upper bound and steps.

    Now to specify the assigment:

    First Part (create a row 0.0-5.0 using lb and ub)
    Java Code:
    double lb = 0;                                              
    double ub = 5;  
    double step = 1; 
    for (double i = lb; i<=ub; i++)                                //create a row
        {
          System.out.print(i);                                      //print row 0.0-5.0
          System.out.print("  ");                                   //print space between the values
        }
    System.out.println();
    Well, that's done.

    Second Part (create a row 1.0-11.0 using the f(x) = 2*x + 1)
    Java Code:
    for (double j = 1; j<=2*ub+1; j=j+2)                        //I created a row equivalent to that function
        {
          System.out.print(j);                                      //print row 1.0-11.0
          System.out.print("  ");                                   //print space between values
        }
    System.out.println();
    And well this works fine, but the next part is going in shambles.

    Third Part (sum of [f(0)+f(1)+f(2)+f(3)+f(4)+f(5)]*step = f(0)*step+f(1)*step+f(2)*step+f(3)*step+f(4)*step+ f(5)*step)
    Java Code:
    for(double k = 0; k <=5; k++)
    { 
    //double sum = k0...k5*step
    System.out.println(sum);
    }
    Here I tried almost everything, I think Part 2 must be done with the function 2*x + 1 and then I have to use that function and throw it in a loop.

    The correct answer should be 36 for a stepsize of 1.0 and when the stepsize gets smaller it will reach 30. As expected because the integration of f(x) = 2*x + 1 is of course F(x) = x^2 + x evalute that at x=5.0 and we get F(5) = 5^2 + 5 = 30.

  2. #2
    Aero is offline Member
    Join Date
    Sep 2011
    Posts
    14
    Rep Power
    0

    Default Re: Sum sequence

    Even now I'm still stuck on this...

    I adapted a new for loop, but if you change the value of the stepsize you will get no results.

    This is for the third part.

    Java Code:
    double max =0;
    for (double k = 0; k<=7*ub+1; k=(k+2)*step)
        {
          if (k>max)
          {
            max = k;
          }
        }
        System.out.print(max);
    So I have to change it so I it can give a better approximation, but as I was typing just now, I'm stuck. Please help.

  3. #3
    Aero is offline Member
    Join Date
    Sep 2011
    Posts
    14
    Rep Power
    0

    Default Re: Sum sequence

    Allright I found it with, this topic can be locked.

Similar Threads

  1. complete sequence
    By aizen92 in forum New To Java
    Replies: 25
    Last Post: 12-29-2010, 11:58 AM
  2. Fibonacci sequence
    By ŖΫ ỏ Ңόρę in forum New To Java
    Replies: 6
    Last Post: 03-25-2010, 06:59 AM
  3. Linked list sequence and array sequence
    By Predz in forum New To Java
    Replies: 1
    Last Post: 12-31-2009, 01:30 AM
  4. calling sequence
    By rocky in forum Web Frameworks
    Replies: 0
    Last Post: 04-27-2009, 08:35 PM
  5. Escape Sequence
    By Punter in forum New To Java
    Replies: 4
    Last Post: 02-10-2009, 07:04 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
  •