Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Nbm Reg Sim Nonlinearwith-١

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

nbm_reg_sim_nonlinearwith.

nb 1

Nonlinear Regression with Data


Linearization
Fabian Farelo, Autar Kaw, Jamie Trahan
University of South Florida
United States of America
kaw@eng.usf.edu
ClearAll;

Introduction

This 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 data.

Exponential: y = aebx
Power: y = axb
ax
Saturation: y = ÅÅÅÅ
ÅÅÅÅÅÅ
b+x

a and b are the constants of the regression model.

To learn more about Nonlinear Regression with data linearization, see the Nonlinear Regression worksheet.

Section 1: Input Data

Below are the input parameters to begin the simulation. This is the only section that requires user input. The user can
change the values below and Mathematica will calculate the nonlinear regression model using data linearization for the
corresponding model that the user chooses.

Input Parameters:
nbm_reg_sim_nonlinearwith.nb 2

è Number of data points, n

n=5

è Array of x values, x

x = 810, 16, 25, 40, 60<

810, 16, 25, 40, 60<

è Array of y values, y

y = 894, 118, 147, 180, 230<

894, 118, 147, 180, 230<

è 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"

modeltype = "exponential"

exponential

Section 2: Nonlinear Model with Data Linearization Procedures

The 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) + bln(x) (taking the natural log of both sides) (2.2)
1 b 1 1
Growth: ÅÅÅÅy = ÅÅÅÅa ÅÅÅÅx + ÅÅÅÅ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 modeltype variable, the proper procedure will calculate the coefficients for that model using data linearization.
Note: See Nonlinear Regression notes for explanation of the model.
nbm_reg_sim_nonlinearwith.nb 3

ü Exponential model procedure:

