Nonlinear Regression with Data Linearization\302\251 2007 Fabian Farelo, Autar Kaw, Jamie TrahanUniversity of South FloridaUnited States of Americakaw@eng.usf.eduNote: This worksheet demonstrates the use of Maple to illustrate the procedure to regress a given data set to a nonlinear model with linearization of data.IntroductionThis worksheet illustrates finding the constants of nonlinear regression models with data linearization. Three common nonlinear models are illustrated - 1)Exponential 2)Power 3)Saturation Growth.Given n data points (x1,y1), (x2,y2), (x3,y3),.....,(xn,yn), best fit one of the following models to the dataExponential: y =aebx (1.1)Power: y =axb (1.2)Growth: y = ax/(b+ x) (1.3)a and b are the constants of the above regression models.JSFHJSFHSection 1: Input DataBelow are the input parameters to begin the simulation. This is the only section that requires user input. The user can change the desired nonlinear model below and Maple will calculate the nonlinear regression model using data linearization for the corresponding model that the user chooses.Input Parameters:n = Number of data points, nX = Array of x valuesY = Array of y valuesrestart;
n:=6;
X:=[0.5,1,3,5,7,9];
Y:=[1.0,0.8920,0.7080,0.5620,0.4470,0.3550];
For exponential model call model type to be "exponential"
For power model assign the model type variable as "power"
For saturation growth model, assign the model type variable to be "growth"
model_type:="growth";Section 2:Nonlinear Model with Data Linearization ProceduresThe following manipulation must first be made to each model in order to linearize the data:Exponential: ln(y) = ln(a) + bx (taking the natural log of both sides) (2.1)Power: ln(y) = ln(a) + b*ln(x) (taking the natural log of both sides) (2.2)Growth: 1/y = (b/a)*(1/x)+(1/a) (taking the reciprocal of both sides then rearranging) (2.3)Once the data is linearized, substitutions are made so as to apply a direct solution approach using least squares regression method for a straight line. In this section, a procedure is written for each model. Once a specific nonlinear model is called for with the model_type variable, the proper procedure will calculate the coefficients for that model using data linearization.Note: See nonlinear model regression notes for explanation of the model.Exponential model procedureAfter data linearization, the following substitutions are made to Equation 2.1let z = ln(y) a0 = ln(a), implying a = ea0 a1 = b
The data z versus x now takes the form of a linear model: z = a0 + a1x (2.4)In the exponential_model procedure, least squares linear regression method is used to solve for the a0 and a1 coefficients which are then used to determine the original constants of the exponential model a and b, where y = aebx .JSFHexponential_model:=proc(X,Y,n)
local f,x,y,a,b,z,i,sumz,sumx,sumxz,sumxx,a1,a0,x1,y1;
sumz:=0;
sumx:=0;
sumxz:=0;
sumxx:=0;
for i from 1 by 1 to n do
z[i]:=ln(Y[i]);
sumz:=sumz+z[i];
sumx:=sumx+X[i];
sumxz:=sumxz+X[i]*z[i];
sumxx:=sumxx+X[i]^2;
end do;
a1:=(n*sumxz-sumx*sumz)/((n*sumxx)-(sumx)^2);
a0:=(sumz/n)-a1*(sumx/n);
a:=exp(a0);
b:=a1;
return(a,b);
end proc:Power model procedureAfter data linearization, the following substitutions are made to Equation 2.2:let z = ln(y) w = ln(x) a0 = ln(a), implying a = ea0 a1 = bThe data z versus w now takes the form of a linear model: z = a0 + a1w (2.5)In the power_model procedure, least squares linear regression method is used to solve for the a0 and a1 coefficients which are then used to determine the original constants of the exponential model a and b, where y = axb .power_model:=proc(X,Y,n)
local a0,a1,sum,z,w,sumz,sumw,sumwz,sumww,a,b,i;
sumz:=0;
sumw:=0;
sumwz:=0;
sumww:=0;
for i from 1 by 1 to n do
w[i]:=evalf(ln(X[i]));
z[i]:=evalf(ln(Y[i]));
sumw:=sumw+w[i];
sumz:=sumz+z[i];
sumwz:=sumwz+w[i]*z[i];
sumww:=sumww+(w[i])^2;
end do:
a1:=(n*sumwz-(sumw*sumz))/(n*(sumww)-(sumw^2));
a0:=((sumz/n)-a1*(sumw/n));
a:=exp(a0);
b:=a1;
return(a,b);
end proc:JSFHSaturation Growth model procedureAfter data linearization, the following substitutions are made to Equation 2.3:let z = 1/y q = 1/x a0 = 1/a, implying a = 1/a0 a1 = b/a, implying b = a1/a0The data z versus q now takes the form of a linear model: z = a0 + a1 q (2.6)In the growth_model procedure, least squares linear regression method is used to solve for the a0 and a1 coefficients which are then used to determine the original constants of the exponential model a and b, where y = ax . b+xJSFHgrowth_model:=proc(X,Y,n)
local i,z,q,a0,a1,a,b,sumz,sumq,sumqq,sumqz;
sumz:=0;
sumq:=0;
sumqq:=0;
sumqz:=0;
for i from 1 by 1 to n do
z[i]:=1/Y[i];
q[i]:=1/X[i];
sumz:=sumz+z[i];
sumq:=sumq+q[i];
sumqz:=sumqz+q[i]*z[i];
sumqq:=sumqq+q[i]^2;
end do;
a1:=(n*sumqz-(sumq*sumz))/(n*(sumqq)-(sumq^2));
a0:=((sumz/n)-a1*(sumq/n));
a:=1/a0;
b:=a1/a0;
return(a,b);
end proc:JSFHSection 3: Finding the constants of the modelThe proper regression model is assigned below, returning the constants of the model that was chosen with the model_type variable.if (model_type="exponential") then
exponential_model(X,Y,n):
a,b:=exponential_model(X,Y,n):
f:=x->a*exp(b*x):
print(`The constants of the exponential model are a = `,a,` and b =`,b);
end if:
if (model_type="power") then
power_model(X,Y,n):
a,b:=power_model(X,Y,n):
f:=x->a*x^b:
print(`The constants of the power model are a = `,a,` and b =`,b);
end if:
if (model_type="growth") then
growth_model(X,Y,n):
a,b:=growth_model(X,Y,n):
f:=x->(a*x)/(b+x):
print(`The constants of the saturation growth model are a = `,a,` and b =`,b);
end if:JSFHBelow, the nonlinear model is plotted versus the data set.predicted:=f(x);
observed:=[seq([X[i],Y[i]],i=1..n)];
ttle:=cat(model_type, ` regression model with data linearization, y vs x`):
plot([predicted,observed],x=X[1]..X[n],style=[line,point],title=ttle,legend=["Nonlinear Regression model","Data Points"]);JSFHReferences[1] Autar Kaw, Holistic Numerical Methods Institute, http://numericalmethods.eng.usf.edu/mws, SeeHow does Nonlinear Regression work?JSFHConclusionMaple helped us apply our knowledge of linear regression to regress a given data set to a nonlinear model.Question 1: You are working for Valdez SpillProof Oil Company as a petroleum engineer. Your boss is asking you to estimate the future life of an oil well. The analysis used in the industry is called the decline curve analysis where the barrels of oil produced per unit time are plotted against time, and the curve is extrapolated. One of the standard curves used is harmonic decline model, that is q = b 1 + atwhere q is the rate of production and t is the time, b and a are the constants of the regression model.
a)Find the constants of the regression model. Hint: You are allowed to linearize the data if possible.b)Find the total life of an oil field if 5 barrels per day is considered the production at which the field needs to be abandoned for further production.c) What does b stand for?Question 2: . It is desired to obtain a functional relationship between the mass density \317\201 of air and the altitude h above the sea level for the dynamic analysis of bodies moving within earth's atmosphere. Use the approximation to fit the data given below by regression analysis to r = k1e-k2h. Find the constants k1 and k2. You are allowed to linearize the data.
Question 3: .It is suspected from theoretical considerations that the rate of flow from a fire hose is proportional to some power of the nozzle pressure. Determine whether the speculation is true. What is the exponent of the data. Assume pressure data is more accurate. You are allowed to linearize the data.
JSFHLegal Notice: The copyright for this application is owned by the author(s). Neither Maplesoft nor the author are responsible for any errors contained within and are not liable for any damages resulting from the use of this material. This application is intended for non-commercial, non-profit use only. Contact the author for permission if you wish to use this application in for-profit activities.