# Tema 8
08-5  Aplicaciones de la derivada. 
          Optimización

## Caracterización de la concavidad, la convexidad  
y las inflexiones de una función

Ejemplo 8.5.1

kill(all)$

f(x):=x^4-x^3-9*x^2;

wxplot2d([f(x)], [x,-3, 3],  [ylabel, ""] , [legend, "" ] , [style, [lines, 2]] ,
[gnuplot_preamble, "set grid"], [nticks, 300] )$

define (Df(x) , diff(f(x), x) );

define (D2f(x) , diff(f(x), x, 2) );

Eq1 : D2f(x) = 0 ;
solve([Eq1], [x]);

wxplot2d([D2f(x)], [x,-3, 3],  [ylabel, ""] , [legend, "D2f(x)" ] , [style, [lines, 2]] ,
[gnuplot_preamble, "set grid"], [nticks, 300] )$

define (D3f(x) , diff(f(x), x, 3) );

x1=x1:-1;       'D3f(x1) = D3f(x1);

x2=x2:3/2;     'D3f(x2)=D3f(x2);

## Resolución de ecuaciones: el método 
de Newton - Raphson

Ejemplo 8.5.2

kill(all)$

Eq1:  x^2 - 8*log(x) = 0;
solve(Eq1, x);

f(x) := x^2 - 8*log(x);

define (Df(x) , diff(f(x), x) );

wxplot2d([f(x)], [x, 0.5, 4],  [y, -2, 6] , [ylabel, ""] , [legend, "f(x)" ] , [style, [lines, 2]] ,
[gnuplot_preamble, "set size ratio 1; set grid"], [nticks, 300] )$

x1=x1:4;    x2=x2:x1 - (f(x1))/(Df(x1)), numer;

x3=x3:x2 - (f(x2))/(Df(x2)), numer;

x4=x4:x3 - (f(x3))/(Df(x3)), numer;

x5=x5:x4 - (f(x4))/(Df(x4)), numer;

x6=x6:x5 - (f(x5))/(Df(x5)), numer;

load(newton1)$
newton(x^2 - 8*log(x), x, 4, 10^(-5));

load(newton1)$
newton(x^2 - 8*log(x), x, 4, 10^(-9));

load(newton1)$
newton(x^2 - 8*log(x), x, 1, 10^(-9));

## Variaciones respecto al tiempo

Ejemplo 8.5.3

kill(all)$

V(t):=(%pi/3)*r(t)^2*y(t);

r(t):=(R/H)*y(t);        'V(t) = V(t);

Eq22: q*t=V(t);

(y(t))^3 = (3*q*H^2) / (%pi*R^2) * t;

define (y(t) , ((3*q*H^2)/(%pi*R^2))^(1/3) * t^(1/3) );

q=q:200$     R=R:20$     H=H:40$

'K=K:((3*q*H^2)/(%pi*R^2))^(1/3), numer;

define (y(t) , K*t^(1/3) );

wxplot2d([y(t)], [t, 0,100], [ylabel, ""] , [legend, "y(t)" ] , [style, [lines, 2]] ,
[gnuplot_preamble, "set size ratio 1; set grid"], [nticks, 300] )$

define (Dy(t) , diff(y(t), t) );

wxplot2d([Dy(t)], [t, 0.1,90] , [y, 0, 8] , [ylabel, ""] , [legend, "y(t)" ] , [style, [lines, 2, 2]] ,
[gnuplot_preamble, "set size ratio 1; set grid"], [nticks, 300] )$

diff(Dy(t), t);

La derivada segunda es negativa: la derivada primera es decreciente.

fpprintprec : 5$

Eq24: y(t)=25;        solve([Eq24], t);

t0 = t0 : 10757271671875/525948789248, numer;

'Dy(t0)=Dy(t0);

## Optimización

Ejemplo 8.5.4

kill(all)$

L1(x):=R*x;     L2(x):=2*%pi*R - R*x;

r(x):=(2*%pi*R - R*x)/(2*%pi);

h(x):=sqrt(R^2 - ((2*%pi*R - R*x)/(2*%pi))^2);

V(x):=(%pi/3)*(r(x)^2)*h(x);

diff(V(x), x);

ratsimp(%);

DV(x):=-((2*x^3-12*%pi*x^2+16*%pi^2*x)*R^4+
(x^3-6*%pi*x^2+12*%pi^2*x-8*%pi^3)*R^4)/(24*%pi^2*sqrt(4*%pi*x-x^2)*R);

Eq1:DV(x)=0;

solve([Eq1], [x]);

x1=x1:-((2*sqrt(6)-6)*%pi)/3, numer;
x2=x2:((2*sqrt(6)+6)*%pi)/3, numer;
x3=x3:2*%pi, numer;

diff(DV(x), x);

D2V(x):=(-9*x^2+36*%pi*x-28*%pi^2)/(24*%pi^2*sqrt(4*%pi*x-x^2)) - 
((4*%pi-2*x)*(-3*x^3+18*%pi*x^2-28*%pi^2*x+8*%pi^3))/(48*%pi^2*(4*%pi*x-x^2)^(3/2));

'D2V(x1)=D2V(x1), numer;

R=R:1$
r(x):=(2*%pi*R - R*x)/(2*%pi)$
h(x):=sqrt(R^2 - ((2*%pi*R - R*x)/(2*%pi))^2)$
V(x):=(%pi/3)*(r(x)^2)*h(x)$

wxplot2d([V(x)], [x, 0, 2*%pi] , [ylabel, ""] , [legend, "V(x)" ] , [style, [lines, 2, 3]] ,
[gnuplot_preamble, "set size ratio 1; set grid"], [nticks, 300] )$