# Tema 8
08-1  Extremos de una función.

kill(all)$

## Ilustración de la condición de extremo local

f1(x):=2 - (x - 1)^2$
wxplot2d([f1(x)], [x,0,3], [y, 0, 3], [ylabel, ""] , [style, [lines, 2]] , [legend, "f1(x)"], 
[gnuplot_preamble, "set size ratio 1; set grid"] , [nticks, 200] )$

f2(x):=x^2-2*x+2$
wxplot2d([f2(x)], [x,0,3], [y, 0,3], [ylabel, ""] , [style, [lines, 2]] , [legend, "f1(x)"],
[gnuplot_preamble, "set size ratio 1; set grid"] , [nticks, 200] )$

f3(x):=abs(x^2-2*x-8)$      
wxplot2d([f3(x)], [x, 2, 6] , [y, -2, 6], [ylabel, ""] , [style, [lines, 2]] , [legend, "f1(x)"],
[gnuplot_preamble, "set size ratio 1; set grid"] , [nticks, 200] )$

f1(x):=2 - (x - 1)^2$       y1(x):=2$
wxplot2d([f1(x), y1(x)], [x,0,3], [y, 0,3], [ylabel, ""] , [style, [lines, 2]] , [legend, "f1(x)", "y1(x)"],
[gnuplot_preamble, "set size ratio 1; set grid"] , [nticks, 200] )$

f2(x):=x^2-2*x+2$           y2(x):=1$
wxplot2d([f2(x), y2(x)], [x,0,3], [y, 0,3], [ylabel, ""] , [style, [lines, 2]] , [legend, "f2(x)", "y2(x)"],
[gnuplot_preamble, "set size ratio 1; set grid"] , [nticks, 200] )$

f4(x):=x^3$           y4(x):=0$
wxplot2d([f4(x), y4(x)], [x,-2,2], [ylabel, ""] , [style, [lines, 2]] , [legend, "f4(x)", "y4(x)"],
[gnuplot_preamble, "set size ratio 1; set grid"] , [nticks, 200] )$

## Análisis de los puntos críticos y de los puntos 
en los que la función no es derivable

kill(all)$

f1(x):=2 - (x - 1)^2;

define (Df1(x)  , diff(f1(x), x) );

Eq1:  Df1(x) = 0;    solve(Eq1, x);

assume(x >0, x < 1);

is(Df1(x) > 0);     
is(Df1(x) < 0);

forget(x >0, x < 1)$        
assume(x >1, x < 2);

is(Df1(x) > 0);      
is(Df1(x) < 0);

kill(all)$

f4(x):=x^3;

define (Df4(x) , diff(f4(x), x) );

Eq2:  Df4(x) = 0;    solve(Eq2, x);

assume(x >-1, x < 0);

is(Df4(x) > 0);      is(Df4(x) < 0);

forget(x >-1, x < 0)$        
assume(x >0, x < 1);

is(Df4(x) > 0);      is(Df4(x) < 0);

kill(all)$

f3(x):=abs(x^2-2*x-8);

define (Df3(x) , diff(f3(x), x) );

assume(x > 3, x < 4);

is(Df3(x) > 0);      is(Df3(x) < 0);

forget(x > 3, x < 4)$       assume(x > 4, x < 5);

is(Df3(x) > 0);      is(Df3(x) < 0);

## Extremos absolutos

kill(all)$

f5(x):=(x^2*(6-x))^(1/3);

diff(f5(x), x);

ratsimp(%);

define (Df5(x) , %);

Eq3a:  Df5(x) = 0;     solve(Eq3a, x);

assume(x>-1, x<0);      
is(Df5(x) > 0);      is(Df5(x) < 0);

forget(x>-1, x<0)$    assume(x>0, x<1);     
is(Df5(x) > 0);      is(Df5(x) < 0);

forget(x>0, x<1)$   assume(x>3, x<4);      
is(Df5(x) > 0);      is(Df5(x) < 0);

forget(x>3, x<4)$    assume(x>4, x<5);     
is(Df5(x) > 0);      is(Df5(x) < 0);

forget(x>4, x<5)$   assume(x>5, x<6);      
is(Df5(x) > 0);      is(Df5(x) < 0);

forget(x>5, x<6)$    assume(x>6, x<7);     
is(Df5(x) > 0);      is(Df5(x) < 0);

a=a:-6$     b=b:8$      x1=x1:4$        x2=x2:0$
[a, x1, x2, b];     [f5(a), f5(x1), f5(x2), f5(b)];
max(f5(a), f5(x1), f5(x2), f5(b));
min(f5(a), f5(x1), f5(x2), f5(b));

wxplot2d([f5(x)], [x,-6,8], [ylabel, ""] , [style, [lines, 2]] , [legend, "f5(x)"],
[gnuplot_preamble, "set size ratio 1; set grid"] , [nticks, 200] )$