- #1
ncp1044
- 8
- 0
So I'm writing a program to do a riemann sum. The final answer should be Pi.
My function: f(x) = 4/(1+x^2) a = 0 b = 1 n = 40,000,000
For a riemann sum, delta x = (b-a)/n so (1-0)/40,000,000 = 1/40,000,000.
Then the riemann sum looks like:
(1/40,000,000) [f(1/40,000,000) + f(2/40,000,000) + f(3/40,000,000) + ...until you get f(40,000,000/40,000,000)]
That's the math behind the problem, now onto the pseudo code:
Enter limits (lower, upper)
lower = i upper = j
s = 0
while i =< j
s = s + 4/(1 + (i/j)^2)
i = i + 1
answer = s * 1/j
The limits mentioned in the code above are i = 1 and j = 40,000,000
I'm not very confident on my pseudo code; any feedback would be helpful.
My function: f(x) = 4/(1+x^2) a = 0 b = 1 n = 40,000,000
For a riemann sum, delta x = (b-a)/n so (1-0)/40,000,000 = 1/40,000,000.
Then the riemann sum looks like:
(1/40,000,000) [f(1/40,000,000) + f(2/40,000,000) + f(3/40,000,000) + ...until you get f(40,000,000/40,000,000)]
That's the math behind the problem, now onto the pseudo code:
Enter limits (lower, upper)
lower = i upper = j
s = 0
while i =< j
s = s + 4/(1 + (i/j)^2)
i = i + 1
answer = s * 1/j
The limits mentioned in the code above are i = 1 and j = 40,000,000
I'm not very confident on my pseudo code; any feedback would be helpful.