/* Example of the use of the class Regression demonstrating the use of the non-linear regression method, Regression.simplexPlot in fitting data to the function, y = a + b.exp(-c.x) + g^z with b fixed and a,c and g unknown Michael Thomas Flanagan http://www.ee.ucl.ac.uk/~mflanaga/java/Regression.html April 2007 Copyright (c) 2007 - 2014 * PERMISSION TO COPY: * Permission to use, copy and modify this software and its documentation for * NON-COMMERCIAL purposes is granted, without fee, provided that an acknowledgement * to the author, Dr Michael Thomas Flanagan at www.ee.ucl.ac.uk/~mflanaga, * appears in all copies and associated documentation or publications. * * Public listing of the source codes on the internet is not permitted. * * Redistribution of the source codes or of the flanagan.jar file is not permitted. * * Redistribution in binary form of all or parts of these classes is not permitted. * * Dr Michael Thomas Flanagan makes no representations about the suitability * or fitness of the software for any or for a particular purpose. * Dr Michael Thomas Flanagan shall not be liable for any damages suffered * as a result of using, modifying or distributing this software or its derivatives. * ***************************************************************************************/ import flanagan.analysis.Regression; import flanagan.analysis.RegressionFunction; // Class to evaluate the function y = a + b.exp(-c.x) + f^z class FunctTwo implements RegressionFunction{ private double b = 0.0D; public double function(double[ ] p, double[ ] x){ double y = p[0] + b*Math.exp(-p[1]*x[0]) + Math.pow(p[2], x[1]); return y; } public void setB(double b){ this.b = b; } } // Class to demonstrate non-linear regression method, Regression.simplex. public class RegressionExampleTwo{ public static void main(String[] arg){ // x1 data array double[] xArray = {0.0,0.5,1.0,1.5,2.0,2.5,3.0,3.5,4.0,4.5,5.0,5.5,6.0,6.5,7.0,7.5}; // x2 data array double[] zArray = {0.0,0.13,0.26,0.39,0.52,0.65,0.78,0.91,1.04,1.17,1.3,1.43,1.56,1.69,1.82,1.95}; // observed y data array double[] yArray = {12.1379,10.1886,8.9674,7.7824,7.9645,7.3671,6.8216,7.2602,7.1105,7.2873,7.9745,8.5188,9.1492,9.3891,10.4923,11.8675}; // estimates of the standard deviations of y double[] sdArray = {0.25,0.22,0.27,0.23,0.21,0.26,0.28,0.24,0.25,0.23,0.27,0.22,0.23,0.26,0.28,0.24}; // combine x and z data into common array int arrayLen = xArray.length; double[][] doubleArray = new double[2][arrayLen]; for(int i=0; i