(*******************************  brevicaulis  *)

Needs["Splines`"]

brevicaulis[1]={{0.594,1.7821},{2.970,2.3761},{5.346,2.9701},{7.722,3.5641},{10.098,5.9402},{12.474,8.3163},{14.850,12.4744},{17.227,15.4445},{19.603,19.6026},{21.979,21.9787},{21.979,24.9488},{24.355,24.9488},{26.731,27.9189},{29.107,30.8890},{29.107,33.8591},{31.483,35.0471},{33.859,36.8292},{36.235,39.7992},{38.611,42.1753},{40.987,45.1454},{43.363,49.8976},{45.739,55.8378},{48.116,59.9959},{50.492,61.1839},{52.868,62.3720},{55.244,62.3720},{57.620,62.3720},{59.996,62.3720},{62.372,62.3720},{64.748,61.7779},{67.124,58.2138},{69.500,53.4617},{71.876,49.3035},{74.252,45.7394},{76.628,45.7394},{79.004,42.7693},{81.381,40.3933},{83.757,40.3933},{86.133,38.0172},{88.509,33.8591},{90.885,33.2650},{93.261,29.1069},{95.637,27.9189},{98.013,24.3548},{100.389,21.9787},{102.765,21.9787},{105.141,20.7907},{107.517,21.3847},{109.893,22.5727},{112.270,22.5727},{114.646,21.3847},{117.022,24.3548},{119.398,24.3548},{121.774,25.5428},{124.150,27.9189},{126.526,30.2950},{128.902,30.8890},{131.278,32.6710},{133.654,33.8591},{136.030,36.2351},{138.406,38.0172},{140.782,39.2052},{143.158,40.9873},{145.535,42.7693},{147.911,44.5514},{150.287,45.1454},{150.287,48.1155},{152.663,51.6796},{155.039,53.4617},{157.415,54.6497},{159.791,55.8378},{162.167,55.2437},{164.543,55.2437},{166.919,54.6497},{169.295,53.4617},{171.671,51.0856},{174.047,49.8976},{176.424,42.1753},{178.800,38.6112},{181.176,35.6411},{183.552,33.2650},{185.928,33.8591},{188.304,31.4830},{190.680,31.4830},{193.056,29.1069},{195.432,27.9189},{197.808,25.5428},{200.184,25.5428},{202.560,21.9787},{204.936,20.1966},{207.312,17.8206},{209.689,18.4146},{212.065,19.6026},{214.441,19.0086}}
brevicaulis[2]={{0.594,13.6624},{2.970,13.6624},{5.346,14.8505},{7.722,16.6325},{10.098,17.8206},{12.474,20.1966},{14.850,23.7607},{17.227,26.7308},{19.603,31.4830},{21.979,36.8292},{24.355,39.7992},{26.731,42.7693},{29.107,44.5514},{31.483,45.1454},{33.859,45.1454},{36.235,46.3335},{38.611,46.3335},{40.987,44.5514},{43.363,44.5514},{45.739,43.9574},{48.116,44.5514},{50.492,44.5514},{52.868,43.3634},{55.244,42.1753},{57.620,39.7992},{59.996,38.6112},{62.372,38.0172},{64.748,36.2351},{67.124,34.4531},{69.500,32.0770},{71.876,30.2950},{74.252,30.2950},{76.628,28.5129},{79.004,26.1368},{81.381,26.7308},{83.757,25.5428},{86.133,26.7308},{88.509,26.1368},{90.885,26.7308},{93.261,27.3249},{95.637,29.1069},{98.013,30.2950},{100.389,30.2950},{102.765,31.4830},{105.141,30.8890},{107.517,32.0770},{109.893,32.6710},{112.270,33.8591},{114.646,35.0471},{117.022,36.8292},{119.398,36.8292},{121.774,38.6112},{124.150,38.6112},{126.526,39.7992},{128.902,41.5813},{131.278,42.1753},{133.654,41.5813},{136.030,41.5813},{138.406,41.5813},{140.782,40.9873},{143.158,41.5813},{145.535,40.3933},{147.911,38.0172},{150.287,36.2351},{152.663,34.4531},{155.039,32.0770},{157.415,29.7009},{159.791,26.7308},{162.167,24.3548},{164.543,22.5727},{166.919,20.7907},{169.295,18.4146},{171.671,18.4146},{174.047,18.4146},{176.424,16.6325},{178.800,18.4146},{181.176,18.4146}}
brevicaulis[3]={{0.594,7.1282},{2.970,7.1282},{5.346,5.9402},{7.722,4.1581},{10.098,5.3462},{12.474,4.1581},{14.850,5.3462},{17.227,2.9701},{19.603,5.9402},{21.979,7.1282},{24.355,8.9103},{26.731,10.6923},{29.107,10.6923},{31.483,12.4744},{33.859,13.6624},{36.235,13.0684},{38.611,15.4445},{40.987,17.2265},{43.363,17.8206},{45.739,18.4146},{48.116,20.1966},{50.492,22.5727},{52.868,23.7607},{55.244,28.5129},{57.620,29.7009},{59.996,32.0770},{62.372,32.0770},{64.748,32.0770},{67.124,30.2950},{69.500,31.4830},{71.876,30.2950},{74.252,28.5129},{76.628,26.7308},{79.004,25.5428},{81.381,24.9488},{83.757,24.3548},{86.133,21.9787},{88.509,20.1966},{90.885,20.1966},{93.261,18.4146},{95.637,16.6325},{98.013,11.8804},{98.013,14.8505},{100.389,10.6923},{102.765,11.2864},{105.141,8.3163},{107.517,7.1282},{109.893,7.1282},{112.270,7.1282},{114.646,7.1282},{117.022,8.9103},{119.398,10.0983},{121.774,11.2864},{124.150,11.2864},{126.526,12.4744},{128.902,13.6624},{131.278,14.8505},{133.654,16.0385},{136.030,18.4146},{138.406,19.0086},{140.782,19.0086},{143.158,20.1966},{145.535,21.9787},{147.911,23.1667},{150.287,24.3548},{152.663,27.3249},{155.039,28.5129},{157.415,29.7009},{159.791,32.0770},{162.167,32.6710},{164.543,31.4830},{166.919,32.6710},{169.295,32.6710},{171.671,31.4830},{174.047,30.2950},{176.424,30.2950},{178.800,29.1069},{181.176,25.5428},{183.552,25.5428},{185.928,23.7607},{188.304,20.7907},{190.680,20.1966},{193.056,19.0086},{195.432,16.6325},{197.808,16.0385},{200.184,13.6624},{202.560,1.1880},{202.560,11.8804}}

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