(*******************************  cserei  *)

Needs["Splines`"]

cserei[1]={{0.427,19.6552},{2.136,20.5098},{3.846,22.2190},{5.555,22.6463},{7.264,23.0736},{8.973,23.5008},{8.973,29.9102},{10.682,24.3554},{10.682,26.4919},{10.682,39.7378},{12.391,52.1291},{14.101,55.9747},{15.810,59.8203},{17.519,61.9568},{19.228,63.6659},{20.937,64.9478},{22.646,66.6569},{24.355,67.0842},{26.065,67.0842},{27.774,67.5115},{29.483,68.3661},{31.192,68.7934},{32.901,68.7934},{34.610,68.7934},{36.319,68.7934},{38.029,68.7934},{39.738,68.7934},{41.447,69.6479},{43.156,69.6479},{44.865,69.6479},{46.574,68.7934},{48.284,68.3661},{49.993,67.5115},{51.702,67.0842},{53.411,67.0842},{55.120,66.2296},{56.829,64.9478},{58.538,63.2386},{60.248,60.6749},{61.957,57.2566},{63.666,53.4110},{65.375,49.5654},{67.084,45.2925},{68.793,41.0196},{70.503,38.8832},{72.212,36.3195},{73.921,34.1830},{75.630,32.0466},{77.339,29.9102},{79.048,29.0556},{80.757,26.9191},{82.467,23.5008},{84.176,21.3644},{85.885,19.6552},{87.594,19.2280},{89.303,17.9461},{91.012,16.6642},{92.721,15.8097},{94.431,14.9551},{96.140,14.9551},{97.849,15.8097},{99.558,16.6642},{101.267,17.0915},{102.976,18.3734},{104.686,18.3734},{106.395,19.2280},{108.104,19.2280},{109.813,19.2280},{111.522,19.6552},{111.522,24.3554},{113.231,20.0825},{113.231,22.2190},{113.231,25.2100},{114.940,21.3644},{116.650,26.4919},{118.359,29.0556},{120.068,31.6193},{121.777,36.3195},{123.486,41.4469},{125.195,46.5744},{126.905,55.9747},{128.614,61.5295},{130.323,66.2296},{132.032,68.3661},{133.741,70.0752},{135.450,71.7844},{137.159,74.3481},{138.869,74.7754},{140.578,75.6300},{142.287,76.4846},{143.996,77.3391},{145.705,77.7664},{147.414,78.1937},{149.124,78.1937},{150.833,78.1937},{152.542,78.1937},{154.251,78.1937},{155.960,78.1937},{157.669,78.1937},{159.378,77.7664},{161.088,77.3391},{162.797,77.3391},{164.506,76.9118},{166.215,76.0573},{167.924,75.6300},{169.633,74.7754},{171.342,74.3481},{173.052,72.6390},{174.761,72.2117},{176.470,70.0752},{178.179,68.3661},{179.888,65.3751},{181.597,61.5295},{183.307,50.8473},{183.307,54.6929},{185.016,44.4380},{186.725,36.7468},{188.434,32.4739},{190.143,28.6283},{191.852,24.3554},{193.561,22.2190},{195.271,21.3644},{196.980,19.6552},{198.689,14.1005},{200.398,12.8186},{202.107,11.5368},{203.816,9.4003},{205.526,8.5458},{207.235,8.1185},{208.944,8.9730},{210.653,8.9730},{212.362,10.2549},{214.071,12.8186},{215.780,14.1005},{217.490,16.2369},{219.199,17.9461}}
cserei[2]={{0.427,14.5278},{2.136,13.2459},{3.846,12.3914},{5.555,11.5368},{7.264,11.5368},{8.973,12.8186},{10.682,14.1005},{12.391,15.8097},{14.101,19.6552},{15.810,27.7737},{15.810,35.4649},{17.519,46.1471},{19.228,49.9927},{20.937,52.5564},{22.646,54.2656},{24.355,55.5474},{26.065,56.4020},{27.774,57.6839},{29.483,58.1112},{31.192,58.9657},{32.901,59.8203},{34.610,60.6749},{36.319,62.3840},{38.029,61.9568},{39.738,61.9568},{41.447,61.9568},{43.156,61.9568},{44.865,62.8113},{46.574,62.8113},{48.284,63.2386},{49.993,63.6659},{51.702,64.0932},{53.411,64.5205},{55.120,64.5205},{56.829,64.5205},{58.538,64.5205},{60.248,65.3751},{61.957,65.8024},{63.666,67.0842},{65.375,67.0842},{67.084,67.0842},{68.793,66.2296},{70.503,65.3751},{72.212,64.5205},{73.921,64.0932},{75.630,62.8113},{77.339,62.3840},{79.048,61.5295},{80.757,60.6749},{82.467,59.8203},{84.176,57.6839},{85.885,55.9747},{87.594,36.3195},{87.594,52.1291},{89.303,31.6193},{89.303,45.7198},{91.012,29.9102},{92.721,28.6283},{94.431,27.3464},{96.140,25.6373},{97.849,25.2100},{99.558,24.3554},{101.267,23.5008},{102.976,22.6463},{104.686,21.7917},{106.395,21.7917},{108.104,21.7917},{109.813,21.7917},{111.522,22.6463},{113.231,23.9281},{113.231,43.1561},{114.940,26.9191},{114.940,39.7378},{114.940,44.0107},{116.650,32.0466},{116.650,37.6013},{116.650,44.0107},{116.650,47.4290},{118.359,53.4110},{120.068,56.8293},{121.777,59.8203},{123.486,61.5295},{125.195,63.2386},{126.905,64.0932},{128.614,65.3751},{130.323,67.0842},{132.032,67.0842},{133.741,67.0842},{135.450,67.0842},{137.159,67.9388},{138.869,67.9388},{140.578,67.9388},{142.287,68.7934},{143.996,68.7934},{145.705,69.6479},{147.414,68.3661},{149.124,67.9388},{150.833,68.7934},{152.542,68.7934},{154.251,68.7934},{155.960,68.7934},{157.669,68.7934},{159.378,68.3661},{161.088,67.9388},{162.797,67.9388},{164.506,67.9388},{166.215,67.9388},{167.924,67.5115},{169.633,66.6569},{171.342,66.2296},{173.052,65.3751},{174.761,64.9478},{176.470,64.0932},{178.179,62.3840},{179.888,61.1022},{181.597,59.8203},{183.307,58.1112},{185.016,55.9747},{186.725,52.5564},{188.434,36.3195},{190.143,31.1920},{191.852,29.9102},{193.561,26.9191},{195.271,24.7827},{196.980,23.0736},{198.689,21.7917},{200.398,20.9371},{202.107,20.0825},{203.816,20.0825},{205.526,21.7917}}
cserei[3]={{0.427,65.8024},{2.136,64.0932},{3.846,62.8113},{5.555,61.9568},{7.264,61.5295},{8.973,60.2476},{10.682,60.2476},{12.391,62.8113},{14.101,65.3751},{15.810,69.6479},{17.519,73.0662},{17.519,77.3391},{19.228,85.4576},{20.937,91.4396},{22.646,94.8579},{24.355,96.5671},{26.065,97.8490},{27.774,98.7035},{29.483,99.5581},{31.192,100.4127},{32.901,100.8400},{34.610,101.6945},{36.319,102.5491},{38.029,102.9764},{39.738,102.9764},{41.447,103.4037},{43.156,103.8310},{44.865,105.1128},{46.574,105.5401},{48.284,105.5401},{49.993,104.6856},{51.702,105.5401},{53.411,105.5401},{55.120,105.9674},{56.829,105.5401},{58.538,105.5401},{60.248,105.5401},{61.957,105.5401},{63.666,105.5401},{65.375,105.5401},{67.084,105.1128},{68.793,104.6856},{70.503,104.2583},{72.212,103.8310},{73.921,103.8310},{75.630,103.8310},{77.339,103.4037},{79.048,102.5491},{80.757,101.6945},{82.467,101.2673},{84.176,99.9854},{85.885,97.4217},{87.594,95.7125},{89.303,93.5761},{91.012,87.1668},{91.012,91.0123},{92.721,79.0483},{94.431,74.3481},{96.140,73.4935},{97.849,71.7844},{99.558,70.9298},{101.267,69.2207},{102.976,68.3661},{104.686,66.6569},{106.395,65.3751},{108.104,64.0932},{109.813,63.6659},{111.522,62.8113},{113.231,62.3840},{114.940,61.9568},{116.650,61.9568},{118.359,62.8113},{120.068,63.2386},{121.777,64.9478},{123.486,66.6569},{125.195,68.3661},{126.905,69.2207},{128.614,70.9298},{130.323,72.6390},{132.032,74.7754},{133.741,76.0573},{135.450,77.3391},{137.159,77.7664},{138.869,80.3301},{140.578,85.0303},{142.287,93.1488},{143.996,97.4217},{145.705,99.1308},{147.414,101.2673},{149.124,102.9764},{150.833,103.8310},{152.542,104.2583},{154.251,105.1128},{155.960,105.9674},{157.669,106.8220},{159.378,107.6766},{161.088,108.1039},{162.797,108.5312},{164.506,108.9584},{166.215,109.3857},{167.924,109.8130},{169.633,109.8130},{171.342,109.8130},{173.052,110.2403},{174.761,110.6676},{176.470,111.0949},{178.179,111.0949},{179.888,111.5222},{181.597,111.5222},{183.307,110.6676},{185.016,110.6676},{186.725,110.6676},{188.434,111.5222},{190.143,111.0949},{191.852,110.6676},{193.561,109.8130},{195.271,109.8130},{196.980,109.3857},{198.689,108.9584},{200.398,108.1039},{202.107,106.8220},{203.816,106.3947},{205.526,105.1128},{207.235,104.2583},{208.944,101.6945},{210.653,99.1308},{212.362,96.9944},{214.071,75.2027},{214.071,82.4666},{214.071,91.8669},{215.780,72.6390},{217.490,71.7844},{219.199,69.6479},{220.908,68.3661},{222.617,67.0842},{224.326,65.8024},{226.035,63.6659},{227.745,62.3840},{229.454,61.5295},{231.163,59.8203},{232.872,58.5385},{234.581,57.2566},{236.290,56.4020},{237.999,54.6929},{239.709,52.9837},{241.418,52.1291},{243.127,51.7018},{244.836,52.9837},{246.545,53.8383},{248.254,54.6929},{249.963,55.9747},{251.673,56.4020},{253.382,56.8293}}
cserei[4]={{0.427,14.955},{2.136,14.955},{3.846,14.955},{5.555,14.101},{7.264,14.101},{8.973,14.101},{10.682,14.101},{12.391,14.955},{14.101,18.373},{15.810,21.792},{17.519,23.501},{19.228,24.783},{20.937,27.346},{22.646,28.201},{24.355,29.910},{26.065,31.619},{27.774,34.183},{29.483,35.038},{31.192,36.319},{31.192,51.702},{32.901,36.319},{32.901,48.711},{32.901,55.975},{34.610,38.456},{34.610,45.293},{34.610,62.811},{36.319,72.212},{38.029,76.485},{39.738,79.476},{41.447,82.039},{43.156,84.176},{44.865,85.458},{46.574,85.885},{48.284,88.021},{49.993,88.876},{51.702,89.730},{53.411,90.585},{55.120,91.867},{56.829,92.721},{58.538,93.149},{60.248,94.003},{61.957,95.285},{63.666,96.140},{65.375,97.422},{67.084,98.276},{68.793,98.704},{70.503,98.704},{72.212,98.704},{73.921,99.558},{75.630,99.985},{77.339,99.985},{79.048,100.413},{80.757,100.413},{82.467,100.413},{84.176,100.840},{85.885,101.267},{87.594,101.695},{89.303,102.976},{91.012,102.976},{92.721,102.976},{94.431,102.976},{96.140,102.549},{97.849,99.985},{99.558,97.422},{101.267,95.285},{102.976,93.576},{104.686,92.294},{106.395,89.730},{108.104,86.739},{109.813,80.330},{111.522,78.621},{113.231,77.339},{114.940,76.057},{116.650,74.775},{118.359,73.921},{120.068,73.066},{121.777,73.066},{123.486,72.639},{125.195,72.212},{126.905,71.784},{128.614,70.930},{130.323,70.075},{132.032,68.793},{133.741,67.939},{135.450,67.512},{137.159,66.657},{138.869,66.230},{140.578,64.948},{142.287,64.093},{143.996,63.666},{145.705,63.239},{147.414,62.384},{149.124,61.529},{150.833,61.102},{152.542,61.102},{154.251,59.393},{155.960,58.538},{157.669,58.538},{159.378,57.257},{161.088,56.402},{162.797,55.975},{164.506,55.120},{166.215,55.120},{167.924,54.693},{169.633,53.411},{171.342,53.411},{173.052,52.556},{174.761,51.275},{176.470,50.847},{178.179,51.702},{179.888,51.702},{181.597,52.556},{183.307,53.411},{185.016,55.120},{186.725,56.402},{188.434,57.257},{190.143,58.966},{191.852,61.529},{193.561,62.384},{195.271,64.948},{196.980,68.366},{198.689,71.357},{200.398,72.212},{202.107,73.494},{203.816,74.775},{205.526,78.194},{207.235,80.757},{208.944,82.894},{210.653,84.603},{212.362,87.167},{214.071,89.303},{215.780,100.413},{217.490,113.231},{219.199,116.650},{220.908,117.931},{222.617,120.068},{224.326,121.350},{226.035,123.059},{227.745,124.768},{229.454,125.195},{231.163,125.195},{232.872,126.477},{234.581,127.332},{236.290,127.759},{237.999,128.614},{239.709,128.614},{241.418,128.614},{243.127,129.041},{244.836,129.468},{246.545,129.468},{248.254,129.468},{249.963,130.323},{251.673,130.323},{253.382,130.323},{255.091,130.323},{256.800,129.896},{258.509,129.896},{260.218,130.323},{261.928,130.750},{263.637,131.605},{265.346,132.887},{267.055,135.023},{268.764,138.014},{270.473,138.869},{272.182,138.869},{273.892,138.869},{275.601,139.296},{277.310,138.869},{279.019,138.441},{280.728,135.878},{282.437,119.641},{282.437,133.314},{284.147,116.222},{284.147,123.059},{284.147,130.323},{285.856,114.086},{287.565,109.813},{289.274,104.686},{290.983,98.276},{292.692,96.994},{294.401,93.576},{296.111,91.440},{297.820,90.585},{299.529,88.876},{301.238,87.594},{302.947,85.458},{304.656,85.030},{306.366,83.748},{308.075,81.185},{309.784,79.903},{311.493,77.766},{313.202,76.057},{314.911,73.921},{316.620,72.212},{318.330,71.784},{320.039,70.075},{321.748,68.793},{323.457,67.512},{325.166,66.230},{326.875,64.093},{328.584,62.811},{330.294,60.248},{332.003,58.966},{333.712,58.538},{335.421,55.975},{337.130,54.693},{338.839,52.984},{340.549,51.275},{342.258,49.993},{343.967,49.138},{345.676,47.856},{347.385,46.147},{349.094,45.720},{350.803,45.720},{352.513,44.865},{354.222,44.865},{355.931,44.865}}

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