CPI 200, G. Farin

Integrals

The area under f over [0,1] is given by

	(∫_0^1)f(t)dt
	
The area under f over [0,x] is given by

	A(x)=(∫_0^x)f(t)dt

The rate of change of the area under f over [0,x] is given by

	A’(x)=f(x)
	
That is the fundamental theorem of calculus,

The following are plots of precipitation data for Phoenix. Raw rainfall data are in rain, accumulated rainfall is in accumrain.

rain=WeatherData["Phoenix", "TotalPrecipitation", {{2011, 1, 1}, {2013, 1, 1}, "Month"}];


rainvals=Table[rain[[i,2]],{i,1,length}];
length=Length[rain];
accumrain=Table[0,{i,1,length}];
Do[
If[i==1,accumrain[[i]] =rainvals[[1]],accumrain[[i]]=accumrain[[i-1]]+rainvals[[i]]/length],{i,2,length}];

ListPlot[{accumrain,rainvals}, Joined->True,Filling->Axis]//N

Areas

h=0.02; (* step length *)
n=1/h; (* how many steps *)
f[x_]:=Sin[3x]^2 + x; (* example function *)



fplot=Plot[{Thick,Red,f[x]},{x,0,1},PlotRange->All,AxesOrigin->{0,0},Filling->Axis];

ff[i_]:=If[i==0,0,ff[i-1]+h*f[i*h]];
(*accumulated area from 0 to i*h *)

approxarea=ff[n];

areaplot[n_]:=ListLinePlot[Table[ff[i],{i,0,n}],PlotStyle->Thick,DataRange->{0,1},PlotRange->All,AxesOrigin->{0,0},Filling->Axis,InterpolationOrder->0,FillingStyle->Directive[Opacity[0.5],Orange]];

Show[{areaplot[n],fplot}]

Print["actual area over [0,1]: ",Integrate[f[x],{x,0,1}]//N];
Print["approximated area over [0,1]: ",approxarea//N];

f[x_]:=1+2x-3x^2+0.5x^3;

int[x_]:=Integrate[f[t],{t,0,x}];

Plot[{Red,f[x],Blue,int[x]},{x,0,2Pi},Filling->Axis]

(* take the derivative of int[x]: you'll get f[x] back!  *)
Plot[{Red,int'[x]},{x,0,2Pi},Filling->Axis]