CellPrint[TextCell[Quiet[Manipulate[If[ToString[Criterio]≠ToString[Null],If[!StringContainsQ[ToString[g[x]],"If"]&&!StringContainsQ[ToString[g[x]],"I"],If[NumericQ[g[Quiet[w/.Quiet[FindInstance[Quiet[FunctionDomain[g[w],w]],{w},Reals][[1]]]]]],If[VectorQ[{n,vtolerancia,p0v,p1v},NumericQ],If[!tolerancia,Secante[p0v,p1v,n],Column[{If[etolerancia,SecanteToleranciaE[p0v,p1v,vtolerancia],""],If[ftolerancia,SecanteToleranciaF[p0v,p1v,vtolerancia],""]},Center]],Text[Style["Error en los datos",12]]],Text[Style["Error en los datos",12]]],Text[Style["Error en los datos",12]]],Text[Style["Error en los datos",12]]],Style["Propósito: implementa el método de la secante.",Bold,10],Spacer[{400,2}],{{Criterio,(x^3)-13x-12,"f(x)="}},Delimiter,{{p0v,2.5,"Valor de (Subscript[p, 0])"}},{{p1v,3.5,"Valor de (Subscript[p, 1])"}},{{n,5,"Iteraciones"},Enabled->!tolerancia},Delimiter,{{tolerancia,False,"Tolerancia"},{True,False}},{{vtolerancia,(10^(-3)),"Valor de precisión ξ"},Enabled->tolerancia},OpenerView[{"Criterio para detener las iteraciones:",Column[{Control[{{etolerancia,True,"|(((Subscript[p, n]) - (Subscript[p, n - 1]))/(Subscript[p, n]))|⩽ξ (error relativo)"},{True,False},Enabled->tolerancia}],Control[{{ftolerancia,False,"|f((Subscript[p, n]))|⩽ξ"},{True,False},Enabled->tolerancia}]}]},Dynamic[tolerancia]],Delimiter,Button["Cambiar función",CrearFuncion[{Criterio}]],Alignment->Center,Deployed->False,AppearanceElements->"ResetButton",LocalizeVariables->True,ContinuousAction->True,ControlPlacement->Top,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["Método de la secante", Bold,14, RGBColor[0,0.33,0.33]]}},Initialization:>(Clear[VariableFuncioni,f,CrearFuncion,w,Secante,SecanteToleranciaE,SecanteToleranciaF];CrearFuncion[f_List]:=Module[{FuncionVariable},FuncionVariable[FuncionVariable_List]:=Module[{FuncionVariableAuxiliar,Simbolos,VariableAuxiliarSimbolos,VariableAuxiliarVariables={}},FuncionVariableAuxiliar[]:=FuncionVariable[[1]];Simbolos[VariableFuncion_]:=DeleteDuplicates[Cases[DownValues[VariableFuncion],_Symbol,Infinity]];VariableAuxiliarSimbolos=Sort[Simbolos[FuncionVariableAuxiliar]];For[VariableFuncioni=1,VariableFuncioni≤Length[VariableAuxiliarSimbolos],If[NumericQ[VariableAuxiliarSimbolos[[VariableFuncioni]]]==False,VariableAuxiliarVariables=Append[VariableAuxiliarVariables,VariableAuxiliarSimbolos[[VariableFuncioni]]]];VariableFuncioni++];VariableAuxiliarVariables];Clear[g,x,Ra];g[Ra_]:= Quiet[Evaluate[First[f]]/.Select[FuncionVariable[f],ToString[#]==ToString[x]&][[1]]->Ra]];CrearFuncion[{Criterio}];Secante[vp0_,vp1_,n_]:=Quiet[Module[{p0=vp0,p1=vp1},If[TrueQ[NumericQ[g[p0]]&&NumericQ[g[p1]]],If[(g[p0]-g[p1])!=0,If[n>=2,Module[{vectNiter={0,1},vecPreIm={p0,p1},vecIm={Abs[g[p0]],Abs[g[p1]]},p2,Secti},For[Secti=2,Secti<=n+1,vectNiter=Append[vectNiter,Secti];p2=p1-((g[p1](p0-p1))/(g[p0]-g[p1]));vecPreIm=Append[vecPreIm,p2];vecIm=Append[vecIm,Abs[g[p2]]];p0=p1;p1=p2;Secti++];Style[Grid[{Prepend[vectNiter,"n"],Prepend[vecPreIm//N,"(Subscript[p, n])"],Prepend[vecIm//N,"|f((Subscript[p, n]))|"]},Frame-> All,Alignment->Left],11]],Style["NaD",11]],Style["Se indefine, f((Subscript[p, 0]))-f((Subscript[p, 1]))=0",11]],Style["Error en los datos iniciales",11]]]];SecanteToleranciaE[vp0_,vp1_,tolerancia_]:=TimeConstrained[Quiet[If[tolerancia>0,Module[{p0=vp0,p1=vp1},If[TrueQ[NumericQ[g[p0]]&&NumericQ[g[p1]]],If[(g[p0]-g[p1])!=0,Module[{vectNiter={0,1},vecPreIm={p0,p1},vecIm={Abs[g[p0]],Abs[g[p1]]},Secti=2,p2},While[Abs[((Extract[vecPreIm,-1]-Extract[vecPreIm,-2])/(Extract[vecPreIm,-1]))]>tolerancia,vectNiter=Append[vectNiter,Secti];p2=p1-((g[p1](p0-p1))/(g[p0]-g[p1]));vecPreIm=Append[vecPreIm,p2];vecIm=Append[vecIm,Abs[g[p2]]];p0=p1;p1=p2;Secti++];Style[Grid[{Prepend[vectNiter,"n"],Prepend[vecPreIm//N,"(Subscript[p, n])"],Prepend[vecIm//N,"|f((Subscript[p, n]))|"]},Frame-> All,Alignment->Left],11]],Style["Se indefine, f((Subscript[p, 0]))-f((Subscript[p, 1]))=0",11]],Style["Error en los datos iniciales",11]]],Style["NaD",11]]],10];SecanteToleranciaF[vp0_,vp1_,tolerancia_]:=TimeConstrained[Quiet[If[tolerancia>0,Module[{p0=vp0,p1=vp1},If[TrueQ[NumericQ[g[p0]]&&NumericQ[g[p1]]],If[(g[p0]-g[p1])!=0,Module[{vectNiter={0,1},vecPreIm={p0,p1},vecIm={Abs[g[p0]],Abs[g[p1]]},Secti=2,p2},While[Last[vecIm]>tolerancia,vectNiter=Append[vectNiter,Secti];p2=p1-((g[p1](p0-p1))/(g[p0]-g[p1]));vecPreIm=Append[vecPreIm,p2];vecIm=Append[vecIm,Abs[g[p2]]];p0=p1;p1=p2;Secti++];Style[Grid[{Prepend[vectNiter,"n"],Prepend[vecPreIm//N,"(Subscript[p, n])"],Prepend[vecIm//N,"|f((Subscript[p, n]))|"]},Frame-> All,Alignment->Left],11]],Style["Se indefine, f((Subscript[p, 0]))-f((Subscript[p, 1]))=0",11]],Style["Error en los datos iniciales",11]]],Style["NaD",11]]],10])]],"Text"]]