(*******************************  swertiifolia  *)

Needs["Splines`"]

swertiifolia[1]={{0.500,13.4985},{2.500,11.9987},{4.499,10.9988},{6.499,10.4988},{8.499,10.4988},{10.499,11.9987},{12.499,12.9985},{14.498,16.9981},{16.498,20.4977},{18.498,26.4970},{20.498,29.4967},{22.497,32.9963},{24.497,40.4954},{26.497,44.4950},{28.497,48.4945},{30.497,49.9944},{32.496,50.9943},{34.496,52.9940},{36.496,54.4939},{38.496,55.9937},{40.495,57.9935},{42.495,58.9934},{44.495,59.9933},{46.495,60.4932},{48.495,61.4931},{50.494,61.4931},{52.494,61.4931},{54.494,61.9930},{56.494,62.4930},{58.493,61.9930},{60.493,62.4930},{62.493,61.9930},{64.493,60.9931},{66.493,59.4933},{68.492,58.4934},{70.492,57.4935},{72.492,56.9936},{74.492,55.9937},{76.491,54.4939},{78.491,52.9940},{80.491,51.4942},{82.491,49.9944},{84.490,47.9946},{86.490,44.9949},{88.490,41.4953},{90.490,38.9956},{92.490,35.9959},{94.489,32.9963},{96.489,30.9965},{98.489,28.9967},{100.489,25.9971},{102.488,25.9971},{104.488,28.4968},{106.488,31.4965},{108.488,33.4962},{110.488,34.4961},{112.487,36.9958},{114.487,38.9956},{116.487,39.9955},{118.487,41.9953},{120.486,42.9952},{122.486,43.9951},{124.486,44.9949},{126.486,45.9948},{128.486,46.4948},{130.485,47.4947},{132.485,47.4947},{134.485,48.4945},{136.485,48.4945},{138.484,47.9946},{140.484,48.4945},{142.484,48.4945},{144.484,48.9945},{146.484,47.9946},{148.483,47.4947},{150.483,47.4947},{152.483,47.4947},{154.483,46.4948},{156.482,44.9949},{158.482,43.9951},{160.482,42.9952},{162.482,40.9954},{164.481,39.9955},{166.481,33.4962},{168.481,29.4967},{170.481,25.4971},{172.481,23.9973},{174.480,20.4977},{176.480,18.9979},{178.480,18.4979},{180.480,19.4978},{182.479,20.4977},{184.479,20.9976},{186.479,22.9974}}
swertiifolia[2]={{0.500,19.9978},{2.500,18.9979},{4.499,17.4980},{6.499,16.4981},{8.499,16.9981},{10.499,19.4978},{12.499,21.4976},{14.498,24.9972},{16.498,26.9970},{18.498,29.9966},{20.498,32.4963},{22.497,34.9961},{24.497,36.9958},{26.497,38.9956},{28.497,40.9954},{30.497,42.4952},{32.496,43.9951},{34.496,45.9948},{36.496,47.4947},{38.496,48.4945},{40.495,49.9944},{42.495,50.9943},{44.495,51.4942},{46.495,52.4941},{48.495,52.9940},{50.494,53.9939},{52.494,54.4939},{54.494,54.4939},{56.494,54.4939},{58.493,54.9938},{60.493,55.4938},{62.493,55.4938},{64.493,55.4938},{66.493,55.4938},{68.492,54.9938},{70.492,54.4939},{72.492,53.4940},{74.492,53.4940},{76.491,52.9940},{78.491,51.9942},{80.491,50.9943},{82.491,48.9945},{84.490,46.9947},{86.490,46.4948},{88.490,45.4949},{90.490,43.9951},{92.490,41.9953},{94.489,39.9955},{96.489,37.9957},{98.489,35.9959},{100.489,33.9962},{102.488,30.4966},{104.488,29.4967},{106.488,31.9964},{108.488,34.4961},{110.488,36.9958},{112.487,39.9955},{114.487,42.4952},{116.487,45.4949},{118.487,46.9947},{120.486,48.9945},{122.486,49.9944},{124.486,51.9942},{126.486,53.4940},{128.486,54.9938},{130.485,56.4936},{132.485,56.4936},{134.485,56.4936},{136.485,57.4935},{138.484,57.4935},{140.484,57.4935},{142.484,57.4935},{144.484,57.4935},{146.484,57.4935},{148.483,57.4935},{150.483,56.9936},{152.483,56.4936},{154.483,55.9937},{156.482,54.4939},{158.482,53.9939},{160.482,52.4941},{162.482,50.4943},{164.481,49.4944},{166.481,47.9946},{168.481,44.9949},{170.481,43.4951},{172.481,39.9955},{174.480,37.4958},{176.480,33.9962},{178.480,29.4967},{180.480,25.9971},{182.479,23.9973},{184.479,25.4971},{186.479,27.4969}}
swertiifolia[3]={{0.500,19.9978},{2.500,18.4979},{4.499,17.4980},{6.499,21.9975},{8.499,22.9974},{10.499,24.4972},{12.499,28.9967},{14.498,31.4965},{16.498,34.4961},{18.498,37.4958},{20.498,39.4956},{22.497,41.9953},{24.497,43.4951},{26.497,45.4949},{28.497,47.4947},{30.497,47.4947},{32.496,47.9946},{34.496,48.4945},{36.496,49.9944},{38.496,50.4943},{40.495,50.4943},{42.495,51.4942},{44.495,51.4942},{46.495,51.4942},{48.495,50.9943},{50.494,51.4942},{52.494,51.4942},{54.494,50.9943},{56.494,50.4943},{58.493,49.9944},{60.493,49.4944},{62.493,48.4945},{64.493,47.9946},{66.493,46.4948},{68.492,44.9949},{70.492,43.9951},{72.492,41.4953},{74.492,39.4956},{76.491,36.9958},{78.491,35.4960},{80.491,33.4962},{82.491,28.4968},{84.490,26.9970},{86.490,25.9971},{88.490,23.9973},{90.490,21.9975},{92.490,20.4977},{94.489,18.9979},{96.489,18.4979},{98.489,18.4979},{100.489,20.4977},{102.488,23.4974},{104.488,26.4970},{106.488,29.4967},{108.488,31.9964},{110.488,34.9961},{112.487,37.9957},{114.487,40.4954},{116.487,43.9951},{118.487,45.4949},{120.486,47.9946},{122.486,49.9944},{124.486,50.9943},{126.486,52.9940},{128.486,54.4939},{130.485,54.9938},{132.485,55.4938},{134.485,55.9937},{136.485,55.4938},{138.484,56.4936},{140.484,56.4936},{142.484,56.4936},{144.484,57.4935},{146.484,56.4936},{148.483,55.4938},{150.483,55.4938},{152.483,55.4938},{154.483,54.4939},{156.482,53.9939},{158.482,52.4941},{160.482,52.4941},{162.482,49.9944},{164.481,47.9946},{166.481,46.4948},{168.481,44.4950},{170.481,41.9953},{172.481,39.9955},{174.480,37.9957},{176.480,32.4963},{178.480,30.9965},{180.480,25.9971},{182.479,27.9969},{184.479,30.9965},{186.479,33.9962}}
swertiifolia[4]={{0.500,23.4974},{2.500,22.9974},{4.499,18.4979},{6.499,18.9979},{8.499,22.9974},{10.499,26.4970},{12.499,30.4966},{14.498,32.9963},{16.498,34.4961},{18.498,38.4957},{20.498,39.9955},{22.497,40.9954},{24.497,43.4951},{26.497,45.4949},{28.497,47.4947},{30.497,48.4945},{32.496,48.9945},{34.496,50.9943},{36.496,51.4942},{38.496,51.4942},{40.495,51.4942},{42.495,52.4941},{44.495,52.4941},{46.495,53.4940},{48.495,52.4941},{50.494,51.4942},{52.494,50.4943},{54.494,50.4943},{56.494,48.9945},{58.493,47.9946},{60.493,46.9947},{62.493,45.4949},{64.493,43.9951},{66.493,41.9953},{68.492,40.9954},{70.492,37.9957},{72.492,36.4959},{74.492,30.9965},{76.491,28.4968},{78.491,26.4970},{80.491,22.4975},{82.491,21.4976},{84.490,22.4975},{86.490,25.4971},{88.490,27.9969},{90.490,32.9963},{92.490,36.4959},{94.489,39.4956},{96.489,44.9949},{98.489,46.4948},{100.489,46.9947},{102.488,49.4944},{104.488,50.4943},{106.488,52.4941},{108.488,54.4939},{110.488,54.9938},{112.487,55.4938},{114.487,56.4936},{116.487,56.4936},{118.487,55.9937},{120.486,55.4938},{122.486,55.4938},{124.486,55.4938},{126.486,54.9938},{128.486,55.4938},{130.485,54.9938},{132.485,53.4940},{134.485,52.4941},{136.485,51.9942},{138.484,50.4943},{140.484,48.9945},{142.484,47.9946},{144.484,43.9951},{146.484,40.9954},{148.483,38.9956},{150.483,34.4961},{152.483,32.9963},{154.483,29.9966},{156.482,27.9969},{158.482,24.9972},{160.482,20.4977},{162.482,19.9978},{164.481,18.9979},{166.481,17.4980},{168.481,20.9976}}

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