# Exercici 11.18

kill(all)$

## Solució pel mètode de Lagrange

Eq1: P = x + 2*y + 2*(2*x);

sqrt( (2*x)^2 - (x/2)^2);

h : (sqrt(15)*(x))/2;

A(x,y):= x*y + (1/2)*x*h;

L(x,y,%lambda) := A(x,y) + %lambda * (P - 2*y - 5*x);

EqL1:  diff(L(x,y,%lambda), x) = 0;
EqL2:  diff(L(x,y,%lambda), y) = 0;
EqL3:  P-2*y-5*x = 0;

solve ( [EqL1, EqL2, EqL3] , [x,y,%lambda]);

P = P:100;

A(x):= x * (P-5*x)/2 + (1/2)*x*(sqrt(15)*x)/2;

x0=(sqrt(15)*P+10*P)/85, numer;

wxplot2d([A(x)], [x,0,30], [ylabel, ""] , [legend, "A(x)"] , [style,  [lines, 2]] ,
[gnuplot_preamble, "set grid;"])$

## Solució per reducció a 1 variable

kill(all)$

Eq1: P = x + 2*y + 2*(2*x);
solve( Eq1, y);

sqrt( (2*x)^2 - (x/2)^2);

h : (sqrt(15)*(x))/2;

A(x):= x*((P-5*x)/2) + (1/2)*x*((sqrt(15)*x)/2);

diff(A(x), x);

solve ( diff(A(x), x) = 0, x );

P:100;

x0=-P/(sqrt(15)-10), numer;

wxplot2d([A(x)], [x,0,30], [ylabel, ""] , [legend, "A(x)"] , [style,  [lines, 2]] ,
[gnuplot_preamble, "set grid;"])$