(*******************************  tenuiflora  *)

Needs["Splines`"]

tenuiflora[1]={{0.2183,7.6418},{1.0917,7.2052},{1.9650,7.2052},{2.8384,7.2052},{3.7118,7.8602},{4.5851,10.0436},{5.4585,11.7903},{6.3318,12.6636},{7.2052,14.4103},{8.0785,15.2837},{8.9519,16.3754},{9.8252,17.0304},{10.6986,17.4671},{11.5719,19.6505},{12.4453,20.9605},{13.3187,21.1788},{14.1920,22.4889},{15.0654,24.2356},{15.9387,25.9823},{16.8121,28.1657},{17.6854,30.1307},{18.5588,31.0041},{19.4321,31.4407},{20.3055,31.6591},{21.1788,31.6591},{22.0522,31.6591},{22.9255,31.6591},{23.7989,31.4407},{24.6723,29.9124},{25.5456,26.6373},{26.4190,25.3273},{27.2923,24.8906},{28.1657,24.6723},{29.0390,24.0172},{29.9124,23.3622},{30.7857,22.9255},{31.6591,22.7072},{32.5324,21.8339},{33.4058,21.3972},{34.2791,20.9605},{35.1525,20.0871},{36.0259,19.2138},{36.8992,18.3404},{37.7726,17.2487},{38.6459,16.1571},{39.5193,15.7204},{40.3926,15.5020},{41.2660,15.2837},{42.1393,15.2837},{43.0127,17.0304},{43.8860,17.4671},{44.7594,18.1221},{45.6328,18.7771},{46.5061,19.6505},{47.3795,20.3055},{48.2528,21.1788},{49.1262,21.1788},{49.9995,21.8339},{50.8729,22.2705},{51.7462,22.4889},{52.6196,22.7072},{53.4929,22.7072},{54.3663,23.1439},{55.2396,23.5806},{56.1130,23.3622},{56.9864,23.3622},{57.8597,22.9255},{58.7331,23.1439},{59.6064,23.3622},{60.4798,23.3622},{61.3531,22.9255},{62.2265,22.9255},{63.0998,22.4889},{63.9732,22.4889},{64.8465,22.4889},{65.7199,22.0522},{66.5933,22.0522},{67.4666,21.6155},{68.3400,21.6155},{69.2133,20.9605},{70.0867,20.3055},{70.9600,19.2138},{71.8334,18.7771},{72.7067,18.5588},{73.5801,18.5588},{74.4534,18.3404},{75.3268,17.9038},{76.2001,18.1221},{77.0735,18.7771},{77.9469,19.6505},{78.8202,20.0871}}
tenuiflora[2]={{0.2183,9.1702},{1.0917,8.7335},{1.9650,8.5152},{2.8384,8.5152},{3.7118,8.2969},{4.5851,7.8602},{5.4585,8.0785},{6.3318,8.7335},{7.2052,9.6069},{8.0785,10.0436},{8.9519,10.6986},{9.8252,11.3536},{10.6986,11.5719},{11.5719,11.5719},{12.4453,12.2270},{13.3187,12.4453},{14.1920,12.4453},{15.0654,12.4453},{15.9387,12.6636},{16.8121,12.8820},{17.6854,13.1003},{18.5588,13.3187},{19.4321,13.5370},{20.3055,13.7553},{21.1788,13.9737},{22.0522,14.4103},{22.9255,14.6287},{23.7989,14.8470},{24.6723,16.3754},{25.5456,17.2487},{26.4190,17.6854},{27.2923,18.1221},{28.1657,18.5588},{29.0390,18.9955},{29.9124,18.7771},{30.7857,17.9038},{31.6591,16.8121},{32.5324,14.6287},{33.4058,13.7553},{34.2791,13.3187},{35.1525,12.6636},{36.0259,12.4453},{36.8992,12.2270},{37.7726,11.7903},{38.6459,11.3536},{39.5193,10.0436},{40.3926,8.7335},{41.2660,8.5152},{42.1393,8.9519},{43.0127,9.6069},{43.8860,10.4802},{44.7594,10.9169},{45.6328,11.7903},{46.5061,12.6636},{47.3795,13.3187},{48.2528,13.7553},{49.1262,14.1920},{49.9995,14.1920},{50.8729,14.1920},{51.7462,14.4103},{52.6196,14.6287},{53.4929,15.2837},{54.3663,15.7204},{55.2396,16.3754},{56.1130,17.0304},{56.9864,17.9038},{57.8597,18.7771},{58.7331,19.6505},{59.6064,20.3055},{60.4798,20.9605},{61.3531,21.6155},{62.2265,22.0522},{63.0998,22.4889},{63.9732,22.4889},{64.8465,22.4889},{65.7199,22.4889},{66.5933,22.4889},{67.4666,22.4889},{68.3400,22.2705},{69.2133,21.8339},{70.0867,21.3972},{70.9600,18.1221},{71.8334,16.1571},{72.7067,15.7204},{73.5801,14.8470},{74.4534,14.1920},{75.3268,13.1003},{76.2001,12.2270},{77.0735,11.5719},{77.9469,10.9169},{78.8202,9.3886},{79.6936,8.9519},{80.5669,9.3886},{81.4403,9.8252},{82.3136,9.8252},{83.1870,10.4802},{84.0603,10.6986},{84.9337,10.2619}}
tenuiflora[3]={{0.2183,5.4585},{1.0917,5.0218},{1.9650,5.0218},{2.8384,6.9868},{3.7118,8.0785},{4.5851,9.1702},{5.4585,10.6986},{6.3318,11.7903},{7.2052,12.6636},{8.0785,13.9737},{8.9519,15.7204},{9.8252,16.3754},{10.6986,17.0304},{11.5719,18.1221},{12.4453,20.3055},{13.3187,21.8339},{14.1920,22.2705},{15.0654,22.9255},{15.9387,23.3622},{16.8121,23.3622},{17.6854,23.3622},{18.5588,23.3622},{19.4321,23.3622},{20.3055,22.9255},{21.1788,22.2705},{22.0522,21.3972},{22.9255,20.9605},{23.7989,20.7422},{24.6723,20.0871},{25.5456,19.2138},{26.4190,18.7771},{27.2923,17.9038},{28.1657,17.2487},{29.0390,16.5937},{29.9124,16.1571},{30.7857,15.2837},{31.6591,14.4103},{32.5324,13.5370},{33.4058,12.4453},{34.2791,11.3536},{35.1525,11.1353},{36.0259,12.0086},{36.8992,12.6636},{37.7726,13.1003},{38.6459,14.4103},{39.5193,15.2837},{40.3926,16.1571},{41.2660,17.0304},{42.1393,17.6854},{43.0127,18.7771},{43.8860,19.8688},{44.7594,21.3972},{45.6328,22.4889},{46.5061,23.3622},{47.3795,24.4539},{48.2528,26.2006},{49.1262,27.0740},{49.9995,27.9473},{50.8729,28.1657},{51.7462,28.1657},{52.6196,28.3840},{53.4929,27.9473},{54.3663,27.7290},{55.2396,27.0740},{56.1130,26.2006},{56.9864,25.7639},{57.8597,24.8906},{58.7331,24.2356},{59.6064,23.5806},{60.4798,23.1439},{61.3531,22.7072},{62.2265,22.2705},{63.0998,21.3972},{63.9732,20.7422},{64.8465,19.8688},{65.7199,18.7771},{66.5933,17.6854},{67.4666,15.7204},{68.3400,15.5020},{69.2133,14.8470},{70.0867,14.8470},{70.9600,15.9387},{71.8334,16.1571},{72.7067,16.3754},{73.5801,16.3754},{74.4534,16.8121},{75.3268,17.6854}}
tenuiflora[4]={{0.2183,12.2270},{1.0917,10.9169},{1.9650,10.0436},{2.8384,8.2969},{3.7118,7.2052},{4.5851,6.9868},{5.4585,6.3318},{6.3318,7.2052},{7.2052,7.6418},{8.0785,8.0785},{8.9519,8.0785},{9.8252,8.2969},{10.6986,8.7335},{11.5719,10.0436},{12.4453,10.6986},{13.3187,11.7903},{14.1920,12.2270},{15.0654,13.1003},{15.9387,13.7553},{16.8121,14.6287},{17.6854,15.2837},{18.5588,15.9387},{19.4321,16.1571},{20.3055,17.0304},{21.1788,17.6854},{22.0522,18.5588},{22.9255,19.4321},{23.7989,19.8688},{24.6723,20.7422},{25.5456,22.0522},{26.4190,22.7072},{27.2923,22.4889},{28.1657,22.4889},{29.0390,22.4889},{29.9124,22.0522},{30.7857,20.7422},{31.6591,18.9955},{32.5324,17.9038},{33.4058,17.0304},{34.2791,16.3754},{35.1525,15.7204},{36.0259,15.0654},{36.8992,14.4103},{37.7726,13.5370},{38.6459,12.8820},{39.5193,11.7903},{40.3926,11.3536},{41.2660,10.4802},{42.1393,9.6069},{43.0127,7.8602},{43.8860,5.8951},{44.7594,6.3318},{45.6328,6.9868},{46.5061,8.2969},{47.3795,9.1702},{48.2528,10.0436},{49.1262,10.9169},{49.9995,12.2270},{50.8729,13.1003},{51.7462,13.7553},{52.6196,14.8470},{53.4929,15.2837},{54.3663,15.7204},{55.2396,16.1571},{56.1130,16.5937},{56.9864,17.0304},{57.8597,17.4671},{58.7331,18.1221},{59.6064,19.2138},{60.4798,20.0871},{61.3531,20.7422},{62.2265,21.1788},{63.0998,21.8339},{63.9732,22.0522},{64.8465,21.8339},{65.7199,21.3972},{66.5933,20.9605},{67.4666,19.6505},{68.3400,17.2487},{69.2133,16.3754},{70.0867,15.7204},{70.9600,14.8470},{71.8334,14.4103},{72.7067,13.3187},{73.5801,12.2270},{74.4534,10.9169},{75.3268,10.0436},{76.2001,9.1702},{77.0735,8.9519},{77.9469,9.1702}}

