
clear; close
disp('     LAGRANGE MULTPLIERS  Second Example  ')
disp( ' ')
disp('  Find the extreme points of  ')
disp('                 f(x,y) = x^3 +x^2 +y^2/3   ')
disp('   on the circle  ')
disp('   g(x,y) = x^2 +y^2 - 36 = 0  ')

corners = [ -8,8, -7,7];
f = inline(' x.^3 +x.^2  + .5*y.^2 ', 'x', 'y');
g = inline(' x.^2 + y.^2 - 36 ', 'x', 'y')

lagrange(f,g,corners)

disp('  The lagrange system is  ')
disp('            x^2 +2*x -2*lambda*x = 0 ')
disp('            (2/3)*y - 2*lambda*y = 0')
disp('                   x^2 +y^2 - 36 = 0 ')
disp('  The solutions are ')
disp(' ')

clear x y
syms x y lambda
eq1 = 3*x^2 +2*x - 2*lambda*x;
eq2 = (2/3)*y - 2*lambda*y ;
g = x^2 +y^2 - 36;
[lambda, x y] = solve(eq1,eq2, g);
disp(' ')
disp('   lambda       x         y        f(x,y)')
   A = zeros(6,4);
   A(1:6, 1:3) =  double([lambda, x,y]);
   for i = 1:6
       A(i,4) = f(A(i,2),A(i,3));
   end
  A
  pause
  close
  
 

