So I'm writing a program to do a riemann sum. The final answer should be Pi.(adsbygoogle = window.adsbygoogle || []).push({});

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.

**Physics Forums - The Fusion of Science and Community**

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Pseudo code for reimann sum

Loading...

Similar Threads - Pseudo code reimann | Date |
---|---|

What should be the rules to write excellent code? | Mar 12, 2018 |

Help on converting code to pseudocode? | Oct 1, 2015 |

Understanding of this pseudo-code | Jul 13, 2015 |

Is this algo and pseudo for cylinder correct? | Mar 27, 2011 |

Writing pseudo-code | Mar 30, 2008 |

**Physics Forums - The Fusion of Science and Community**