
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)
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();
Well, that's done.
Second Part (create a row 1.011.0 using the f(x) = 2*x + 1)
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();
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)
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.

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.
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.

Re: Sum sequence
Allright I found it with, this topic can be locked.