Example: Tangent Planes and Gradient Descent
Plotting contour plots and the gradient
restart ;
with(plots): with(plottools) : with(LinearAlgebra):
f := 4*x^2 - 5*x*y + 3*y^2 ;
fx := diff(f,x); fy := diff(f,y);
gradient_f := <fx,fy>;
x0 := -1; y0 := 1;
g0 := Normalize(subs({x=x0,y=y0},gradient_f));
contour_plot := contourplot(f,x=-3..3,y=-3..3):
gradient_line := line([x0,y0],[x0+g0[1],y0+g0[2]]):
display({contour_plot,gradient_line});