Prof. Walter Mora F.
 Escuela de Matemática. 
  Instituto Tecnológico de Costa Rica

Requiere instalar MaTeX: Ver 0-InstalarMaTeX.nb

DynamicModule[{initDone=False},
Dynamic[If[Not@TrueQ@initDone,
Panel[
Row[{ProgressIndicator[Appearance->"Necklace"],Style["   Un momento por favor...",12,Red, Bold]}]
],
(*body---------------------------------------------------------------------------------------------------------*)
bodyCDICap4ProblemaOptimizacionI
(*-------------------------------------------------------------------------------------------------------- body-*)
],TrackedSymbols:>{initDone}],
UnsavedVariables:>{initDone},
SynchronousInitialization->False,
SaveDefinitions->True,
(*Ini---------------------------------------------------------------------------------------------------------*)
Initialization:>(
bodyCDICap4ProblemaOptimizacionI=Manipulate[
(*Malla*)
Grid[{
(* ------         Columna 1: parte interactiva       ------*)
{Column[{
Row[{  "Optimización"     }],
LocatorPane[
(*     a = First@CDIOptej1pt,   f(a) = CDIOptej1fun[ First@CDIOptej1pt ]  *)
Dynamic[CDIOptej1pt,(CDIOptej1pt={Clip[#[[1]],{0.001,4}  ],0};
(*Pt se mueve entonces actualiza tabla de valores, agregando el nuevo valor*)
CDIOptej1TablaVals=Join[CDIOptej1TablaVals,{ {First@CDIOptej1pt,CDIOptej1Area[ First@CDIOptej1pt ]}  }]
)&],
(* -----   -------*)
Dynamic@Graphics[{
RGBColor[0.3, 0.3, 1],Opacity[0.6],
(*--Trapecio--*)
Polygon[{(*(-4,0),(-a, f[-a]),(a,f[a]),(4,0)*)
{-4,0},{-CDIOptej1pt[[1]],CDIOptej1fun[-CDIOptej1pt[[1]]]},
{CDIOptej1pt[[1]],CDIOptej1fun[CDIOptej1pt[[1]]]},{4,0}
}],Opacity[1],
(*--Curva--*)
First@ParametricPlot[{4Cos[t],4Sin[t]}, {t, 0, Pi},
PlotStyle->{RGBColor[0, 0.3, 0],Thickness[0.01] }],
(*--Vértices--*)
PointSize[Large],RGBColor[0, 0.05, 0],Map[Point,{{-4,0},{4,0},
{-CDIOptej1pt[[1]],CDIOptej1fun[-CDIOptej1pt[[1]]]},
{CDIOptej1pt[[1]],CDIOptej1fun[CDIOptej1pt[[1]]]}  }],
(*Agregar "Altura"*)
Dashed, White, Line[{CDIOptej1pt,{CDIOptej1pt[[1]],CDIOptej1fun[-CDIOptej1pt[[1]]]}}],
 Line[{-CDIOptej1pt,{-CDIOptej1pt[[1]],CDIOptej1fun[-CDIOptej1pt[[1]]]}}],
(*Agregar "h"*)
Text[Style["h", Bold, 16, White,FontFamily->"Times", Italic], {CDIOptej1pt[[1]]-0.1, CDIOptej1fun[-CDIOptej1pt[[1]]] /2 },{1,0}],
(*Base menor "2a"  y coordenada "a"*)
Black,Dashing[{}],
Arrowheads[{-0.04,0.04}] (*doble flecha, de "-a" a "a"*),
Arrow[{{-CDIOptej1pt[[1]],-0.4},{CDIOptej1pt[[1]],-0.4}}],
Text[, {0,  -0.8}],
Red,
Text[Style["a", Bold, 11, FontFamily->"Helvetica"], { CDIOptej1pt[[1]], -0.2}],
Text[Style["-a", Bold, 11, FontFamily->"Helvetica"], { -CDIOptej1pt[[1]], -0.2}]
},
GridLines->{Range[-5,5],Range[0,5]},GridLinesStyle->LightGray, (*Maya gris*)
Ticks->{Automatic,{1,2,3,4}},
AxesStyle->Arrowheads[0.04], (*Flechas en los ejes*)
Axes->True, 
PlotRange->{{-5,5},{-1,5}},
ImageSize->400]
]
}](*Columna 1*),
Spacer[10],
(* ------    Columna 2: Imprime   últimos 5 valores de la tabla      ------*)
Dynamic@CDItablavals["a", "(Subscript[A, T])(a)", Take[CDIOptej1TablaVals,-5],7],                      (*--- POR QUÉ -5 Y 7*)
Spacer[10],
(* ------    Columna 3: El gráfico Area T vs a  ------*)
Dynamic@ListPlot[CDIOptej1TablaVals,
PlotStyle->PointSize[Medium],AxesOrigin->{0,0},
 AxesLabel->{Style["a", Red, Bold, 11, FontFamily->"Times"],Style["Área", Red, Bold, 10]},
PlotRange->{{0,4.5},{0,25}},ImageSize->300,
Epilog->{(*Graficar el punto actual*)
PointSize[Large], Red, Point[{First@CDIOptej1pt,CDIOptej1Area[ First@CDIOptej1pt ]}]
}]
}
}] (*Fin Grid = malla*),
(*-------Zona de controles y opciones-----*)
ContentSize ->Automatic,
AppearanceElements->None,
SaveDefinitions->True,
Alignment->{Center,Top},
Initialization->{(* -----   INI  ------*)
(*Formato para la tabla de valores*)
(*Uso: cap5tablavalsAp[ "x", " f(x) ", LaTabla, tamaño ]*)
CDItablavals[x_,y_, ladata_, itemsize_]:=Text@Grid[
Prepend[Prepend[ladata,{x,y}],{"Tabla de Valores" ,SpanFromLeft}],
Background->{
None,{None,(*color fila 1*)
GrayLevel[0.9],(*color fila 2*)
{White,Lighter[Blend[{Blue,Green}],.8]}}},(*color fila i>1*)
Dividers->{{2->GrayLevel[0.7]},{True,True}},(*{{vlines}, {hlines} *)
Alignment->{{Center,Center}},
ItemSize->{{3,itemsize}},Frame->True,
Frame->Darker[Gray,.6],
ItemStyle->12,Spacings->{Automatic,.5}
];
(*Tabla de valores: Toma solo 10 elementos*)
CDIOptej1pt={1,0};
CDIOptej1fun[x_]=Sqrt[16-x^2];
(*Tabla inicial*)
CDIOptej1TablaVals=Table[{0+dx,CDIOptej1Area[dx]},{dx,0,1-0.2,0.2}];
(*Tabla para graficar*)
(*Área*)
CDIOptej1Area[a_]=(2*a+8)*CDIOptej1fun[a]/2
}

];
initDone=True)]