# Definite integral using Riemann sums [closed]

I just started learning Mathematica. It seems like a good program to learn. I only know some basics though. I came across this problem online which I want to learn how to solve:

Write a Mathematica program to approximate a definite integral using Riemann sums.

-
–  Nasser Sep 5 '13 at 3:40
You might find this question and its answers relevant to your problem. –  m_goldberg Sep 5 '13 at 6:33

## closed as too broad by Nasser, Vitaliy Kaurov, Pinguin Dirk, Kuba, Sjoerd C. de VriesSep 5 '13 at 7:08

There are either too many possible answers, or good answers would be too long for this format. Please add details to narrow the answer set or to isolate an issue that can be answered in a few paragraphs.If this question can be reworded to fit the rules in the help center, please edit the question.

I made this for you. It should get you started.

Here you can type a function to integrate, for example:

 func[x_] := 1/Exp[x]


This is your integrator. It takes a function f, a lower and upper bound a,b and a step size l:

 riemint[f_, a_, b_, l_] := Total[ Table[ f[i]*l, {i, a, b - l, l}]]


You can try it out like this:

 riemint[ func, 1, 5, .0001]


As it is set here, that evaluates to $0.36116$. Use this to compare:

 NIntegrate[ func[x], {x, 1, 5}]


That gives about $0.36114$. Have fun with your Mathematica, and note that you can do MUCH better than this functionality wise with a little effort. :)

-