CellPrint[TextCell[Quiet[cdf =Manipulate[SuFunc[u, ff],Style[proposito,Bold,10],Spacer[{100,3}],
 (*Inicio contadores *)
 
 {{u,1,"Opción = "},{1-> "Trapecio", 2->"Simpson", 3->"Tres Octavos", 4->"Punto Medio"},ControlType->PopupMenu},
{{nn,9,"n="},ControlType->InputField}
,
{{ff,x^4,"f(x) = "},ControlType->InputField},
{{puntoA,0,"a = "},ControlType->InputField},
{{puntoB,1,"b = "},ControlType->InputField},
Button["Calcular",pos =u; If[u==1, u=2, u=1];u=pos;  SuFunc[Dynamic@u, ff]] ,
{{math,0,"Calcular con Mathematica "},{0,1},ControlType->Checkbox},
{{darerror,0,"Dar error Aprox. "},{0,1},ControlType->Checkbox}

(* Fin contadores *)

,Alignment->Center,Deployed->True,AppearanceElements->"ResetButton",LocalizeVariables->True,ContinuousAction->False,FrameLabel->{{None,None},{Column[{,Row[{Style["Autores: Juan Félix Ávila Herrera y Enrique Vílchez Quesada",Bold,10,RGBColor[0,0,0.5]]}],Row[{Style["Escuela de Informática | Universidad Nacional de Costa Rica",Bold,10,RGBColor[0.5,0.1,0]]}]},Center],Style["Aproximación numérica de integrales definidas usando las fórmulas compuestas de Newton-Cotes.", Bold,14, RGBColor[0,0.33,0.33]]}},
Initialization:>(
 ClearAll["Global`*"];
escriba[lista_]:=Style[Row@lista,Black];


integre = ToString[TraditionalForm@Defer[(∫_a^b)f[x]\[DifferentialD]x]];
PuntoMedioCompuesto[ n_] := Module[{h},h =((b-a)/(n+2)); 
2h  (∑_(k=0)^(n/2))f[a+(2k+1)*h]  
];
TresOctavoCompuesto[ n_] := Module[{h, A, B},h =((b-a)/n); 
 A =Total@Table[f[a+k h]+f[a+(k+1) h], {k, 1, n-2, 3}];
 B =Total@Table[f[a+k h], {k, 3, n-3, 3}];
 ((3h)/8)(f[a]+3A+2B+f[b])
];
 
formulas:={
{(h/2)(f[a]+f[b]+2 (∑_(k=1)^(n-1))f[a+k*h]  ) , ((-(b-a)h^2f''[ξ])/12),"(Regla compuesta del trapecio)\n"},
{(h/3)(f[a]+f[b]+2 (∑_(k=1)^(n/2-1))f[a+2k*h] +4(∑_(k=1)^(n/2))f[a+ h(2k-1)] ), ((-(b-a)h^4 )/180)* Derivative[4][f][ξ],"(Regla compuesta de Simpson)\n"},
{TresOctavoCompuesto[ n], (((b-a)h^2f''[ξ])/2),"(Regla compuesta de tres octavos)\n"},
 {PuntoMedioCompuesto[n], (((b-a) h^2 )/6)* Derivative[2][f][ξ],"(Regla Compuesta del Punto Medio)\n"}
 
};

Clear[f];

(*($PreRead=(#/. s_String/;StringMatchQ[s,NumberString]&&Precision@ToExpression@s==MachinePrecision:>s<>"`12."&));*)
proposito ="Propósito: Usar fórmulas compuestas para aproximar " <>integre;(*TraditionalForm@Defer[(∫_a^b)f[x]\[DifferentialD]x] ;*)

SuFunc[k_, ff_]:=Module[{aux, resp, pt, coef, error, max, val, hache = ((puntoB-puntoA)/nn)},
n=nn;
Which[u==2∨u==4,  If[¬EvenQ[nn], nn++], u==3, While[Mod[nn, 3] ≠0, nn++]   ];

resp[x_] := If[val =x; val==Round[val], x,escriba@{x," ≈ ",ToString[Sign[x] AccountingForm[Abs@N@x]]}];
(*resp[x_] := N@x;*)


Clear[f, g];
g[t_] = ff/.x->t;
aux =N@formulas[[u]][[1]]/.{a-> puntoA,b-> puntoB, h->hache, f->g   };
If[darerror==1, error =formulas[[u]][[2]]/.{a-> puntoA,b-> puntoB, h->hache, f->g };
error=Simplify[error];];

max =N@Quiet[ Maximize[Abs[error], puntoA≤ξ≤ puntoB, ξ]];
 
(*aux = ToString@ TraditionalForm[ (∫_a^b)f[x]\[DifferentialD]x ]<>"≈ "<>*)
aux =  {"Fórmula usada:\n" , 
  formulas[[u]][[3]] , integre ,
  "≈", (*TraditionalForm@formulas[[u]][[1]],"\n",integre ,  "≈" ,  *)
   ToString[Sign[aux] AccountingForm[Abs@aux]] } ;
If[math==1, aux = Join[aux, { 
   "\nUsando Mathematica: " ,  integre ,  " = " ,  resp[(∫_puntoA^puntoB)g[x]\[DifferentialD]x]}  ]];
If[darerror==1, aux = Join[aux, {"\nNota. Error usando Aprox =",TraditionalForm[error], "\n|Error Aprox.| ≤" , TraditionalForm@max[[1]]}]];
escriba@aux
 
];
SuFunc[1, ff]
)]],"Text"]]