ClearAll;
$DefaultFont = {"Times-Roman",10};
Needs["Statistics`DataManipulation`"];
Needs["Graphics`Graphics`"];
npoints = 5;

cumprob = {1,23,75,142,256,513,690,731,733}/733;
sizes = Table[3k,{k,1,9}];
datapoints = Map[Thread,Transpose[{sizes,cumprob}]];
scale = cumprob[[npoints]];
cumscaled = cumprob/scale;
datapointscond = Map[Thread,Transpose[{sizes,cumscaled}]];

n = 5;
F[a_,x_]:= 1 - E^(-(a x)^n);
f[a_,x_]:= n a (a x)^(n-1) E^(-(a x)^n);

err[a_] = N[Apply[Plus,Table[(F[a,sizes[[k]]]-cumprob[[k]])^2,{k,1,9}]]];
Plot[err[a],{a,0.05,0.07}]
leasterr = FindMinimum[err[a],{a,0.06,0.05,0.07}];
aopt = a/.leasterr[[2]]
Print["Error is ",leasterr[[1]]]

left = Plot[f[aopt,x],{x,0,15}];
right = Plot[f[aopt,x],{x,15,27},PlotStyle->Dashing[{0.01,0.01}]];
both = {left, right};
plot =  Show[both, PlotRange->{{0,27},Automatic},
			PlotLabel->"Probability density function of size above base length in minnows",
			Axes->True,AxesLabel->{" x","y"},
			AxesOrigin->{-1,-0.004}];		
					
Show[GraphicsArray[{plot}],PlotLabel->"Figure 10.1"]