(*Poner aqui la familia*)
var=tenuiflora;
(* el número de curvas estudiadas/semillas de la familia*)
m=4;
For[j=1,j≤m,j++,
puntos=var[j];
(* pru es el spline cubico
d es el vector que contiene la información de pru 
n es el número de trozos del spline, es decir, el número de puntos menos 1
*)
pru=SplineFit[puntos,Cubic];
d=InputForm[pru];
n=IntegerPart[d[[1,2,2]]];
spli=ParametricPlot[pru[t],{t,0,n},PlotRange->All, DisplayFunction->Identity];
(* Con los coeficientes se calculan los polinomios cúbicos que dan el spline. Habrá n polinomios para la primera coordenada (X) y otros tantos para la segunda
*)
For[i=0,i<n,i++,
SX[i,t_]=d[[1,4,i+1,1,1]]+d[[1,4,i+1,1,2]]*(t-i)+d[[1,4,i+1,1,3]]*(t-i)^2+d[[1,4,i+1,1,4]]*(t-i)^3];
For[i=0,i<n,i++,SY[i,t_]=d[[1,4,i+1,2,1]]+d[[1,4,i+1,2,2]]*(t-i)+d[[1,4,i+1,2,3]]*(t-i)^2+d[[1,4,i+1,2,4]]*(t-i)^3];
(* Derivada primera y segunda de cada trozo del spline
*)
For[i=0,i<n,i++,DX[i,t_]=d[[1,4,i+1,1,2]]+2*d[[1,4,i+1,1,3]]*(t-i)+3*d[[1,4,i+1,1,4]]*(t-i)^2];
For[i=0,i<n,i++,DY[i,t_]=d[[1,4,i+1,2,2]]+2*d[[1,4,i+1,2,3]]*(t-i)+3*d[[1,4,i+1,2,4]]*(t-i)^2];
For[i=0,i<n,i++,DDX[i,t_]=2*d[[1,4,i+1,1,3]]+6*d[[1,4,i+1,1,4]]*(t-i)];
For[i=0,i<n,i++,DDY[i,t_]=2*d[[1,4,i+1,2,3]]+6*d[[1,4,i+1,2,4]]*(t-i)];
(*Cálculo de la curvatura a trozos
*)
For[i=0,i<n,i++,cur[i,t_]=(DX[i,t]DDY[i,t]-DDX[i,t]DY[i,t])/((DX[i,t])^2+(DY[i,t])^2)^(3/2)];
(* Dibujos de los trozos de curvatura 
*)
For[i=0,i<n,i++,dib[i]=Plot[cur[i,t],{t,i,i+1},DisplayFunction->Identity]];
pp=dib[0];
For[i=1,i<n,i++,pp=Show[pp,dib[i],PlotRange->All]];
(* bez es el spline de Bezier
b es el vector que contiene la información de bez
nb es el número de trozos del spline, es decir, el número de puntos menos 1 (Como nb=n, no se define nuevo)
*)
bez=SplineFit[puntos,Bezier];
b=InputForm[bez];
(*Calculo de las funciones de Bezier para la coordenada X y la Y; la curva es la imagen del intervalo[0,1]*)
For[i=1,i≤n+1,i++,BX[t_]=bez[[4,1,1]]/.#1->t];
For[i=1,i≤n+1,i++,BY[t_]=bez[[4,1,2]]/.#1->t];
dibez[j]=ParametricPlot[{BX[t],BY[t]},{t,0,1},PlotRange->All,DisplayFunction->Identity];
curbe[j,t_]=1000*(BX'[t]BY''[t]-BX''[t]BY'[t])/((BX'[t])^2+(BY'[t])^2)^(3/2);
aa=0.1;
bb=0.9;
cur[j]=Abs[NMinValue[{curbe[j,t],aa<t<bb},t]];
vmed[j]=Abs[NIntegrate[curbe[j,t],{t,aa,bb}]];
vals[j]=Reap[soln=y[x]/. First[NDSolve[{y'[x]==Evaluate[D[curbe[j,x],x]],y[0]==(curbe[j,x]/. x->0)},y[x],{x,aa,bb},Method->{"EventLocator","Event"->y'[x],"EventAction":>Sow[{x,y[x]}]}]]][[2,1]];
Print[ var,"-",j,":"];Print["Máximos y mínimos locales "];
Print[vals[j]];
z=vals[j];
max[j]=Max[Table[z[[k,2]],{k,1,Length[z]}]];
min[j]=Min[Table[z[[k,2]],{k,1,Length[z]}]];dibcurbe[j]=Plot[curbe[j,x],{x,0,1},Epilog->{PointSize[Medium],Red,Point[z]}];
Print[dibez[j]];
Print[dibcurbe[j]];
Print[Plot[{curbe[j,t],vmed[j]},{t,0,1},Axes->True,DisplayFunction->Identity,PlotStyle->{RGBColor[0,1,0],{Dotted,Dashed}}]];
Print[ "Máximo valor de la curvatura",max[j]];
Print[ "Mínimo valor de la curvatura",min[j]];Print[ "Máximo valor de la curvatura (en valor absoluto)con otro cálculo",cur[j]];
Print["______________________________________________________"];];
Print["Curvaturas de cada ", var ,":  ", Table[cur[r],{r,1,4}]];
Print["Valores medios de curvatura de cada ", var ," en [0,1]:  ", Table[vmed[j],{j,1,4}]];

Show[Table[dibcurbe[j],{j,1,6}]]

Table[NMinValue[{curbe[j,t],0.25<t<0.75},t],{j,1,6}]

dibcurbe[j],{j,1,6}

Table[dibcurbe[j],{j,1,6}]

curbe[j,t_]
dibcurbe[j]

Plot[curbe[1,x],{x,0,1},Epilog->{PointSize[Medium],Red,Point[vals[1]]}]

dibcurbe[j]=Plot[curbe[j,x],{x,0,1},Epilog->{PointSize[Medium],Red,Point[z]}]

dibcurbe2[1]

Print[dibez[1]];

f=vals[1]

Max[vals[1]]

Max[Table[f[[k,2]],{k,1,Length[f]}]]
Min[Table[f[[k,2]],{k,1,Length[f]}]]

List