(*******************************  nocturna  *)

Needs["Splines`"]

nocturna[1]={{0.216,7.5758},{1.082,7.7922},{1.948,8.8745},{2.814,9.3074},{3.680,9.7403},{4.545,9.7403},{5.411,10.1732},{6.277,10.6061},{7.143,11.2554},{8.009,12.1212},{8.874,12.7706},{9.740,13.8528},{10.606,14.7186},{11.472,16.0173},{12.338,16.4502},{13.203,17.9654},{14.069,19.0476},{14.935,19.4805},{15.801,19.9134},{16.667,20.5628},{17.532,21.4286},{18.398,20.9957},{19.264,20.9957},{20.130,21.6450},{20.996,22.0779},{21.861,22.7273},{22.727,23.3766},{23.593,23.8095},{24.459,24.0260},{25.325,23.5931},{26.190,23.5931},{27.056,24.0260},{27.922,24.4589},{28.788,24.4589},{29.654,24.4589},{30.519,24.4589},{31.385,24.8918},{32.251,25.1082},{33.117,25.3247},{33.983,25.3247},{34.848,25.3247},{35.714,25.3247},{36.580,24.8918},{37.446,24.8918},{38.312,24.8918},{39.177,24.8918},{40.043,25.1082},{40.909,25.7576},{41.775,25.7576},{42.641,25.5411},{43.506,24.0260},{44.372,24.0260},{45.238,24.0260},{46.104,23.5931},{46.970,23.5931},{47.835,23.3766},{48.701,23.1602},{49.567,22.5108},{50.433,21.8615},{51.299,21.4286},{52.165,20.9957},{53.030,20.9957},{53.896,20.9957},{54.762,20.5628},{55.628,20.1299},{56.494,20.1299},{57.359,20.1299},{58.225,21.2121},{59.091,21.8615},{59.957,21.8615},{60.823,21.6450},{61.688,20.9957},{62.554,21.6450},{63.420,22.5108},{64.286,22.7273},{65.152,22.7273},{66.017,23.1602},{66.883,23.5931},{67.749,24.0260},{68.615,24.0260},{69.481,24.4589},{70.346,24.8918},{71.212,25.3247},{72.078,25.3247},{72.944,25.3247},{73.810,25.7576},{74.675,25.7576},{75.541,25.7576},{76.407,25.7576},{77.273,25.7576},{78.139,25.7576},{79.004,25.7576},{79.870,25.9740},{80.736,26.1905},{81.602,26.4069},{82.468,25.9740},{83.333,25.7576},{84.199,25.3247},{85.065,25.3247},{85.931,24.6753},{86.797,24.2424},{87.662,23.5931},{88.528,23.1602},{89.394,22.7273},{90.260,22.5108},{91.126,21.6450},{91.991,21.2121},{92.857,20.3463},{93.723,19.9134},{94.589,19.4805},{95.455,18.8312},{96.320,18.3983},{97.186,18.3983},{98.052,17.3160},{98.918,16.4502},{99.784,15.8009},{100.649,14.7186},{101.515,12.9870},{102.381,12.1212},{103.247,11.2554},{104.113,10.8225},{104.978,12.1212},{105.844,12.3377},{106.710,12.3377}}
nocturna[2]={{0.216,17.0996},{1.082,16.6667},{1.948,16.0173},{2.814,14.9351},{3.680,13.8528},{4.545,13.2035},{5.411,13.2035},{6.277,12.9870},{7.143,12.7706},{8.009,12.7706},{8.874,12.7706},{9.740,12.9870},{10.606,13.2035},{11.472,13.6364},{12.338,14.2857},{13.203,15.1515},{14.069,15.8009},{14.935,16.4502},{15.801,17.3160},{16.667,18.1818},{17.532,18.8312},{18.398,19.2641},{19.264,19.6970},{20.130,19.9134},{20.996,20.5628},{21.861,20.9957},{22.727,21.2121},{23.593,21.4286},{24.459,22.0779},{25.325,22.7273},{26.190,23.3766},{27.056,24.2424},{27.922,24.4589},{28.788,24.8918},{29.654,24.6753},{30.519,24.6753},{31.385,24.8918},{32.251,25.3247},{33.117,25.5411},{33.983,25.7576},{34.848,25.7576},{35.714,25.3247},{36.580,24.8918},{37.446,25.3247},{38.312,25.3247},{39.177,25.3247},{40.043,24.6753},{40.909,23.8095},{41.775,23.3766},{42.641,23.1602},{43.506,22.9437},{44.372,21.8615},{45.238,20.9957},{46.104,20.5628},{46.970,20.3463},{47.835,19.2641},{48.701,19.4805},{49.567,20.1299},{50.433,17.9654},{51.299,16.6667},{52.165,16.0173},{53.030,15.1515},{53.896,14.0693},{54.762,14.7186},{55.628,15.1515},{56.494,15.1515},{57.359,15.1515},{58.225,16.2338},{59.091,16.6667},{59.957,16.8831},{60.823,18.1818},{61.688,19.0476},{62.554,20.5628},{63.420,21.2121},{64.286,22.2944},{65.152,22.2944},{66.017,22.9437},{66.883,23.5931},{67.749,24.0260},{68.615,24.0260},{69.481,24.4589},{70.346,25.3247},{71.212,25.9740},{72.078,26.1905},{72.944,26.4069},{73.810,27.4892},{74.675,28.1385},{75.541,29.6537},{76.407,30.5195},{77.273,30.5195},{78.139,30.5195},{79.004,30.5195},{79.870,30.5195},{80.736,30.5195},{81.602,30.5195},{82.468,30.0866},{83.333,30.0866},{84.199,29.6537},{85.065,29.0043},{85.931,28.1385},{86.797,27.2727},{87.662,26.4069},{88.528,25.3247},{89.394,24.8918},{90.260,25.1082},{91.126,25.1082},{91.991,23.3766},{92.857,22.2944},{93.723,22.2944},{94.589,22.0779},{95.455,21.8615},{96.320,21.4286},{97.186,21.4286},{98.052,21.4286},{98.918,21.4286},{99.784,21.4286},{100.649,21.4286},{101.515,21.4286},{102.381,21.4286},{103.247,21.4286},{104.113,21.4286},{104.978,20.9957},{105.844,20.7792},{106.710,20.3463},{107.576,19.4805},{108.442,19.2641},{109.307,19.2641},{110.173,19.2641},{111.039,19.0476},{111.905,18.6147},{112.771,18.3983},{113.636,17.3160},{114.502,16.4502},{115.368,16.0173},{116.234,14.9351},{117.100,13.6364},{117.965,12.3377},{118.831,11.6883},{119.697,11.0390},{120.563,10.6061},{121.429,10.8225},{122.294,11.4719},{123.160,11.6883},{124.026,11.9048},{124.892,11.9048}}
nocturna[3]={{0.2165,11.9048},{1.0823,12.1212},{1.9481,12.9870},{2.8139,13.2035},{3.6797,13.4199},{4.5455,14.2857},{5.4113,16.0173},{6.2771,16.6667},{7.1429,16.6667},{8.0087,16.6667},{8.8745,16.6667},{9.7403,17.3160},{10.6061,18.1818},{11.4719,19.4805},{12.3377,19.6970},{13.2035,19.6970},{14.0693,19.9134},{14.9351,20.7792},{15.8009,20.9957},{16.6667,21.2121},{17.5325,21.8615},{18.3983,22.7273},{19.2641,23.5931},{20.1299,26.4069},{20.9957,29.6537},{21.8615,31.1688},{22.7273,31.6017},{23.5931,31.8182},{24.4589,31.8182},{25.3247,31.8182},{26.1905,31.6017},{27.0563,31.3853},{27.9221,30.7359},{28.7879,29.4372},{29.6537,28.3550},{30.5195,26.4069},{31.3853,24.6753},{32.2511,23.8095},{33.1169,21.8615},{33.9827,20.7792},{34.8485,20.1299},{35.7143,19.4805},{36.5801,19.0476},{37.4459,18.1818},{38.3117,18.3983},{39.1775,17.9654},{40.0433,18.1818},{40.9091,18.1818},{41.7749,17.9654},{42.6407,17.5325},{43.5065,17.5325},{44.3723,17.5325},{45.2381,17.5325},{46.1039,17.3160},{46.9697,16.6667},{47.8355,16.4502},{48.7013,15.8009},{49.5671,15.3680},{50.4329,15.3680},{51.2987,14.9351},{52.1645,14.9351},{53.0303,15.3680},{53.8961,16.0173},{54.7619,16.6667},{55.6277,17.0996},{56.4935,16.8831},{57.3593,17.7489},{58.2251,18.3983},{59.0909,18.6147},{59.9567,18.8312},{60.8225,18.8312},{61.6883,19.0476},{62.5541,18.8312},{63.4199,18.8312},{64.2857,18.8312},{65.1515,18.8312},{66.0173,19.0476},{66.8831,19.2641},{67.7489,19.2641},{68.6147,19.2641},{69.4805,19.2641},{70.3463,19.2641},{71.2121,19.2641},{72.0779,18.8312},{72.9437,18.1818},{73.8095,18.6147},{74.6753,18.6147},{75.5411,19.2641},{76.4069,19.2641},{77.2727,19.4805},{78.1385,19.2641},{79.0043,19.2641},{79.8701,19.2641},{80.7359,19.6970},{81.6017,19.2641},{82.4675,19.2641},{83.3333,19.0476},{84.1991,18.8312},{85.0649,18.1818},{85.9307,17.9654},{86.7965,17.7489},{87.6623,17.5325},{88.5281,17.3160},{89.3939,16.4502},{90.2597,15.3680},{91.1255,15.3680},{91.9913,15.3680},{92.8571,15.1515},{93.7229,15.3680},{94.5887,15.3680},{95.4545,15.5844},{96.3203,15.8009}}
nocturna[4]={{0.2165,11.4719},{1.0823,11.0390},{1.9481,10.3896},{2.8139,10.1732},{3.6797,10.1732},{4.5455,10.1732},{5.4113,10.3896},{6.2771,11.6883},{7.1429,11.9048},{8.0087,11.9048},{8.8745,11.9048},{9.7403,12.9870},{10.6061,13.8528},{11.4719,14.5022},{12.3377,15.1515},{13.2035,15.8009},{14.0693,16.2338},{14.9351,17.3160},{15.8009,17.9654},{16.6667,18.3983},{17.5325,18.6147},{18.3983,18.8312},{19.2641,19.0476},{20.1299,20.3463},{20.9957,20.5628},{21.8615,20.9957},{22.7273,20.9957},{23.5931,20.9957},{24.4589,20.9957},{25.3247,21.2121},{26.1905,21.4286},{27.0563,20.9957},{27.9221,21.2121},{28.7879,21.2121},{29.6537,21.4286},{30.5195,21.2121},{31.3853,20.9957},{32.2511,21.2121},{33.1169,21.2121},{33.9827,20.7792},{34.8485,20.1299},{35.7143,19.6970},{36.5801,19.6970},{37.4459,19.4805},{38.3117,18.8312},{39.1775,18.8312},{40.0433,17.9654},{40.9091,17.5325},{41.7749,16.4502},{42.6407,16.0173},{43.5065,15.1515},{44.3723,14.9351},{45.2381,14.2857},{46.1039,14.0693},{46.9697,14.0693},{47.8355,14.0693},{48.7013,14.0693},{49.5671,14.2857},{50.4329,14.5022},{51.2987,14.5022},{52.1645,14.5022},{53.0303,14.7186},{53.8961,14.9351},{54.7619,15.5844},{55.6277,16.0173},{56.4935,17.3160},{57.3593,17.7489},{58.2251,19.0476},{59.0909,18.8312},{59.9567,19.4805},{60.8225,19.9134},{61.6883,20.3463},{62.5541,20.9957},{63.4199,21.2121},{64.2857,21.6450},{65.1515,21.8615},{66.0173,22.0779},{66.8831,22.2944},{67.7489,22.2944},{68.6147,22.5108},{69.4805,22.9437},{70.3463,23.3766},{71.2121,23.8095},{72.0779,23.8095},{72.9437,23.3766},{73.8095,22.7273},{74.6753,22.5108},{75.5411,22.0779},{76.4069,21.8615},{77.2727,21.8615},{78.1385,21.6450},{79.0043,20.5628},{79.8701,19.4805},{80.7359,18.6147},{81.6017,17.9654},{82.4675,17.9654},{83.3333,17.3160},{84.1991,16.0173},{85.0649,14.9351},{85.9307,14.0693},{86.7965,13.8528},{87.6623,13.2035},{88.5281,12.1212},{89.3939,11.9048},{90.2597,11.2554},{91.1255,10.3896},{91.9913,10.1732},{92.8571,10.1732},{93.7229,10.1732},{94.5887,10.1732},{95.4545,10.1732}}

(*Poner aqui la familia*)
var=nocturna;
(* 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