Code:

import com.imsl.stat.*;
public class ForumNLR {
public static void main(String args[])
throws NonlinearRegression.TooManyIteration***ception,
NonlinearRegression.NegativeFreqException,
NonlinearRegression.NegativeWeightException {
NonlinearRegression.Function f = new NonlinearRegression.Function() {
public boolean f(double theta[], int iobs, double frq[], double wt[], double e[]) {
double xdata[] = {0.048,0.091,0.091,0.091,0.082,0.13,0.138,0.176,0.214,0.226,
0.269,0.294,0.327,0.371,0.417,0.454,0.493,0.558,0.606,0.656,0.701,0.765,
0.814,0.879,0.93,0.991,1.073,1.13,1.194,1.279};
double ydata[] = {0.6,0.8,0.8,0.8,1,1.2,1.4,1.6,1.8,2,2.2,2.4,2.6,2.8,3,3.2,
3.4,3.6,3.8,4,4.2,4.4,4.6,4.8,5,5.2,5.4,5.6,5.8,6};
boolean iend;
int nobs = 30;
if(iobs < nobs){
wt[0] = 1.0;
frq[0] = 1.0;
iend = true;
e[0] = ydata[iobs]
- theta[0] * Math.log(theta[1] + xdata[iobs])
- theta[2] * xdata[iobs]
- theta[3] * Math.sqrt(xdata[iobs]);
} else {
iend = false;
}
return iend;
}
};
int nparm = 4;
double theta[] = {1, 1, 1, 1};
NonlinearRegression regression = new NonlinearRegression(nparm);
regression.setGuess(theta);
double coef[] = regression.solve(f);
System.out.println("The computed regression coefficients are:");
for (int i=0; i<coef.length; i++) {
System.out.println("\t" + coef[i]);
}
double sse = regression.getSSE();
System.out.println("The sums of squares for error is " + sse);
}
}