Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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.

If it is OK, please help me with this.

share|improve this question

closed as too broad by Nasser, Vitaliy Kaurov, Pinguin Dirk, Kuba, Sjoerd C. de Vries Sep 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.

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

1 Answer 1

up vote 4 down vote accepted

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

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.