Geoscience Reference
In-Depth Information
models to the data. An easy-to-use routine to i t such models is nonlinear
regression using the function nlinfit . To demonstrate the use of nlinfit we
generate a bivariate data set where one variable is exponentially correlated
with a second variable. We i rst generate evenly-spaced values between
0.3 and 3 at intervals of 0.1 and add some Gaussian noise with a standard
deviation of 0.2 to make the data unevenly spaced. h e resulting 26 data
points are stored in the i rst column of the variable data .
clear
rng(0)
data(:,1) = 0.3 : 0.1 : 3;
data(:,1) = data(:,1) + 0.2*randn(size(data(:,1)));
We can then compute the second variable, which is the exponent of the i rst
variable multiplied by 0.2 and increased by 3. We again add Gaussian noise,
this time with a standard deviation of 0.5, to the data. Finally, we can sort the
data with respect to the i rst column and display the result.
data(:,2) = 3 + 0.2 * exp(data(:,1));
data(:,2) = data(:,2) + 0.5*randn(size(data(:,2)));
data = sortrows(data,1);
plot(data(:,1),data(:,2),'o')
xlabel('x-Axis'), ylabel('y-Axis')
Nonlinear regression aims to estimate the two coei cients of the exponential
function, i.e., the multiplier 0.2 and the summand 3. h e function
p=nlinfit(data(:,1),data(:,2),fun,p0) returns a vector p of coei cient
estimates for a nonlinear regression of the responses in data(:,2) to the
predictors in data(:,1) using the model specii ed by fun . Here, fun is a
function handle to a function of the form hat=modelfun(b,X) , where b is a
coei cient vector. A function handle is passed in an argument list to other
functions, which can then execute the function using the handle. A function
handle uses the at sign, @ , before the function name. h e variable p0 is a
vector containing initial values for the coei cients and is the same length
as p . We can design a function handle model representing an exponential
function with an input variable t and the coei cients phi . h e initial values
of p are [0 0] . We can then use nlinfit to estimate the coei cients p using the
data data , the model model , and the initial values p0 .
model = @(phi,t)(phi(1)*exp(t) + phi(2));
p0 = [0 0];
p = nlinfit(data(:,1),data(:,2),model,p0)
p =
0.2121 2.8306
Search WWH ::




Custom Search