(*******************************  papillosa  *)

Needs["Splines`"]

papillosa[1]={{0.240,11.9901},{1.199,11.5105},{2.158,11.0309},{3.117,10.5513},{4.077,9.8319},{5.036,9.1125},{5.995,8.8727},{6.954,8.8727},{7.913,9.3523},{8.873,10.0717},{9.832,10.7911},{10.791,11.5105},{11.750,12.9493},{12.710,13.9085},{13.669,14.8677},{14.628,16.0667},{15.587,17.2657},{16.546,18.4648},{17.506,19.9036},{18.465,21.3424},{19.424,22.3016},{20.383,23.5006},{21.342,24.4598},{22.302,25.8986},{23.261,27.3374},{24.220,28.5364},{25.179,30.2150},{26.138,31.6539},{27.098,33.0927},{28.057,34.5315},{29.016,35.9703},{29.975,36.9295},{30.934,37.8887},{31.894,39.0877},{32.853,40.0469},{33.812,40.7663},{34.771,41.0061},{35.730,41.4857},{36.690,41.4857},{37.649,41.7255},{38.608,41.9653},{39.567,41.9653},{40.527,41.9653},{41.486,41.9653},{42.445,41.9653},{43.404,41.9653},{44.363,41.9653},{45.323,41.7255},{46.282,41.2459},{47.241,40.7663},{48.200,40.0469},{49.159,39.3275},{50.119,38.3683},{51.078,37.4091},{52.037,36.4499},{52.996,35.4907},{53.955,34.5315},{54.915,33.3325},{55.874,32.1335},{56.833,30.4548},{57.792,29.2558},{58.751,28.2966},{59.711,26.8578},{60.670,25.8986},{61.629,24.6996},{62.588,23.5006},{63.548,21.8220},{64.507,20.8628},{65.466,20.1434},{66.425,18.7046},{67.384,17.5055},{68.344,16.7861},{69.303,15.5871},{70.262,14.8677},{71.221,14.1483},{72.180,13.4289},{73.140,12.7095},{74.099,12.7095},{75.058,12.9493},{76.017,13.1891},{76.976,13.9085},{77.936,15.1075},{78.895,16.3065},{79.854,16.7861},{80.813,17.7453},{81.772,18.7046},{82.732,19.6638},{83.691,20.6230},{84.650,21.5822},{85.609,22.5414},{86.569,23.0210},{87.528,23.9802},{88.487,24.9394},{89.446,25.4190},{90.405,26.8578},{91.365,27.8170},{92.324,28.5364},{93.283,29.0160},{94.242,29.7354},{95.201,30.6946},{96.161,31.1743},{97.120,32.1335},{98.079,33.0927},{99.038,33.8121},{99.997,34.5315},{100.957,35.4907},{101.916,35.9703},{102.875,36.9295},{103.834,37.8887},{104.793,38.3683},{105.753,38.8479},{106.712,39.8071},{107.671,40.5265},{108.630,41.2459},{109.589,41.7255},{110.549,41.9653},{111.508,41.9653},{112.467,42.2051},{113.426,42.4449},{114.386,42.4449},{115.345,42.2051},{116.304,41.9653},{117.263,41.9653},{118.222,41.4857},{119.182,41.2459},{120.141,40.7663},{121.100,40.2867},{122.059,39.8071},{123.018,38.8479},{123.978,38.3683},{124.937,36.9295},{125.896,35.9703},{126.855,34.7713},{127.814,33.5723},{128.774,32.6131},{129.733,31.6539},{130.692,30.4548},{131.651,29.2558},{132.610,28.2966},{133.570,27.3374},{134.529,25.8986},{135.488,24.6996},{136.447,23.2608},{137.407,21.8220},{138.366,20.6230},{139.325,19.4240},{140.284,18.2249},{141.243,17.0259},{142.203,15.3473},{143.162,14.3881},{144.121,12.9493},{145.080,11.7503},{146.039,10.3115},{146.999,9.3523},{147.958,8.6329},{148.917,7.9135},{149.876,7.6737},{150.835,7.9135},{151.795,7.9135},{152.754,8.1533},{153.713,8.6329},{154.672,8.8727}}
papillosa[2]={{0.240,24.6996},{1.199,24.2200},{2.158,24.2200},{3.117,23.7404},{4.077,23.9802},{5.036,25.1792},{5.995,26.3782},{6.954,27.5772},{7.913,28.7762},{8.873,30.2150},{9.832,31.6539},{10.791,33.0927},{11.750,34.5315},{12.710,36.2101},{13.669,37.4091},{14.628,38.8479},{15.587,40.2867},{16.546,42.4449},{17.506,43.6440},{18.465,45.0828},{19.424,46.2818},{20.383,47.0012},{21.342,47.9604},{22.302,48.6798},{23.261,49.3992},{24.220,50.1186},{25.179,50.5982},{26.138,50.8380},{27.098,51.3176},{28.057,51.7972},{29.016,52.0370},{29.975,52.0370},{30.934,52.5166},{31.894,52.5166},{32.853,52.7564},{33.812,52.5166},{34.771,52.5166},{35.730,52.5166},{36.690,52.5166},{37.649,52.5166},{38.608,52.2768},{39.567,52.0370},{40.527,51.5574},{41.486,51.0778},{42.445,50.5982},{43.404,50.1186},{44.363,49.3992},{45.323,48.9196},{46.282,48.2002},{47.241,47.4808},{48.200,46.7614},{49.159,46.0420},{50.119,45.0828},{51.078,44.1236},{52.037,43.6440},{52.996,42.6847},{53.955,41.7255},{54.915,41.0061},{55.874,40.2867},{56.833,39.3275},{57.792,38.3683},{58.751,37.8887},{59.711,36.9295},{60.670,36.2101},{61.629,35.2509},{62.588,34.0519},{63.548,33.5723},{64.507,32.6131},{65.466,31.6539},{66.425,30.9345},{67.384,30.2150},{68.344,29.0160},{69.303,27.8170},{70.262,27.0976},{71.221,26.3782},{72.180,25.8986},{73.140,24.9394},{74.099,23.9802},{75.058,23.5006},{76.017,22.5414},{76.976,22.0618},{77.936,21.1026},{78.895,20.6230},{79.854,19.6638},{80.813,18.7046},{81.772,18.2249},{82.732,17.7453},{83.691,17.2657},{84.650,17.0259},{85.609,17.0259},{86.569,17.5055},{87.528,17.9851},{88.487,18.7046},{89.446,19.1842},{90.405,20.1434},{91.365,20.8628},{92.324,21.5822},{93.283,22.5414},{94.242,23.5006},{95.201,23.9802},{96.161,24.9394},{97.120,25.8986},{98.079,26.3782},{99.038,27.3374},{99.997,28.2966},{100.957,29.0160},{101.916,29.7354},{102.875,30.6946},{103.834,31.1743},{104.793,32.1335},{105.753,32.6131},{106.712,33.5723},{107.671,34.5315},{108.630,35.2509},{109.589,35.9703},{110.549,36.4499},{111.508,36.9295},{112.467,37.6489},{113.426,38.3683},{114.386,38.6081},{115.345,39.3275},{116.304,39.8071},{117.263,40.2867},{118.222,40.5265},{119.182,40.7663},{120.141,41.2459},{121.100,41.4857},{122.059,41.4857},{123.018,41.7255},{123.978,41.9653},{124.937,41.9653},{125.896,41.9653},{126.855,41.7255},{127.814,41.4857},{128.774,41.4857},{129.733,41.0061},{130.692,41.0061},{131.651,40.5265},{132.610,40.0469},{133.570,39.3275},{134.529,38.8479},{135.488,38.3683},{136.447,37.8887},{137.407,36.9295},{138.366,35.9703},{139.325,35.0111},{140.284,34.5315},{141.243,33.3325},{142.203,31.8937},{143.162,30.9345},{144.121,29.4956},{145.080,28.0568},{146.039,26.6180},{146.999,25.4190},{147.958,24.2200},{148.917,23.0210},{149.876,22.0618},{150.835,20.1434},{151.795,18.7046},{152.754,17.7453},{153.713,16.3065},{154.672,14.3881},{155.631,12.7095},{156.591,11.0309},{157.550,10.0717},{158.509,9.1125},{159.468,9.1125},{160.428,9.3523},{161.387,10.0717},{162.346,11.0309}}
papillosa[3]={{0.240,7.1941},{1.199,7.6737},{2.158,8.8727},{3.117,10.0717},{4.077,11.5105},{5.036,12.7095},{5.995,13.9085},{6.954,14.8677},{7.913,15.8269},{8.873,16.7861},{9.832,17.7453},{10.791,18.2249},{11.750,19.4240},{12.710,20.3832},{13.669,21.1026},{14.628,22.3016},{15.587,23.5006},{16.546,23.9802},{17.506,24.9394},{18.465,25.4190},{19.424,26.3782},{20.383,27.0976},{21.342,27.8170},{22.302,28.7762},{23.261,29.2558},{24.220,29.9752},{25.179,30.6946},{26.138,31.1743},{27.098,31.6539},{28.057,32.1335},{29.016,32.3733},{29.975,32.8529},{30.934,32.8529},{31.894,32.8529},{32.853,33.3325},{33.812,33.3325},{34.771,33.3325},{35.730,33.3325},{36.690,32.8529},{37.649,32.8529},{38.608,32.6131},{39.567,32.3733},{40.527,32.1335},{41.486,31.8937},{42.445,31.4141},{43.404,31.1743},{44.363,30.6946},{45.323,30.2150},{46.282,29.4956},{47.241,29.0160},{48.200,28.2966},{49.159,27.3374},{50.119,26.8578},{51.078,25.8986},{52.037,24.9394},{52.996,24.4598},{53.955,23.5006},{54.915,23.0210},{55.874,22.0618},{56.833,21.1026},{57.792,20.1434},{58.751,19.6638},{59.711,18.4648},{60.670,17.7453},{61.629,16.7861},{62.588,16.0667},{63.548,15.3473},{64.507,14.3881},{65.466,13.6687},{66.425,12.9493},{67.384,11.9901},{68.344,10.7911},{69.303,9.5921},{70.262,8.6329},{71.221,7.6737},{72.180,7.4339},{73.140,7.4339},{74.099,7.6737},{75.058,8.1533},{76.017,8.8727},{76.976,10.0717},{77.936,11.0309},{78.895,11.9901},{79.854,12.9493},{80.813,13.9085},{81.772,14.8677},{82.732,15.3473},{83.691,16.0667},{84.650,16.7861},{85.609,17.5055},{86.569,18.2249},{87.528,18.9444},{88.487,19.6638},{89.446,20.1434},{90.405,20.8628},{91.365,21.3424},{92.324,22.0618},{93.283,22.5414},{94.242,23.0210},{95.201,23.5006},{96.161,24.2200},{97.120,24.6996},{98.079,25.1792},{99.038,25.8986},{99.997,26.3782},{100.957,26.8578},{101.916,27.3374},{102.875,27.5772},{103.834,28.0568},{104.793,28.2966},{105.753,28.5364},{106.712,28.7762},{107.671,29.0160},{108.630,29.0160},{109.589,29.2558},{110.549,29.4956},{111.508,29.2558},{112.467,29.0160},{113.426,29.0160},{114.386,29.0160},{115.345,28.7762},{116.304,28.5364},{117.263,28.2966},{118.222,28.0568},{119.182,27.5772},{120.141,26.8578},{121.100,26.3782},{122.059,25.8986},{123.018,25.1792},{123.978,24.6996},{124.937,23.9802},{125.896,23.5006},{126.855,22.5414},{127.814,21.5822},{128.774,20.6230},{129.733,19.6638},{130.692,18.4648},{131.651,17.2657},{132.610,16.3065},{133.570,14.8677},{134.529,13.9085},{135.488,13.1891},{136.447,13.1891},{137.407,12.4697},{138.366,11.5105},{139.325,10.0717},{140.284,9.5921},{141.243,8.6329},{142.203,7.6737},{143.162,7.1941},{144.121,6.2349},{145.080,5.9950},{146.039,5.9950},{146.999,6.4747}}
papillosa[4]={{0.273,9.5627},{1.366,10.1091},{2.459,10.3824},{3.552,10.9288},{4.645,11.2020},{5.738,12.0217},{6.830,13.1146},{7.923,14.4807},{9.016,16.3932},{10.109,19.9451},{11.202,21.3112},{12.295,23.2237},{13.388,24.5898},{14.481,25.9559},{15.574,28.4149},{16.666,29.5078},{17.759,30.6006},{18.852,30.8739},{19.945,31.6935},{21.038,32.5132},{22.131,33.3328},{23.224,33.8793},{24.317,34.1525},{25.409,34.6989},{26.502,34.6989},{27.595,34.6989},{28.688,34.6989},{29.781,34.1525},{30.874,33.6061},{31.967,33.0596},{33.060,32.7864},{34.152,32.2400},{35.245,30.8739},{36.338,30.6006},{37.431,29.2345},{38.524,27.3220},{39.617,25.1362},{40.710,24.0434},{41.803,21.8576},{42.896,20.7647},{43.988,19.6718},{45.081,18.5790},{46.174,17.4861},{47.267,16.9396},{48.360,15.8468},{49.453,15.0271},{50.546,14.4807},{51.639,13.9342},{52.731,13.3878},{53.824,12.5681},{54.917,12.2949},{56.010,11.7485},{57.103,11.7485},{58.196,11.2020},{59.289,10.6556},{60.382,10.9288},{61.474,11.2020},{62.567,12.0217},{63.660,12.2949},{64.753,13.6610},{65.846,14.7539},{66.939,15.5735},{68.032,18.5790},{69.125,19.6718},{70.218,21.5844},{71.310,24.0434},{72.403,24.8630},{73.496,26.2291},{74.589,27.5952},{75.682,30.0542},{76.775,30.6006},{77.868,31.1471},{78.961,31.6935},{80.053,32.5132},{81.146,32.7864},{82.239,33.0596},{83.332,33.3328},{84.425,33.6061},{85.518,33.6061},{86.611,33.0596},{87.704,33.0596},{88.796,32.2400},{89.889,31.1471},{90.982,30.6006},{92.075,29.5078},{93.168,28.4149},{94.261,27.3220},{95.354,26.5023},{96.447,25.9559},{97.540,22.9505},{98.632,20.4915},{99.725,19.3986},{100.818,18.3057},{101.911,15.8468},{103.004,13.9342},{104.097,12.5681},{105.190,12.0217},{106.283,8.7430},{107.375,6.2841},{108.468,4.9180},{109.561,4.6447},{110.654,4.0983},{111.747,4.0983},{112.840,4.3715}}

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