Halette C. Burgess
Calc 3
A gradient search is used to locate critical points in a
localized area. The partials - that
form the gradient - approach zero when they approach a critical point. We will be using this program on Maple to
find local minimums.
Exercise one:
> restart:with(plottools):with(linalg):
Warning, the protected names norm and trace have been
redefined and unprotected
> func:=(x,y)->(x+1)^4
+(y-1)^4+1/(x^2*y^2+1);
![]()
> with(plottools):plot3d((x+1)^4
+(y-1)^4+1/(x^2*y^2+1),x=-10..10,y=-10..10);

I would guess the local minimum would be at x=0 and y=0
> a
:= 0: b := 0: del := 1: evalf(func(a, b));
![]()
> plot3d(func(x,y),x=a-del..a+del,
y=b-del..b+del,axes=boxed, style=patchcontour);

> plots[contourplot](func(x,y),x=a-del..a+del,
y=b-del..b+del);

> funcx
:= diff(func(x,y),x);

> funcy
:= diff(func(x,y),y);

> fxpoint
:= evalf(subs({x=a, y=b}, funcx));
![]()
> fypoint
:= evalf(subs({x=a, y=b}, funcy));
![]()
> plot(func(a+fxpoint*t,
b+fypoint*t), t=-1..0);

> pathdiff
:= diff(func(a+fxpoint*t, b+fypoint*t),t);

> tmin
:= fsolve(pathdiff,t=0);
![]()
> a1 := a + tmin*fxpoint; b1 := b +
tmin*fypoint; func(a1, b1);
![]()
![]()
![]()
> a
:= a1; b := b1; currentval := func(a, b);
![]()
![]()
![]()
> print(`currrent
a `=a, `current b `=b, `current val `= currentval);
![]()
> fxpoint
:= evalf(subs({x=a, y=b}, funcx));
![]()
> fypoint
:= evalf(subs({x=a, y=b}, funcy));
![]()
> print(`current
gradient `=[fxpoint,fypoint]);
![]()
> pathdiff
:= diff(func(a+fxpoint*t, b+fypoint*t),t):
> tmin
:= fsolve(pathdiff,t=0);
![]()
> a1
:= a + tmin*fxpoint; b1 := b + tmin*fypoint; func(a1, b1);
![]()
![]()
![]()
The "very accurate" approximation of the local
minimum is at x= -1.391040050 and y=1.391040050.
> plot3d(func(x,y),x=a1-del..a1+del,
y=b1-del..b1+del,axes=boxed, style=patchcontour);

> plots[contourplot](func(x,y),x=a1-del..a1+del,
y=b1-del..b1+del);

Exercise two:
> restart:with(plottools):with(linalg):
Warning, the protected names norm and trace have been
redefined and unprotected
> func
:= (x,y) -> .15*x+3*(.8*y)^(-.87)+(.8*y)*(1+3/x);
![]()
> with(plottools):plot3d(.15*x+3*(.8*y)^(-.87)+(.8*y)*(1+3/x),x=0..10,y=0..10);

>
I would guess the local minimum in this window to be at
about x=1 and y=1
> a
:= 1: b := 1: del := 1: evalf(func(a, b));
![]()
> plot3d(func(x,y),x=a-del..a+del,
y=b-del..b+del,axes=boxed, style=patchcontour);

> plots[contourplot](func(x,y),x=a-del..a+del,
y=b-del..b+del);

>
func
:= (x,y) -> .15*x+3*(.8*y)^(-.87)+(.8*y)*(1+3/x);
initx
:= 10; inity := 10;
funcx
:= diff(func(x,y),x);
funcy
:= diff(func(x,y),y);
a1
:= initx: b1 := inity:
for
i from 1 to 10 do
a
:= a1; b := b1; currentval := evalf(func(a, b));
print(`currrent
a `=a, `current b `=b, `current val `= currentval);
fxpoint
:= evalf(subs({x=a, y=b}, funcx));
fypoint
:= evalf(subs({x=a, y=b}, funcy));
print(`current
gradient `=[fxpoint,fypoint]);
pathdiff
:= diff(func(a+fxpoint*t, b+fypoint*t),t):
tmin
:= fsolve(pathdiff,t=0);
a1
:= a + tmin*fxpoint; b1 := b + tmin*fypoint; func(a1, b1);
od:
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
Local minimum is at x=5.108160844 and y=1.630830381
> a1=5.108160844,b1=1.63083081;
![]()
> plot3d(func(x,y),x=a1-del..a1+del,
y=b1-del..b1+del,axes=boxed, style=patchcontour);

> plots[contourplot](func(x,y),x=a1-del..a1+del,
y=b1-del..b1+del);
