(*******************************  spergulifolia  *)

Needs["Splines`"]

spergulifolia[1]={{0.368,15.8079},{1.838,15.8079},{3.309,15.4402},{4.779,14.7050},{6.250,13.6021},{7.720,12.1316},{9.191,11.3964},{10.661,11.0287},{12.132,9.9259},{13.602,9.1906},{15.073,8.8230},{16.543,9.1906},{18.014,9.5582},{19.484,10.6611},{20.955,12.8669},{22.425,14.3374},{23.896,16.1755},{25.366,19.8517},{26.837,22.0575},{28.307,24.6309},{29.778,26.1014},{31.248,27.5719},{32.719,29.4100},{34.189,30.1452},{35.660,31.6157},{37.130,32.3510},{38.601,33.0862},{40.071,34.5567},{41.542,35.2920},{43.012,36.0272},{44.483,36.7625},{45.953,37.4977},{47.424,37.8653},{48.894,38.9682},{50.365,39.3358},{51.835,39.3358},{53.306,40.0711},{54.776,40.0711},{56.247,40.0711},{57.717,40.0711},{59.188,40.0711},{60.658,40.0711},{62.129,40.8063},{63.599,40.8063},{65.070,40.8063},{66.540,40.0711},{68.011,39.3358},{69.481,39.3358},{70.952,39.3358},{72.422,38.9682},{73.893,38.2330},{75.363,38.2330},{76.834,38.6006},{78.304,39.3358},{79.775,38.9682},{81.245,38.2330},{82.716,37.8653},{84.186,37.1301},{85.657,37.1301},{87.127,37.1301},{88.598,36.3948},{90.068,36.3948},{91.539,35.6596},{93.009,34.5567},{94.480,31.9833},{97.421,30.5128},{98.891,30.5128},{100.362,30.5128},{101.832,31.9833},{103.303,31.9833},{104.773,32.7186},{106.244,32.7186},{107.714,32.7186},{109.185,33.0862},{110.655,33.8215},{112.126,34.5567},{113.596,35.6596},{115.067,36.3948},{116.537,37.1301},{118.008,38.2330},{119.478,39.3358},{120.949,40.4387},{122.419,40.8063},{123.890,41.5416},{125.360,42.2768},{126.831,42.2768},{128.301,42.2768},{129.772,42.2768},{131.242,42.6445},{132.713,43.0121},{134.183,43.7473},{135.654,43.7473},{137.124,43.7473},{138.595,44.1150},{140.065,44.4826},{141.536,45.2178},{143.006,44.4826},{144.477,44.4826},{145.947,43.7473},{147.418,43.7473},{148.888,43.7473},{150.359,43.3797},{151.829,43.0121},{153.299,42.2768},{154.770,42.2768},{156.240,41.5416},{157.711,40.8063},{159.181,39.7035},{160.652,39.3358},{162.122,38.2330},{163.593,36.7625},{165.063,35.2920},{166.534,34.5567},{168.004,33.4538},{169.475,31.9833},{170.945,30.5128},{172.416,29.4100},{173.886,27.5719},{175.357,26.1014},{176.827,24.9985},{178.298,24.2632},{179.768,23.5280},{181.239,21.6899},{182.709,20.9546},{184.180,21.6899},{185.650,22.4251},{187.121,23.5280},{188.591,24.6309},{190.062,25.7337},{191.532,26.4690}}
spergulifolia[2]={{0.368,28.3071},{1.838,27.9395},{3.309,27.5719},{4.779,27.2042},{6.250,26.8366},{7.720,26.1014},{9.191,25.3661},{10.661,24.6309},{12.132,23.8956},{13.602,22.7927},{15.073,22.4251},{16.543,22.4251},{18.014,22.7927},{19.484,23.8956},{20.955,24.9985},{22.425,26.8366},{23.896,28.6747},{25.366,30.1452},{26.837,30.8805},{28.307,31.9833},{29.778,32.7186},{31.248,33.8215},{32.719,34.5567},{34.189,35.6596},{35.660,36.7625},{37.130,38.2330},{38.601,40.4387},{40.071,42.2768},{41.542,44.1150},{43.012,45.5855},{44.483,47.4236},{45.953,49.9970},{47.424,50.7322},{48.894,51.8351},{50.365,52.5703},{51.835,53.3056},{53.306,54.4085},{54.776,55.1437},{56.247,56.2466},{57.717,56.6142},{59.188,57.7171},{60.658,58.8200},{62.129,59.5552},{63.599,60.2905},{65.070,61.3933},{66.540,61.7609},{68.011,62.1286},{69.481,62.1286},{70.952,62.4962},{72.422,63.2314},{73.893,63.5991},{75.363,63.5991},{76.834,64.3343},{78.304,64.7020},{79.775,65.0696},{81.245,65.8048},{82.716,65.8048},{84.186,65.8048},{85.657,65.8048},{87.127,66.5401},{88.598,66.5401},{90.068,66.5401},{91.539,66.5401},{93.009,67.2753},{94.480,67.6429},{95.950,68.0106},{97.421,68.0106},{98.891,67.6429},{100.362,67.2753},{101.832,67.2753},{103.303,66.9077},{104.773,66.1724},{106.244,65.8048},{107.714,65.0696},{109.185,64.3343},{110.655,63.9667},{112.126,63.2314},{113.596,62.8638},{115.067,62.8638},{116.537,63.5991},{118.008,63.5991},{119.478,63.5991},{120.949,63.5991},{122.419,63.2314},{123.890,61.7609},{125.360,58.8200},{126.831,57.3495},{128.301,56.6142},{129.772,56.2466},{131.242,55.8790},{132.713,54.7761},{134.183,54.0408},{135.654,52.9380},{137.124,51.4675},{138.595,50.7322},{140.065,49.2617},{141.536,48.8941},{143.006,48.1588},{144.477,48.1588},{145.947,48.1588},{147.418,48.1588},{148.888,48.1588},{150.359,48.1588},{151.829,48.8941},{153.299,49.6293},{154.770,49.6293},{156.240,50.7322},{157.711,52.5703},{159.181,53.3056},{160.652,54.4085},{162.122,55.5113},{163.593,56.2466},{165.063,56.9818},{166.534,57.7171},{168.004,59.1876},{169.475,61.0257},{170.945,61.7609},{172.416,62.4962},{173.886,63.2314},{175.357,63.9667},{176.827,64.3343},{178.298,65.0696},{179.768,65.4372},{181.239,66.1724},{182.709,66.9077},{184.180,68.0106},{185.650,68.3782},{187.121,69.4811},{188.591,69.4811},{190.062,69.8487},{191.532,70.5839},{193.003,71.3192},{194.473,71.6868},{195.944,72.4221},{197.414,73.1573},{198.885,73.1573},{200.355,73.5249},{201.826,73.8926},{203.296,73.8926},{204.767,73.8926},{206.237,73.8926},{207.708,73.8926},{209.178,73.8926},{210.649,73.8926},{212.119,73.8926},{213.590,74.2602},{215.060,74.2602},{216.531,73.8926},{218.001,73.8926},{219.472,73.1573},{220.942,73.1573},{222.413,73.1573},{223.883,73.1573},{225.354,73.1573},{226.824,73.1573},{228.295,73.1573},{229.765,73.1573},{231.236,72.7897},{232.706,72.0544},{234.177,71.3192},{235.647,70.9516},{237.118,70.9516},{238.588,70.9516},{240.059,70.9516},{241.529,70.9516},{243.000,70.5839},{244.470,69.8487},{245.941,69.4811},{247.411,67.6429},{248.882,66.1724},{250.352,65.0696},{251.823,63.5991},{253.293,62.4962},{254.764,61.7609},{256.234,61.3933},{257.705,61.3933},{259.175,60.6581},{260.646,60.2905},{262.116,58.8200},{263.587,56.9818},{265.057,54.0408},{266.528,52.9380},{267.998,51.0998},{269.469,49.2617},{270.939,46.3207},{272.410,44.8502},{273.880,44.8502},{275.351,45.9531},{276.821,47.0560},{278.292,47.7912},{279.762,48.5265},{281.233,49.2617},{282.703,49.6293},{284.174,49.9970}}
spergulifolia[3]={{0.368,56.2466},{1.838,55.8790},{3.309,55.5113},{4.779,55.5113},{6.250,55.8790},{7.720,55.5113},{9.191,56.2466},{10.661,57.3495},{12.132,58.0847},{13.602,58.8200},{15.073,60.2905},{16.543,61.7609},{18.014,62.4962},{19.484,63.5991},{20.955,64.3343},{22.425,65.4372},{23.896,65.8048},{25.366,66.1724},{26.837,67.6429},{28.307,68.3782},{29.778,69.1134},{31.248,69.4811},{32.719,70.5839},{34.189,70.5839},{35.660,70.9516},{37.130,71.6868},{38.601,72.4221},{40.071,73.1573},{41.542,73.1573},{43.012,73.8926},{44.483,74.6278},{45.953,74.9954},{47.424,75.3631},{48.894,75.7307},{50.365,76.0983},{51.835,76.8336},{53.306,76.8336},{54.776,77.5688},{56.247,78.3041},{57.717,79.7746},{59.188,81.2451},{60.658,81.9803},{62.129,81.6127},{63.599,81.2451},{65.070,80.5098},{66.540,80.5098},{68.011,80.5098},{69.481,80.1422},{70.952,80.5098},{72.422,80.5098},{73.893,80.5098},{75.363,80.5098},{76.834,79.7746},{78.304,79.0393},{79.775,78.6717},{81.245,78.6717},{82.716,79.0393},{84.186,79.0393},{85.657,79.0393},{87.127,77.9364},{88.598,77.2012},{90.068,76.0983},{91.539,76.0983},{93.009,76.0983},{94.480,76.4659},{95.950,76.8336},{97.421,76.8336},{98.891,76.8336},{100.362,76.4659},{101.832,76.0983},{103.303,76.0983},{104.773,75.3631},{106.244,74.2602},{107.714,73.8926},{109.185,73.8926},{110.655,73.8926},{112.126,73.8926},{113.596,73.5249},{115.067,72.0544},{116.537,70.9516},{118.008,69.8487},{119.478,67.6429},{120.949,66.1724},{122.419,65.4372},{123.890,63.5991},{125.360,62.1286},{126.831,61.0257},{128.301,59.9228},{129.772,57.7171},{131.242,55.8790},{132.713,54.0408},{134.183,53.3056},{135.654,51.4675},{137.124,49.9970},{138.595,49.9970},{140.065,53.3056},{141.536,53.6732},{143.006,55.1437},{144.477,55.8790},{145.947,56.2466},{147.418,57.3495},{148.888,58.0847},{150.359,59.5552},{151.829,61.3933},{153.299,62.1286},{154.770,62.8638},{156.240,63.9667},{157.711,65.0696},{159.181,65.8048},{160.652,66.5401},{162.122,67.2753},{163.593,67.2753},{165.063,67.2753},{166.534,67.6429},{168.004,68.3782},{169.475,69.1134},{170.945,69.8487},{172.416,70.2163},{173.886,70.2163},{175.357,71.3192},{176.827,72.0544},{178.298,72.7897},{179.768,73.1573},{181.239,73.1573},{182.709,73.1573},{184.180,73.1573},{185.650,73.5249},{187.121,73.5249},{188.591,73.8926},{190.062,73.8926},{191.532,74.6278},{193.003,74.6278},{194.473,73.8926},{195.944,73.8926},{197.414,73.8926},{198.885,73.1573},{200.355,73.1573},{201.826,73.1573},{203.296,73.1573},{204.767,73.1573},{206.237,72.7897},{207.708,72.4221},{209.178,72.0544},{210.649,72.0544},{212.119,71.3192},{213.590,70.9516},{215.060,70.2163},{216.531,69.8487},{218.001,69.4811},{219.472,68.7458},{220.942,68.0106},{222.413,68.0106},{223.883,68.0106},{225.354,68.7458},{226.824,68.3782},{228.295,68.0106},{229.765,66.9077},{231.236,65.4372},{232.706,63.2314},{234.177,59.1876},{235.647,57.7171},{237.118,57.3495},{238.588,56.2466},{240.059,55.1437},{241.529,52.9380},{243.000,51.0998},{244.470,49.2617},{245.941,47.7912},{247.411,45.5855},{248.882,44.8502},{250.352,43.3797},{251.823,42.2768},{253.293,38.2330},{254.764,34.5567},{256.234,32.7186},{257.705,30.5128},{259.175,28.3071},{260.646,24.2632},{262.116,23.5280},{263.587,22.4251},{265.057,22.4251},{266.528,22.4251},{267.998,22.7927},{269.469,22.4251},{270.939,22.4251},{272.410,22.4251},{273.880,22.7927},{275.351,23.5280},{276.821,23.8956},{278.292,24.6309},{279.762,25.3661},{281.233,25.3661},{282.703,26.1014}}
spergulifolia[4]={{0.368,11.3964},{1.838,11.3964},{3.309,11.3964},{4.779,12.4992},{6.250,13.6021},{7.720,16.1755},{7.720,19.4841},{7.720,23.8956},{9.191,25.7337},{10.661,26.4690},{12.132,27.2042},{13.602,28.3071},{15.073,30.1452},{16.543,33.0862},{18.014,34.1891},{19.484,34.1891},{20.955,34.1891},{22.425,34.1891},{23.896,34.5567},{25.366,34.9243},{26.837,35.2920},{28.307,35.6596},{29.778,35.6596},{31.248,36.3948},{32.719,37.1301},{34.189,38.2330},{35.660,38.9682},{37.130,40.0711},{38.601,41.1740},{40.071,41.5416},{41.542,41.5416},{43.012,42.2768},{44.483,43.0121},{45.953,43.3797},{47.424,44.1150},{48.894,44.4826},{50.365,44.4826},{51.835,45.2178},{53.306,45.2178},{54.776,45.9531},{56.247,45.9531},{57.717,46.6883},{59.188,45.9531},{60.658,45.9531},{62.129,45.9531},{63.599,45.9531},{65.070,46.3207},{66.540,46.6883},{68.011,46.6883},{69.481,47.0560},{70.952,47.0560},{72.422,46.6883},{73.893,46.6883},{75.363,46.3207},{76.834,45.9531},{78.304,45.5855},{79.775,45.2178},{81.245,44.4826},{82.716,44.1150},{84.186,43.7473},{85.657,43.3797},{87.127,42.2768},{88.598,41.1740},{90.068,40.8063},{91.539,39.7035},{93.009,38.9682},{94.480,38.2330},{95.950,37.4977},{97.421,36.3948},{98.891,36.3948},{100.362,36.3948},{101.832,36.3948},{103.303,36.0272},{104.773,34.1891},{106.244,30.8805},{107.714,27.2042},{109.185,26.8366},{110.655,27.9395},{112.126,30.5128},{113.596,31.9833},{115.067,33.8215},{116.537,37.1301},{118.008,38.9682},{119.478,41.1740},{120.949,42.2768},{122.419,43.3797},{123.890,44.1150},{125.360,45.2178},{126.831,45.5855},{128.301,46.3207},{129.772,47.7912},{131.242,48.1588},{132.713,48.8941},{134.183,49.6293},{135.654,50.7322},{137.124,51.0998},{138.595,51.8351},{140.065,51.8351},{141.536,51.8351},{143.006,51.8351},{144.477,52.5703},{145.947,52.5703},{147.418,53.3056},{148.888,53.3056},{150.359,53.6732},{151.829,54.0408},{153.299,54.4085},{154.770,54.7761},{156.240,54.0408},{157.711,54.0408},{159.181,54.0408},{160.652,54.0408},{162.122,53.3056},{163.593,54.0408},{165.063,54.0408},{166.534,54.0408},{168.004,54.0408},{169.475,54.0408},{170.945,53.6732},{172.416,52.9380},{173.886,52.5703},{175.357,52.5703},{176.827,52.2027},{178.298,51.8351},{179.768,51.0998},{181.239,50.7322},{182.709,49.9970},{184.180,49.6293},{185.650,48.8941},{187.121,48.5265},{188.591,47.7912},{190.062,47.4236},{191.532,46.6883},{193.003,46.3207},{194.473,45.5855},{195.944,44.1150},{197.414,43.0121},{198.885,41.5416},{200.355,40.4387},{201.826,38.9682},{203.296,37.4977},{204.767,35.2920},{206.237,33.8215},{207.708,32.3510},{209.178,30.1452},{210.649,28.6747},{212.119,23.8956},{213.590,19.8517},{215.060,18.0136},{216.531,17.2784},{218.001,17.2784},{219.472,17.2784},{220.942,17.2784},{222.413,18.0136},{223.883,19.1165}}

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