kill(all)$

constrained optimization (lagrange multiplicator), cylinder, optimal surface,version 1.0
peter.vlasschaert@gmail.com, 06/04/2019

load packages
----------------------

load(lrats)$

cylinder , height = h ,radius =r

product : optimization ( = least material)
===================
cylinder construction :   radius = r, height = h
material   =>  manufacturing circular cylinder.

1e)  volume cylinder  = v  (= constraint)
================================

p1:v = π*r^2*h;

2e) total surface area : A=A(r)
=========================
total surface = bottom + top + surface area .

p2:A(r) = %pi*r^2+%pi*r^2+2*%pi*r*h;

principle lagrange multiplicator (optimalisation problem)
===============================================

variables : 
=========

p3:[r,h];

function :
========

equation 'p2' modified for , two variables.
==================================

rem : define and not  ' := ' for definition.

p3a:define(f(r,h),rhs(p2));

constraint :
=========

declare(v,constant);

p3b:define(g(r,h),rhs(p1) - lhs(p1));

construct : lagrange function
=========================
λ = lagrange multiplicator

=> 
----------------------------------------------
L(x,y,...,λ) = f(x,y,...) + λ*g(x,y,...)
----------------------------------------------
process : below
∂L/∂ x = 0
∂L/∂ y = 0
∂L/∂ λ = 0
-----------------------------------------------------------
rem : only one constrained , v= volume.
-----------------------------------------------------------

p4:define(L(r,h,λ),f(r,h)+λ*g(r,h));

process, diff with respect  to r,h,λ
============================

p4a:'diff('L(r,h,λ),r) = diff(L(r,h,λ),r);

p4b:'diff('L(r,h,λ),h) = diff(L(r,h,λ),h);

;p4c:'diff('L(r,h,λ),λ) = diff(L(r,h,λ),λ);

system : equations
================

p4a1: rhs(p4a) = 0;
p4b1: rhs(p4b) = 0;
p4c1: rhs(p4c) = 0;

How to solve system ?
===================
3 equations => 3 unknowns

p5:solve([p4a1,p4b1,p4c1],[r,h,λ])$

first solution ?
============

p5a:p5[1];

second solution ?
===============

p5b:p5[2];

rem : only complex solutions result no physical meaning.

use linsolve ?

linsolve([p4a1, p4b1, p4c1], [r,h,λ]);

rem : no pratical solutions

solve problem ( optimization,least material)
====================================

1e) solve for , [r,λ]
---------------------------

p6a:solve([p4a1,p4b1],[r,λ]);

p6a1:p6a[1];

2e) solve for , [h,λ]
---------------------------

p6b:solve([p4a1,p4b1],[h,λ]);

p6b1:p6b[1];

rem : 'p4c1' not equations because , constraint be given.
====================================================
h=2r  ?
====================================================
website :
constrained optimization, cylinder, optimal surface,version 1.0
====================================================

volume 'see p1'
=============

p7:subst(p6b1,p1);

v= given  'because constraint'  =>  r ?

find :  'r'
=======

p7a:solve(p7,r);

complex solution : no physical meaning
==================================

p7a1:p7a[1];
p7a2:p7a[2];

real solution  : physical meaning
===========================

p7a3:p7a[3];

h ?   for given v ,why see 'p6b1' use 'p7a3'  =>

p7b3: subst([p7a3],p6b1[1]);

value :v =1000  'volume' ,as before. 'see above ,website'

r => r[min]

p7a31:r[min] = subst([v=1000],rhs(p7a3)),float;

h => h[min]

p7a32:h[min] = subst([r=rhs(p7a31)],rhs(p6b1[1]));

rem : graphics
============
see : website
constrained optimization, cylinder, optimal surface,version 1.0