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---------------------------------------------------------------------------------------------------------*)
bodyCDICap1DerivadaDefinicion
(*-------------------------------------------------------------------------------------------------------- body-*)
],TrackedSymbols:>{initDone}],
UnsavedVariables:>{initDone},
SynchronousInitialization->False,
SaveDefinitions->True,
(*Ini---------------------------------------------------------------------------------------------------------*)
Initialization:>(
bodyCDICap1DerivadaDefinicion=Manipulate[
(*Malla*)
Grid[{
(* ------         Columna 1: parte interactiva       ------*)
{Column[{
LocatorPane[
(*     a = First@cap3dvxh,   f(a) = fun[ First@cap3dvxh ]  *)
    Dynamic[{cap3dvx0,cap3dvxh},(cap3dvx0={1.0*Round[First@#[[1]],10.^-1],0}; cap3dvxh={Clip[First@#[[2]],{First@#[[1]]+0.0001, First@#[[1]]+2}],0};
(*Pt se mueve entonces actualiza tabla de valores, agregando el nuevo valor*)
Do[cap3dvDfTablaVals[[i,1]]=First@cap3dvx0,{i,Take[Range[1,Length[cap3dvDfTablaVals]],-4]}];
cap3dvDfTablaVals=Join[cap3dvDfTablaVals,{ {First@cap3dvx0,First@cap3dvxh,cap3dvDfPC[First@cap3dvx0,First@cap3dvxh ]}  }]
)&],
(* -----   -------*)
   Dynamic@With[{baseG=cap3dvDfGr,lax=First@cap3dvx0, laxmh=First@cap3dvxh, lah=(cap3dvx0+cap3dvxh)/2 },
 Graphics[{
(*línea coordenadas*)
Dashed,GrayLevel[0.3],
Line[{cap3dvx0+{0, -1},{lax,cap3dvlaf[lax]}}],Line[{cap3dvxh+{0, -1},{laxmh,cap3dvlaf[laxmh]}}],
Black, Dashing[{}],
baseG,
(*Tangente *)
First@Plot[{cap3dvlaf'[lax] (x-lax)+cap3dvlaf[lax]},{x,0,3},PlotStyle->{Thick,Red,Arrowheads[0.04]}]/.Line->Arrow,
(*cuerda*)
Thick,RGBColor[0, 0.35, 0],Line[{cap3dvL[-1],cap3dvL[3]}],
(*Puntos de arrastre*)
(*Thick,EdgeForm[RGBColor[0, 0.35, 0]],Gray,Disk[cap3dvxh,{0.08,0.12}],
EdgeForm[Red],Gray,Disk[cap3dvx0,{0.08,0.12}],*)

PointSize[Large],RGBColor[0,0.5,0],Point[cap3dvxh],
Red,Map[Point,{cap3dvx0,{lax,cap3dvlaf[lax]}}],
RGBColor[0, 0.35, 0],Point[{laxmh,cap3dvlaf[laxmh]}](*(x0, f(x0))*),
Text[Style[ "x",Bold,wmorado ],{lax,-0.35}],Text[Style[ "x+h",Bold,wmorado ],{laxmh,-0.35},{-1,0}],
(* h en texto*)
Text[Style["h",11,Bold,wmorado],lah+{0,-1.2} ],
Arrowheads[{-.03,.03}],
Arrow[{cap3dvx0+{0,-1},cap3dvxh+{0,-1} }]
},
PlotRange->{{-1,5},{-2,5}},AspectRatio->0.65,Axes->True,AxesOrigin->{0,0},
AxesStyle->Arrowheads[0.04], GridLines->{Range[-1,5],Range[-1,5]},
GridLinesStyle->Directive[LightGray], Ticks->None
,ImageSize->400]] (*Graphics*)](*with*)
}](*Columna 1*),
Spacer[10],
(* ------    Columna 2: Imprime   últimos 5 valores de la tabla      ------*)
Dynamic@cap3dvDfImprimirTabla["x","x+h", Take[cap3dvDfTablaVals,-5],7]
}
}] (*Fin Grid = malla*),
(*-------Zona de controles y opciones-----*)
ControlPlacement->{Left,Top},SaveDefinitions->True,TrackedSymbols->True,
ContentSize ->Automatic,
ControlPlacement->Left,
AppearanceElements->None,
SaveDefinitions->True,
Alignment->{Center,Top},
SynchronousInitialization->False,
Initialization->{(* -----   INI  ------*)
cap3dvx0={1.5,0},cap3dvxh={2.5,0};
wmorado=RGBColor[0.18,0.04,0.499];
cap3dvL[t_]:={First@cap3dvx0,cap3dvlaf[First@cap3dvx0]}+t*({First@cap3dvxh-First@cap3dvx0,cap3dvlaf[First@cap3dvxh]-cap3dvlaf[First@cap3dvx0]}/Norm[{First@cap3dvxh-First@cap3dvx0,cap3dvlaf[First@cap3dvxh]-cap3dvlaf[First@cap3dvx0]}]),
(*Formato para la tabla de valores*)
(*Uso: cap5tablavalsAp[ "x", " f(x) ", LaTabla, tamaño ]*)
cap3dvDfImprimirTabla[x_,y_, ladata_, itemsize_]:=Text@Grid[
Prepend[Prepend[ladata,{Style[x,Italic, Red],Style[y,Italic, RGBColor[0, 0.33, 0]],}],{"Pendiente de la cuerda" ,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],3->GrayLevel[0.7]},{True,True,True}},(*{{vlines}, {hlines} *)
Alignment->{{Center,Center, Center}},
ItemSize->{{3,itemsize}},Frame->True,
Frame->Darker[Gray,.6],
ItemStyle->12,Spacings->{Automatic,.5}
];
cap3dvlaf[x_]=3-(x-2)^2;
(*Tabla de valores: Toma solo 5 elementos*)
cap3dvDfPC[x_,xmh_]:=If[x≠xmh,( cap3dvlaf[xmh]-cap3dvlaf[x])/(xmh-x),( cap3dvlaf[x+0.0001]-cap3dvlaf[x])/(0.0001)];
(*Tabla inicial, la deja en el arranque, en x+h=2.5*)
cap3dvDfTablaVals=Table[{1.5,3-h,cap3dvDfPC[1.5,3-h]},{h,0,0.5,0.1}],
(*Graf Base*)
cap3dvDfGr={(*Curva*)
First@Plot[cap3dvlaf[x],{x, -0.2,4},PlotStyle->{Thickness[0.01]}]}
}
];
initDone=True)]