(*******************************  microsperma  *)

Needs["Splines`"]

anatolica[1]={{8.606,0.4098},{8.606,21.7197},{8.606,29.5060},{8.606,34.4236},{10.245,40.1609},{11.884,42.2099},{13.524,43.8491},{15.163,44.6688},{16.802,45.8982},{18.441,46.7178},{20.080,47.1276},{21.720,47.9472},{23.359,48.7668},{24.998,49.1766},{26.637,49.5864},{28.277,49.5864},{29.916,49.5864},{31.555,50.4060},{33.194,50.4060},{34.833,50.4060},{36.473,50.4060},{38.112,50.4060},{39.751,50.4060},{41.390,50.4060},{43.030,50.4060},{44.669,50.4060},{46.308,49.5864},{47.947,49.5864},{49.586,49.1766},{51.226,48.7668},{52.865,48.7668},{54.504,47.9472},{56.143,47.9472},{57.783,47.1276},{59.422,46.7178},{61.061,46.7178},{62.700,45.4884},{64.339,45.0786},{65.979,44.2589},{67.618,42.6197},{69.257,40.9805},{70.896,38.9315},{72.535,35.2432},{74.175,29.0962},{75.814,18.8510},{77.453,13.1138},{79.092,11.8843},{80.732,11.4745},{82.371,11.0647},{84.010,10.2451},{85.649,10.2451},{87.288,11.0647},{87.288,14.7530},{87.288,25.8177},{87.288,29.5060},{88.928,32.7844},{90.567,35.6530},{92.206,37.7021},{93.845,38.9315},{95.485,39.7511},{97.124,40.5707},{98.763,41.3903},{100.402,42.2099},{102.041,42.6197},{103.681,43.0295},{105.320,43.0295},{106.959,43.8491},{108.598,43.8491},{110.238,43.8491},{111.877,43.8491},{113.516,43.8491},{115.155,43.8491},{116.794,43.8491},{118.434,43.8491},{120.073,43.4393},{121.712,43.8491},{123.351,43.8491},{124.991,43.8491},{126.630,43.0295},{128.269,43.0295},{129.908,43.0295},{131.547,42.2099},{133.187,42.2099},{134.826,41.3903},{136.465,40.9805},{138.104,39.7511},{139.744,38.9315},{141.383,38.5217},{143.022,37.7021},{144.661,36.4727},{146.300,35.6530},{147.940,34.4236},{149.579,32.7844},{151.218,29.9158},{152.857,27.0471},{154.497,22.5393},{156.136,6.1471},{156.136,10.6549},{156.136,18.0314},{157.775,3.6882},{159.414,3.6882},{161.053,2.8686},{162.693,3.6882}}
anatolica[2]={{0.410,22.1295},{2.049,17.6216},{3.688,16.8020},{5.327,16.8020},{6.967,16.8020},{8.606,17.6216},{10.245,22.1295},{10.245,33.6040},{11.884,37.2923},{13.524,41.3903},{15.163,44.2589},{16.802,46.3080},{18.441,47.9472},{20.080,48.7668},{21.720,49.5864},{23.359,50.4060},{24.998,51.2256},{26.637,51.6354},{28.277,52.4551},{29.916,52.8649},{31.555,52.8649},{33.194,52.8649},{34.833,52.8649},{36.473,52.8649},{38.112,53.6845},{39.751,53.6845},{41.390,53.6845},{43.030,53.6845},{44.669,53.6845},{46.308,53.6845},{47.947,53.6845},{49.586,53.6845},{51.226,53.6845},{52.865,53.2747},{54.504,52.8649},{56.143,52.8649},{57.783,52.8649},{59.422,52.8649},{61.061,52.4551},{62.700,52.0452},{64.339,51.6354},{65.979,50.8158},{67.618,50.4060},{69.257,49.5864},{70.896,48.3570},{72.535,46.7178},{74.175,45.8982},{75.814,44.2589},{77.453,41.8001},{79.092,38.5217},{80.732,11.4745},{80.732,21.7197},{80.732,27.4569},{80.732,33.6040},{82.371,10.6549},{84.010,10.6549},{85.649,11.4745},{87.288,12.2942},{88.928,14.3432},{90.567,24.5883},{92.206,38.5217},{93.845,40.1609},{95.485,42.6197},{97.124,45.0786},{98.763,45.0786},{100.402,45.0786},{102.041,47.9472},{103.681,48.3570},{105.320,49.1766},{106.959,50.4060},{108.598,49.9962},{110.238,50.4060},{111.877,50.4060},{113.516,50.4060},{115.155,51.2256},{116.794,51.2256},{118.434,51.2256},{120.073,51.2256},{121.712,51.2256},{123.351,51.2256},{124.991,51.2256},{126.630,51.2256},{128.269,50.4060},{129.908,50.4060},{131.547,50.4060},{133.187,50.4060},{134.826,49.9962},{136.465,49.5864},{138.104,49.5864},{139.744,49.1766},{141.383,48.7668},{143.022,47.9472},{144.661,47.9472},{146.300,47.1276},{147.940,46.3080},{149.579,45.8982},{151.218,44.6688},{152.857,43.4393},{154.497,41.8001},{156.136,38.5217},{157.775,18.4412},{157.775,31.9648},{159.414,13.9334},{161.053,11.4745},{162.693,9.8353},{164.332,7.3765},{165.971,6.5569},{167.610,5.3275},{169.249,6.1471}}
anatolica[3]={{0.410,6.5569},{2.049,4.5079},{3.688,3.2784},{5.327,2.0490},{6.967,0.8196},{8.606,0.4098},{10.245,23.7687},{11.884,17.6216},{11.884,31.1452},{13.524,11.0647},{13.524,34.8334},{15.163,0.8196},{15.163,7.3765},{15.163,36.8825},{16.802,38.5217},{18.441,40.1609},{20.080,41.3903},{21.720,42.2099},{23.359,43.0295},{24.998,43.8491},{26.637,44.2589},{28.277,44.6688},{29.916,45.4884},{31.555,46.3080},{33.194,46.3080},{34.833,47.1276},{36.473,47.1276},{38.112,47.9472},{39.751,47.9472},{41.390,47.9472},{43.030,47.9472},{44.669,48.3570},{46.308,48.7668},{47.947,48.7668},{49.586,48.7668},{51.226,49.1766},{52.865,49.5864},{54.504,49.5864},{56.143,49.5864},{57.783,49.5864},{59.422,49.5864},{61.061,49.1766},{62.700,48.7668},{64.339,48.7668},{65.979,48.7668},{67.618,48.3570},{69.257,47.9472},{70.896,47.9472},{72.535,47.5374},{74.175,47.1276},{75.814,46.3080},{77.453,45.4884},{79.092,45.0786},{80.732,44.2589},{82.371,43.0295},{84.010,41.8001},{85.649,40.1609},{87.288,37.7021},{88.928,35.6530},{90.567,31.9648},{92.206,27.0471},{93.845,22.5393},{95.485,18.4412},{97.124,15.5726},{98.763,13.5236},{100.402,13.1138},{102.041,15.1628},{102.041,19.2608},{103.681,29.9158},{105.320,32.7844},{106.959,42.2099},{108.598,45.8982},{110.238,47.5374},{111.877,49.1766},{113.516,49.9962},{115.155,51.2256},{116.794,52.0452},{118.434,52.8649},{120.073,53.2747},{121.712,53.6845},{123.351,54.5041},{124.991,54.5041},{126.630,54.5041},{128.269,54.5041},{129.908,54.5041},{131.547,55.3237},{133.187,55.3237},{134.826,55.3237},{136.465,55.3237},{138.104,55.3237},{139.744,55.3237},{141.383,55.3237},{143.022,55.3237},{144.661,55.3237},{146.300,55.3237},{147.940,55.3237},{149.579,55.3237},{151.218,55.3237},{152.857,54.9139},{154.497,54.5041},{156.136,54.5041},{157.775,53.6845},{159.414,53.2747},{161.053,52.8649},{162.693,52.8649},{164.332,52.0452},{165.971,51.2256},{167.610,49.5864},{169.249,48.3570},{170.889,47.1276},{172.528,45.4884},{174.167,42.6197},{175.806,25.8177},{175.806,37.7021},{177.446,22.1295},{179.085,19.2608},{180.724,16.8020},{182.363,16.8020},{184.002,17.2118},{185.642,16.3922},{187.281,15.9824},{188.920,18.8510}}
anatolica[4]={{0.410,6.5569},{2.049,6.9667},{3.688,6.1471},{5.327,6.1471},{6.967,7.7863},{8.606,11.4745},{8.606,21.7197},{10.245,31.5550},{11.884,33.6040},{13.524,35.6530},{15.163,37.7021},{16.802,38.5217},{18.441,39.7511},{20.080,40.5707},{21.720,41.3903},{23.359,41.3903},{24.998,42.2099},{26.637,42.6197},{28.277,43.0295},{29.916,43.0295},{31.555,43.0295},{33.194,43.0295},{34.833,43.0295},{36.473,42.6197},{38.112,43.0295},{39.751,43.0295},{41.390,42.6197},{43.030,43.0295},{44.669,43.0295},{46.308,43.0295},{47.947,43.0295},{49.586,43.0295},{51.226,43.0295},{52.865,43.0295},{54.504,43.0295},{56.143,43.0295},{57.783,43.0295},{59.422,42.2099},{61.061,42.2099},{62.700,42.2099},{64.339,41.3903},{65.979,41.3903},{67.618,40.5707},{69.257,40.5707},{70.896,39.7511},{72.535,38.9315},{74.175,37.7021},{75.814,36.8825},{77.453,35.2432},{79.092,32.3746},{80.732,27.4569},{82.371,13.5236},{82.371,18.8510},{84.010,9.8353},{85.649,7.3765},{87.288,6.5569},{88.928,5.3275},{90.567,4.5079},{92.206,0.4098},{92.206,5.3275},{93.845,6.9667},{95.485,13.1138},{97.124,30.3256},{98.763,32.3746},{100.402,34.8334},{102.041,36.0628},{103.681,37.7021},{105.320,38.5217},{106.959,38.9315},{108.598,39.3413},{110.238,39.7511},{111.877,40.5707},{113.516,40.5707},{115.155,40.9805},{116.794,41.3903},{118.434,41.3903},{120.073,41.3903},{121.712,41.3903},{123.351,41.3903},{124.991,41.3903},{126.630,41.3903},{128.269,41.3903},{129.908,40.9805},{131.547,41.3903},{133.187,41.3903},{134.826,41.3903},{136.465,40.5707},{138.104,40.5707},{139.744,40.5707},{141.383,39.7511},{143.022,39.3413},{144.661,38.9315},{146.300,38.9315},{147.940,38.1119},{149.579,38.1119},{151.218,37.7021},{152.857,37.2923},{154.497,36.4727},{156.136,36.0628},{157.775,35.2432},{159.414,34.4236},{161.053,33.6040},{162.693,31.9648},{164.332,30.3256},{165.971,28.2766},{167.610,23.3589},{169.249,14.3432},{170.889,9.4255},{172.528,8.1961},{174.167,7.3765},{175.806,6.5569},{177.446,6.1471}}

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