MAT329, Test 2
Fall, 2015
Andy Long

f[x_,y_]:=Sin[x]y^2
Plot3D[f[x,y],{x,0,Pi},{y,0,2}]
(* true: *)
Integrate[f[x,y],{x,0,Pi},{y,0,2}]
true=N[%]
(* we need an area element *)
Dx=Pi/2;
Dy=1;
DA=Dx*Dy;
(* here is the mask for trapezoidal *)
mask={{1,2,1},{2,4,2},{1,2,1}}
(* actually the mask is divided by 4: *)
mask=mask/4.0; (* but it's easier to remember if you just use integers! *)
table=Table[f[i*Dx,j*Dy],{i,0,2},{j,0,2}];
trap=DA*Total[Total[table*mask]]
(* mid is also given by a mask, actually, evaluated at midpoints: *)
mask={{1,1},{1,1}}
table=Table[f[(i+1/2)*Dx,(j+1/2)*Dy],{i,0,1},{j,0,1}];
mid=DA*Total[Total[table*mask]]
N[%]

mid=DA*(f[Pi/4,.5]+f[Pi/4,1.5]+f[3Pi/4,.5]+f[3Pi/4,1.5])

(* a multivariate Simpson's rule? *)
Clear[a, simp]
(2 mid + trap)/3
simp[a_]:=a*mid+(1-a)trap
Plot[{simp[a],true},{a,0,1}]
Solve[simp[a]==true, a]

Clear[f,x,y]
f[x_,y_]:=(x^2)+3x y+y^2
p1=Plot3D[f[x,y],{x,-1,1},{y,-1,1}];
x[t_]:=Cos[t]
y[t_]:=Sin[t]
p2=ParametricPlot3D[{x[u],y[u],f[x[u],y[u]]},{u,0,2Pi}];
Show[p1,p2]

(* 
This is a hyperbolic paraboloid: note that it is scale invariant (a different type of symmetry): f(ax,ay)=a^2f(x,y) 
*) 
p1=Plot3D[f[x,y],{x,-10,10},{y,-10,10}];
p2=ParametricPlot3D[{x[u],y[u],f[x[u],y[u]]},{u,0,2Pi}];
Show[p1,p2]

a=(Sqrt[17]-1)/2;
RegionPlot3D[y^2≤x≤a&&0<=z<=4-x^2-y^2,{x,0,2},{y,-Sqrt[a],Sqrt[a]},{z,0,4},PerformanceGoal->"Quality",Mesh->30,BoundaryStyle->Red]
Clear[a]
int=2Integrate[4-x^2-y^2,{y,0,Sqrt[a]},{x,y^2,a}]
a=(Sqrt[17]-1)/2;
N[int]

Clear[a]
int=2Integrate[4-x^2-y^2,{x,0,a},{y,0,Sqrt[x]}]
a=(Sqrt[17]-1)/2;
N[int]