Site logo MA251: Calculus I
Fall 2008
MA251
Readings
Problems
Matlab
Calculating the Riemann Sum is a simple thing to do in Matlab. In order to accomplish this goal, we must first identify a, b, the number of intervals n, and the time step delta. Taking the example from class we have that

>> a = 1; b = 2; n = 2; delta = (b-a)/n;

We can identify our time steps t0, t1, t2,...,tn by using the Matlab command linspace. Notice that the number of timesteps is going to be the number of intervals plus 1. Make a diagram to be sure this makes sense.

>> t = linspace(a,b,n+1);
Then we can identify the function we want to calculate the area under by creating a symbolic function:

>> syms X
>> f = 1./X;

Finally, we can calculate the left hand sum (LH) and right hand sum (RH) using the following two commands:

>> LH = sum(subs(f,X,t(1:n)))*delta
>> RH = sum(subs(f,X,t(2:n+1)))*delta

See if you can modify these rules to calculate an approximate to the area under the curve using the mid-point sum.