kill(all)$

load(lrats)$

example : lagrange multiplier,max value nth root product of numbers (x[1],x[2],..,x[n])
                    with constraint on the sum x[i].
 peter.vlasschaert@gmail.com, 03/08/2018

find : Max of  'u' = function ?  with constraint.
=====================================

Given :  ?
**************

function : u
==========

p1: u =(product(x[i],i,1,n))^(1/n);

rem: geometric mean = 'u'

constraint  ,   a = constant
======================

rem : x[1]+x[2]+x[3]+.....+x[n] = a  => x[1]+x[2]+...+x[n]-a=0

p2:sum(x[i],i,1,n)-a;
p2a: p2=0;

---------------------------------------------------------------------------------------------------------------------------------

Answer :  ?
-----------------

combine :'function' and 'constraint'
==============================
=>      λ = lagrange multiplier.

p3:F=rhs(p1)+λ*p2;

to find  Max  u  ?
==============

p4:'diff(rhs(p3),x[i])=diff(rhs(p3),x[i]);

p4a:lratsubst([rhs(p1)=lhs(u)],rhs(p4))=0;

p4b:solve(p4a,u);

check for ,x[1],x[2],...,x[k],...
=======================

first value :  x[i]=x[1]
------------------------------

p5a:subst([x[i]=x[1]],p4b);

second value : x[i]=x[2]
-----------------------------------

p5b:subst([x[i]=x[2]],p4b);

etc ,for all  x[i] =x[3],.....x[i]=x[k], k=1,2,..n.
-------------------------------------------------------------

p5c:subst([x[i]=x[k]],p4b);

p6:solve(p5c,x[k]);

follows x[1]=x[2]=.....=x[k]=... ,
-----------------------------------------------
Answer :  'p6': independent of k

result : Max u ?
=============

put : value into constraint  'p2a'
------------------------------------------------

p7:subst([x[i]=x[k]],p2a);

p7a:solve(p7,x[k]);

why : both side  value 'a' into 'p2a'
=============================

p7b:p2a+a;

result : arithmetic mean ( ' see below  ' )
=================================

p8:subst([rhs(p7b)=lhs(p7b)],p7a);

p8a:p8[1];

definition :geometric mean ,arithmetic mean
=====================================

(product(x[i],i,1,n))^(1/n) ≤ sum(x[i],i,1,n)/n
geometric mean               ≤ arithmetic mean