Test 2 Key
Andy Long
Spring, 2016

#1

Clear[f,x,y]
f[x_,y_]:=Sin[2x+3y]
fx=D[f[x,y],x]
fy=D[f[x,y],y]
grad={fx,fy}
x=-6
y=4
du=grad
u={2,-1}
uhat=u/Norm[u]
Dot[du,uhat]
Clear[f,x,y]

#2

Clear[f,fx,fy,x,y,xs,ys]
f[x_,y_]:=x y(1-x-y)
fx[x_,y_]=Simplify[D[f[x,y],x]]
fy[x_,y_]=Simplify[D[f[x,y],y]]
fxx[x_,y_]=Simplify[D[fx[x,y],x]]
fyy[x_,y_]=Simplify[D[fy[x,y],y]]
fxy[x_,y_]=Simplify[D[fx[x,y],y]]
solns=Solve[fx[x,y]==0 &&fy[x,y]==0,{x,y}]
disc[x_,y_]:=Simplify[fxx[x,y]fyy[x,y]-fxy[x,y]^2]

xs=Replace[x,solns];
ys=Replace[y,solns];
Table[disc[xs[[i]],ys[[i]]],{i,1,4}]
Table[f[xs[[i]],ys[[i]]],{i,1,4}]
Plot3D[f[x,y],{x,-2,2},{y,-2,2}]
ContourPlot[f[x,y],{x,-2,2},{y,-2,2}]

#3

Clear[f,fx,fy,x,y,xs,ys]
f[x_,y_]:=E^(x y)
h[x_,y_,lambda_]:=f[x,y]-lambda(x^3+y^3-16)
hx[x_,y_,lambda_]=Simplify[D[h[x,y,lambda],x]]
hy[x_,y_,lambda_]=Simplify[D[h[x,y,lambda],y]]
hlambda[x_,y_,lambda_]=Simplify[D[h[x,y,lambda],lambda]]

solns=Solve[hx[x,y,lambda]==0 &&hy[x,y,lambda]==0&&hlambda[x,y,lambda]==0,{x,y,lambda}]

Plot3D[f[x,y],{x,-4,4},{y,-4,4}]
ContourPlot[f[x,y],{x,-4,4},{y,-4,4}]

#4

Clear[f,fx,fy,x,y,xs,ys]
f[x_,y_]:=x y(1-x-y)
Integrate[f[x,y],{x,0,1},{y,0,1}]
midpoint=1/2*1/2*(f[1/4,1/4]+f[1/4,3/4]+f[3/4,1/4]+f[3/4,3/4])
trapezoidal=1/2*1/2*(1*f[1,1]+2(f[1/2,1]+f[1,1/2]))/4

Plot3D[f[x,y],{x,0,1},{y,0,1}]
ContourPlot[f[x,y],{x,0,1},{y,0,1}]

#5

Clear[f,fx,fy,x,y,xs,ys]
f[x_,y_]:=2-x-y
RegionPlot3D[0≤x≤2 && 0≤y≤2-x&&0≤z≤f[x,y],{x,0,2},{y,0,2},{z,0,2}]
Integrate[f[x,y],{x,0,2},{y,0,2-x}]

#6

Clear[f,fx,fy,x,y,xs,ys]
f[x_,y_]:=x
RegionPlot3D[-2≤x≤4 && x^2/2-3≤y≤x+1&&-2≤z≤f[x,y],{x,-2,4},{y,-3,5},{z,-2,4}]
Integrate[f[x,y],{x,-2,4},{y,x^2/2-3,x+1}]