Results 1 to 3 of 3
Thread: Sum sequence
 09252011, 03:37 AM #1Member
 Join Date
 Sep 2011
 Posts
 14
 Rep Power
 0
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.05.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.05.0 System.out.print(" "); //print space between the values } System.out.println();
Second Part (create a row 1.011.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.011.0 System.out.print(" "); //print space between values } System.out.println();
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); }
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.
 09252011, 08:32 PM #2Member
 Join Date
 Sep 2011
 Posts
 14
 Rep Power
 0
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);
 09262011, 07:30 PM #3Member
 Join Date
 Sep 2011
 Posts
 14
 Rep Power
 0
Similar Threads

complete sequence
By aizen92 in forum New To JavaReplies: 25Last Post: 12292010, 12:58 PM 
Fibonacci sequence
By ŖàΫ ỏƒ Ңόρę in forum New To JavaReplies: 6Last Post: 03252010, 07:59 AM 
Linked list sequence and array sequence
By Predz in forum New To JavaReplies: 1Last Post: 12312009, 02:30 AM 
calling sequence
By rocky in forum Web FrameworksReplies: 0Last Post: 04272009, 09:35 PM 
Escape Sequence
By Punter in forum New To JavaReplies: 4Last Post: 02102009, 08:04 AM
Bookmarks