(*******************************  caramanica  *)

Needs["Splines`"]

caramanica[1]={{0.705,6.3468},{3.526,7.7572},{6.347,7.7572},{9.168,8.4624},{11.988,10.5780},{14.809,12.6936},{17.630,15.5144},{20.451,16.2196},{23.272,17.6300},{26.092,18.3352},{28.913,19.0404},{31.734,19.0404},{34.555,19.0404},{37.376,19.0404},{40.196,19.0404},{43.017,17.6300},{45.838,16.9248},{48.659,15.5144},{51.480,13.3988},{54.300,16.9248},{57.121,19.7456},{59.942,21.8612},{62.763,23.2716},{65.584,24.6820},{68.405,24.6820},{71.225,24.6820},{74.046,24.6820},{76.867,26.0924},{79.688,26.0924},{82.509,24.6820},{85.329,23.9768},{88.150,22.5664},{90.971,21.8612},{93.792,20.4508},{96.613,18.3352},{99.433,17.6300},{102.254,19.7456},{105.075,21.8612},{107.896,21.1560}}
caramanica[2]={{0.705,8.4624},{3.526,7.7572},{6.347,6.3468},{9.168,4.9364},{11.988,7.0520},{14.809,9.1676},{17.630,10.5780},{20.451,11.9884},{23.272,11.9884},{26.092,13.3988},{28.913,14.8092},{31.734,14.8092},{34.555,14.8092},{37.376,14.8092},{40.196,14.8092},{43.017,15.5144},{45.838,16.2196},{48.659,16.2196},{51.480,16.2196},{54.300,16.2196},{57.121,15.5144},{59.942,14.1040},{62.763,11.9884},{65.584,13.3988},{68.405,14.8092},{71.225,16.2196},{74.046,16.2196},{76.867,17.6300},{79.688,17.6300},{82.509,17.6300},{85.329,17.6300},{88.150,17.6300},{90.971,17.6300},{93.792,16.9248},{96.613,16.2196},{99.433,15.5144},{102.254,14.1040},{105.075,13.3988},{107.896,10.5780},{110.717,7.7572}}
caramanica[3]={{0.705,7.7572},{3.526,5.6416},{6.347,2.8208},{9.168,4.9364},{11.988,8.4624},{14.809,11.2832},{17.630,12.6936},{20.451,13.3988},{23.272,14.8092},{26.092,15.5144},{28.913,16.2196},{31.734,16.2196},{34.555,17.6300},{37.376,17.6300},{40.196,17.6300},{43.017,16.9248},{45.838,16.2196},{48.659,15.5144},{51.480,14.8092},{54.300,13.3988},{57.121,11.2832},{59.942,8.4624},{62.763,10.5780},{65.584,13.3988},{68.405,15.5144},{71.225,16.9248},{74.046,19.7456},{76.867,21.1560},{79.688,23.2716},{82.509,23.2716},{85.329,23.2716},{88.150,24.6820},{90.971,24.6820},{93.792,24.6820},{96.613,23.2716},{99.433,23.2716},{102.254,22.5664},{105.075,21.8612},{107.896,21.1560},{110.717,19.7456},{113.537,17.6300},{116.358,14.1040},{119.179,11.9884},{122.000,15.5144}}
caramanica[4]={{0.7052,11.2832},{3.5260,11.2832},{6.3468,14.1040},{9.1676,15.5144},{11.9884,16.9248},{14.8092,17.6300},{17.6300,17.6300},{20.4508,17.6300},{23.2716,17.6300},{26.0924,17.6300},{28.9132,17.6300},{31.7340,15.5144},{34.5549,14.1040},{37.3757,12.6936},{40.1965,11.9884},{43.0173,8.4624},{45.8381,8.4624},{48.6589,10.5780},{51.4797,14.1040},{54.3005,14.8092},{57.1213,16.2196},{59.9421,16.2196},{62.7629,16.2196},{65.5837,16.2196},{68.4045,16.2196},{71.2253,15.5144},{74.0461,14.1040},{76.8669,12.6936},{79.6877,10.5780},{82.5085,8.4624},{85.3293,6.3468},{88.1501,7.7572}}

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