(*******************************  lydia  *)

Needs["Splines`"]

lydia[1]={{0.243,42.4752},{1.214,42.9607},{2.184,43.2034},{3.155,44.4170},{4.126,47.3295},{5.097,50.2421},{6.068,54.6110},{7.039,57.2809},{8.010,58.9799},{8.980,60.4362},{9.951,63.1061},{10.922,63.8342},{11.893,65.5332},{12.864,67.2322},{13.835,68.4458},{14.806,70.6302},{15.777,71.3584},{16.747,72.8147},{17.718,74.2710},{18.689,75.7273},{19.660,76.6981},{20.631,76.4554},{21.602,76.9408},{22.573,77.9117},{23.543,78.3971},{24.514,78.6398},{25.485,78.8826},{26.456,78.8826},{27.427,78.8826},{28.398,78.8826},{29.369,78.8826},{30.339,78.8826},{31.310,78.1544},{32.281,77.6690},{33.252,78.3971},{34.223,78.3971},{35.194,78.1544},{36.165,77.9117},{37.135,77.9117},{38.106,77.4263},{39.077,76.9408},{40.048,76.9408},{41.019,76.4554},{41.990,76.4554},{42.961,76.4554},{43.932,75.9700},{44.902,75.2418},{45.873,73.7855},{46.844,72.8147},{47.815,71.3584},{48.786,68.2031},{49.757,65.7759},{50.728,64.3196},{51.698,62.6206},{52.669,61.1643},{53.640,58.7372},{54.611,57.0382},{55.582,54.1256},{56.553,49.2713},{56.553,51.2130},{57.524,49.0285},{58.494,48.0577},{59.465,47.0868},{60.436,46.3587},{61.407,45.8732},{62.378,46.3587},{63.349,46.1160},{64.320,46.3587},{65.290,46.1160},{66.261,45.6305},{67.232,45.1451},{68.203,44.9024},{69.174,44.1742},{70.145,43.2034},{71.116,42.2325},{72.087,41.2617},{73.057,40.2908},{74.028,40.2908},{74.028,41.7471},{74.999,42.9607},{75.970,46.1160},{76.941,47.5723},{77.912,49.7567},{78.883,51.2130},{79.853,52.6693},{80.824,54.8537},{81.795,56.5527},{82.766,58.4945},{83.737,60.4362},{84.708,62.1352},{85.679,63.3488},{86.649,64.5623},{87.620,65.5332},{88.591,66.5041},{89.562,66.9895},{90.533,67.9604},{91.504,68.9312},{92.475,69.9021},{93.446,70.8729},{94.416,71.3584},{94.416,75.2418},{95.387,72.3292},{95.387,74.5137},{95.387,76.6981},{96.358,73.3001},{96.358,75.4846},{96.358,77.9117},{97.329,74.7564},{97.329,79.1253},{98.300,80.0961},{99.271,80.3389},{100.242,81.3097},{101.212,82.0379},{102.183,82.5233},{103.154,83.0087},{104.125,83.2514},{105.096,81.0670},{106.067,81.3097},{107.038,81.7952},{108.008,82.2806},{108.979,82.2806},{109.950,82.7660},{110.921,83.2514},{111.892,82.7660},{112.863,82.7660},{113.834,82.2806},{114.804,82.2806},{115.775,82.2806},{116.746,82.0379},{117.717,81.7952},{118.688,81.3097},{119.659,80.5816},{120.630,80.3389},{121.601,80.3389},{122.571,79.6107},{123.542,78.6398},{124.513,77.9117},{125.484,76.4554},{126.455,72.8147},{127.426,67.7177},{128.397,65.7759},{129.367,64.0769},{130.338,62.1352},{131.309,59.9507},{132.280,54.1256},{132.280,56.5527},{133.251,51.4557},{134.222,47.5723},{135.193,43.6888},{135.193,45.6305},{136.163,38.1063},{136.163,40.7762},{137.134,30.0967},{137.134,34.4656},{138.105,25.7279},{138.105,27.1841},{138.105,28.8832},{139.076,24.9997},{140.047,24.9997},{141.018,24.9997},{141.989,24.5143},{142.959,24.2716},{143.930,24.0288},{144.901,23.7861},{145.872,23.3007},{146.843,23.0580},{147.814,22.8153}}
lydia[2]={{0.243,9.9513},{1.214,9.9513},{2.184,9.9513},{3.155,10.4368},{4.126,10.9222},{5.097,10.4368},{6.068,10.6795},{7.039,10.9222},{8.010,10.9222},{8.980,10.9222},{9.951,10.9222},{10.922,11.4076},{11.893,11.4076},{11.893,13.5921},{12.864,12.1358},{12.864,15.0484},{12.864,18.9318},{13.835,24.7570},{14.806,31.3103},{15.777,36.4073},{16.747,39.3199},{17.718,45.3878},{18.689,48.7858},{19.660,50.7276},{20.631,52.1838},{21.602,53.3974},{22.573,54.1256},{23.543,54.3683},{24.514,55.3392},{25.485,56.0673},{26.456,56.0673},{27.427,56.0673},{28.398,56.3100},{29.369,56.7954},{30.339,57.0382},{31.310,57.0382},{32.281,57.0382},{33.252,57.0382},{34.223,57.5236},{35.194,57.2809},{36.165,57.0382},{37.135,57.0382},{38.106,56.7954},{39.077,56.7954},{40.048,57.0382},{41.019,56.5527},{41.990,56.0673},{42.961,55.8246},{43.932,54.8537},{44.902,54.3683},{45.873,53.3974},{46.844,51.2130},{47.815,49.9994},{48.786,43.2034},{48.786,48.3004},{49.757,37.3782},{49.757,40.7762},{50.728,34.4656},{50.728,39.8054},{51.698,32.5239},{52.669,31.0676},{53.640,26.6987},{54.611,24.0288},{55.582,21.3590},{56.553,11.8931},{56.553,18.2037},{57.524,11.4076},{57.524,14.8057},{58.494,11.6503},{59.465,12.6212},{60.436,12.8639},{61.407,14.5629},{62.378,15.5338},{63.349,16.5047},{64.320,17.4755},{65.290,19.1745},{66.261,22.0871},{67.232,24.5143},{68.203,27.9123},{69.174,31.3103},{70.145,33.9802},{71.116,35.9219},{72.087,37.8636},{73.057,40.0481},{74.028,41.9898},{74.999,44.1742},{75.970,45.6305},{76.941,46.8441},{77.912,48.7858},{78.883,50.2421},{79.853,51.4557},{80.824,54.1256},{81.795,55.8246},{82.766,57.0382},{83.737,58.2517},{84.708,58.7372},{85.679,59.7080},{86.649,60.6789},{87.620,61.4070},{88.591,61.8925},{89.562,61.8925},{90.533,62.1352},{91.504,62.3779},{92.475,62.3779},{93.446,62.3779},{94.416,62.3779},{95.387,62.3779},{96.358,62.3779},{97.329,62.3779},{98.300,62.3779},{99.271,61.8925},{100.242,61.8925},{101.212,61.6498},{102.183,61.4070},{103.154,61.4070},{104.125,61.4070},{105.096,60.6789},{106.067,60.1935},{107.038,58.7372},{108.008,57.2809},{108.979,55.8246},{109.950,52.6693},{110.921,49.2713},{111.892,48.7858},{112.863,48.0577},{113.834,47.8150},{114.804,47.3295},{115.775,46.3587},{116.746,42.4752},{117.717,38.1063},{117.717,39.8054},{118.688,36.1646},{119.659,34.2229},{120.630,30.8249},{121.601,25.4851},{122.571,17.4755},{122.571,21.8444},{123.542,16.2619},{124.513,16.7474},{125.484,17.9610},{126.455,19.6600},{127.426,21.1163},{128.397,22.8153}}
lydia[3]={{0.243,0.7281},{0.243,12.1358},{1.214,11.4076},{2.184,11.4076},{3.155,11.6503},{4.126,12.1358},{5.097,13.1066},{6.068,15.7765},{7.039,17.4755},{8.010,19.4172},{8.980,21.1163},{9.951,23.7861},{10.922,25.7279},{11.893,27.4269},{12.864,29.1259},{13.835,31.3103},{14.806,33.7375},{15.777,36.8928},{16.747,38.8345},{17.718,40.2908},{18.689,41.2617},{19.660,41.7471},{20.631,42.7179},{21.602,43.2034},{22.573,43.6888},{23.543,44.1742},{24.514,44.4170},{25.485,44.9024},{26.456,45.8732},{27.427,45.8732},{28.398,45.8732},{29.369,45.8732},{30.339,45.8732},{31.310,45.8732},{32.281,45.8732},{33.252,45.3878},{34.223,45.1451},{35.194,44.9024},{36.165,44.6597},{37.135,44.1742},{38.106,43.9315},{39.077,43.6888},{40.048,43.2034},{41.019,41.7471},{41.990,40.7762},{42.961,38.8345},{43.932,38.5918},{44.902,37.6209},{45.873,36.4073},{46.844,36.1646},{47.815,35.6792},{48.786,34.4656},{49.757,33.4948},{50.728,33.0093},{51.698,32.0385},{52.669,30.5822},{53.640,29.6113},{54.611,28.1550},{55.582,27.1841},{56.553,25.7279},{57.524,24.7570},{58.494,23.0580},{59.465,22.3298},{60.436,21.3590},{61.407,20.6308},{62.378,18.2037},{63.349,16.9901},{64.320,16.0192},{65.290,15.2911},{66.261,14.5629},{67.232,14.0775},{68.203,13.5921},{69.174,13.3494},{70.145,14.3202},{71.116,15.7765},{72.087,16.2619},{73.057,16.5047},{74.028,17.4755},{74.999,17.9610},{75.970,18.4464},{76.941,19.1745},{77.912,19.6600},{78.883,21.1163},{79.853,21.6017},{80.824,22.3298},{81.795,23.0580},{82.766,23.3007},{83.737,23.5434},{84.708,23.5434},{85.679,23.7861},{86.649,24.0288},{87.620,24.2716},{88.591,24.7570},{89.562,24.9997},{90.533,25.2424},{91.504,25.4851},{92.475,25.7279},{93.446,25.9706},{94.416,26.4560},{95.387,26.4560},{96.358,26.9414},{97.329,27.1841},{98.300,27.4269},{99.271,26.4560},{100.242,26.4560},{101.212,27.6696},{102.183,28.8832},{103.154,29.6113},{104.125,31.3103},{105.096,32.5239},{106.067,32.7666},{107.038,32.7666},{108.008,32.7666},{108.979,33.0093},{109.950,33.2520},{110.921,33.0093},{111.892,33.0093},{112.863,33.2520},{113.834,32.7666},{114.804,32.7666},{115.775,32.7666},{116.746,32.7666},{117.717,32.2812},{118.688,31.7957},{119.659,31.3103},{120.630,30.5822},{121.601,30.0967},{122.571,27.6696},{123.542,22.8153},{123.542,25.9706},{124.513,20.6308},{125.484,17.9610},{126.455,16.2619},{127.426,12.3785},{128.397,8.4950},{129.367,6.0679},{130.338,3.8834},{131.309,1.9417},{132.280,1.6990},{133.251,2.1844},{134.222,2.6699},{135.193,3.1553}}

(*Poner aqui la familia*)
var=lydia;
(* el número de curvas estudiadas/semillas de la familia*)
m=3;
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,3}]];
Print["Valores medios de curvatura de cada ", var ," en [0,1]:  ", Table[vmed[j],{j,1,3}]];

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