After data linearization, the following substitutions are made to Equation 2.1
let 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 + a1 x (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 .

Off@General::spellD

z = Array@0, 81, n<D; sumz = 0; sumx = 0; sumxz = 0; sumxx = 0;


ExponentialModel@x_, y_, n_D := ModuleA8z, sumz, sumx, sumxz, sumxx, a1, a0<,

For@i = 1, i ≤ n, i ++, z@@1, iDD = N@Log@y@@iDDDD;


sumz = sumz + z@@1, iDD;
sumx = sumx + x@@iDD;
sumxz = sumxz + x@@iDD ∗ z@@1, iDD;
sumxx = sumxx + Hx@@iDDL ^ 2;D;
E;
n ∗ sumxz − sumx ∗ sumz
Hn ∗ sumxxL − sumx^ 2
a1 = NA

E;
sumz sumx
a0 = NA − a1 ∗
n n
a = E ^ a0;
b = a1;
a; bE;

ü Power model procedure:

After data linearization, the following substitutions are made to Equation 2.2
let z = ln(y)
w = ln(x)
a0 = lnHaL, implying a = ea0
a1 = b
The data z versus w now takes the form of a linear model:

z = a0 + a1 w (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 originial constants of the power model, a and b, where y = axb .
nbm_reg_sim_nonlinearwith.nb 4

z = Array@0, 81, n<D; w = Array@0, 81, n<D; sumz = 0; sumw = 0; sumwz = 0; sumww = 0;
PowerModel@x_, y_, n_D := ModuleA8z, w, sumz, sumw, sumwz, sumww<,

For@i = 1, i ≤ n, i ++, z@@1, iDD = N@Log@y@@iDDDD;


w@@1, iDD = N@Log@x@@iDDDD;
sumw = sumw + w@@1, iDD;
sumz = sumz + z@@1, iDD;
sumwz = sumwz + w@@1, iDD ∗ z@@1, iDD;
sumww = sumww + Hw@@1, iDDL ^ 2;D;
E;
n ∗ sumwz − sumw ∗ sumz
a1 = NA
n ∗ sumww − sumw^ 2
E;
sumz sumw
a0 = NA − a1 ∗
n n
a = E ^ a0;
b = a1E ;

ü Saturation Growth model procedure:

After data linearization, the following substitutions are made to Equation 2.3
let z = 1/y

a0 = 1 ê a, implying a = 1 ê a0
q = 1/x

a1 = b/a, implying b = a1 ê a0
The data z versus q now takes the form of a linear model:

z = a0 + a1 q (2.6)

In the saturation growth model procedure, least squares linear regression method is used to solve for the a0 and a1 coeffi-
ax
cients which are then used to determine the original constants of the growth model, a and b, where y = ÅÅÅÅ
ÅÅÅÅÅÅ .
b+x

z = Array@0, 81, n<D; q = Array@0, 81, n<D; sumq = 0; sumz = 0; sumqz = 0; sumqq = 0;
GrowthModel@x_, y_, n_D := ModuleA8z, q, sumq, sumz, sumqz, sumqq, a1, a0<,

For@i = 1, i ≤ n, i ++, z@@1, iDD = N@1 ê y@@iDDD;


q@@1, iDD = N@1 ê x@@iDDD;
sumq = sumq + q@@1, iDD;
sumz = sumz + z@@1, iDD;
sumqz = sumqz + q@@1, iDD ∗ z@@1, iDD;
sumqq = sumqq + Hq@@1, iDDL ^ 2;D;
E;
n ∗ sumqz − sumq ∗ sumz
a1 = NA
n ∗ sumqq − sumq ^ 2
E;
sumz sumq
a0 = NA − a1 ∗
a = N@1 ê a0D;
n n

b = N@a1 ê a0D;E;
nbm_reg_sim_nonlinearwith.nb 5

Section 3: Finding the constants of the model

The proper regression model is assigned below, returning the constants of the model that was chosen with the modeltype
variable.

If@modeltype == "exponential", ExponentialModel@x, y, nD; f@x_D := N@a ∗ E ^ Hb ∗ xLDD;


If@modeltype == "power", PowerModel@x, y, nD; f@x_D := a ∗ x ^ bD;
If@modeltype == "growth", GrowthModel@x, y, nD; f@x_D := Ha ∗ xL ê Hb + xLD;
Print@"The constants of the ", modeltype, " model are a = ", a, " and b = ", bD

The constants of the exponential model are a = 87.8045 and b = 0.0169529

Below, the nonlinear model is plotted versus the data set.

Datatable = Table@8x@@iDD, y@@iDD<, 8i, 1, n<D;


title = Print@modeltype, " Regression Model, y vs x"D;
points = ListPlot@Datatable, PlotStyle → PointSize@0.02D, DisplayFunction → IdentityD;
lin = Plot@f@XD, 8X, Min@xD, Max@xD<, DisplayFunction → IdentityD;
Show@points, lin, DisplayFunction → $DisplayFunctionD;

exponential Regression Model, y vs x

240

220

200

180

160

140

120

100
10 20 30 40 50 60
nbm_reg_sim_nonlinearwith.nb 6

Conclusion

Mathematica helped us apply our knowledge of linear regression method 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 + at

time HtL, Month


where q is the rate of production and t is the time, b and a are the constants of the regression model.

Rate of Production HqL,


1 5 11 16 18
258 185 109 84 71
Barrels per Day

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 aban-
doned for further production.
c) What does b stand for?

Question 2: It is desired to obtain a functional relationship between the mass density ρ of air and the altitude h above the
sea level for the dynamic analysis of bodies moving within earth's atmosphere. Use the approximation ρ = k1 e-k2 h to fit
the data given below by regression analysis. Find the constants k1 and k2. You are allowed to linearize the data.

HkilometersL Hkg ê m3 L
Altitude Mass Density

0.32 1.15
0.64 1.10
1.28 1.05
1.60 0.95

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.

Flow rate Hgallons ê minL F 94 118 147 180 230


Pressure HpsiL p 10 16 25 40 60
nbm_reg_sim_nonlinearwith.nb 7

References

[1] Autar Kaw, Holistic Numerical Methods Institute, http://numericalmethods.eng.usf.edu/nbm, See


How does Nonlinear Regression work?

You might also like