CE20230 Lecture Notes - Lecture 6: Power Law, Environmental Engineering
14 views3 pages

UNIVERSITY OF NOTRE DAME
Department of Civil and Environmental Engineering
and Earth Sciences
CE 20230 Engineering Programming
A.S. Donahue
Non–Linear Curve Fitting Info
This brief worksheet goes over the details of how we determine the non linear model using the
results of our linear fitting in Matlab. Recall that if we wish to fit a non–linear model to a set of
data our strategy is to fit a linear model to the data after it has been altered in some way, in brief
this looks like:
1. If we wish to fit a Power Law model y=bxmwe fit the following
>> r = polyfit(log(x),log(y),1)
>> y = exp(r(2))*x.^r(1)
we note that the data should look fairly linear on a log–log plot, i.e.
>> loglog(x,y)
2. If we wish to fit an Exponential model y=bemx we fit the following
>> r = polyfit(x,log(y),1)
>> y = exp(r(2))*exp(r(1)*x)
we note that the data should look fairly linear on a semilog–y plot, i.e.
>> semilogy(x,y)
3. If we wish to fit a Logarithmic model y=m∗ln(x) + bwe fit the following
>> r = polyfit(log(x),y,1)
>> y = r(1)*log(x)+r(2)
we note that the data should look fairly linear on a semilog–x plot, i.e.
>> semilogx(x,y)
4. If we wish to fit a Reciprocal model y=1
mx +bwe fit the following
>> r = polyfit(x,1./y,1)
>> y = 1./(r(1)*x+r(2))
we note that the data should look fairly linear on a reciprocal rectilinear plot, i.e.
>> plot(x,1./y)
Note that for plotting we don’t alter the data, we just use a different plot command. Its only
when using polyfit that we alter the data.
1