Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

curve fitting with nlinfit and multiple parameters

190 views
Skip to first unread message

H.M. Barker

unread,
Apr 29, 2004, 9:57:48 PM4/29/04
to
I'm trying to implement the nlinfit function to do a curve fitting
task. I'm a bit confused about how each parameter works, and would
appreciate some clearing up of ideas.

I have an equation with five coefficients I am trying to extract from
the data. My experimental data consists of a vector of independent
variables (plotted on the x-axis when plotting the data), and a matrix
of size 27x6, with each column being the results of running the
experiment with a different experimental variable (not related to the
independent variables listed above). I'm assuming the dependent
variables go into "X" in the nlinfit function, and the experimental
data in "y", but I'm not sure how this works with multiple unknowns.
Where do the coefficients fit in? Any guidance is appreciated.

For reference:

beta = nlinfit(X,y,FUN,beta0)
yhat = myfun(beta,X)

Thank you.

Peter Spellucci

unread,
Apr 30, 2004, 6:22:26 AM4/30/04
to

In article <fa3248bd.04042...@posting.google.com>,

you have to use 6 different fits, since each experiment is done with changing
some additional external parameter, hence it makes no sense to fit
all the data with one model.
beta=zeros(5,6);
for i=1:6
yy=y(:,i);
betai = nlinfit(X,yy,FUN,beta0);
yhat = myfun(betai,X) ;
beta(:,i)=betai;
end

hth
peter

H.M. Barker

unread,
Apr 30, 2004, 1:26:25 PM4/30/04
to
Perhaps I should clarify. Doesn't one need six inputs to get out six
parameters?
X is a 27 x 1 vector; Y is a 27x6 column. In the following code, Y is
assuming I've chosen out one column of the original Y. w_1 is not
necessarily an "additional extermal parameter", as seen below in
"M_a".

Here is the code I'm using:

beta = zeros(6,1);
beta = nlinfit(X,Y, @h2, beta0);

function M_a = h2(beta, X)
w_1 = 0.17;
b1 = beta(1);
b2 = beta(2);
b3 = beta(3);
b4 = beta(4);
b5 = beta(5);
b6 = (w_1^2)*b2/(1+(2*pi.*X*b2))

M_a = ((b1*b4)+b6+b1+b3)/(b4*(b1+b6)+(1+((w_1/2*pi.*X).^2)*b5)*(b1+b3+b6));

When I run the code I get errors about matrix size and whatnot, which
doesn't allow me to make sure the entire code runs correctly. Am I
misunderstanding the syntax of the code?

Thank you.


nospams...@fb04373.mathematik.tu-darmstadt.de (Peter Spellucci) wrote in message news:<c6t9d2$nn0$1...@fb04373.mathematik.tu-darmstadt.de>...

Peter Perkins

unread,
Apr 30, 2004, 3:42:45 PM4/30/04
to
> X is a 27 x 1 vector; Y is a 27x6 column. In the following code, Y is

> beta = zeros(6,1);


> beta = nlinfit(X,Y, @h2, beta0);
>
> function M_a = h2(beta, X)
> w_1 = 0.17;
> b1 = beta(1);
> b2 = beta(2);
> b3 = beta(3);
> b4 = beta(4);
> b5 = beta(5);
> b6 = (w_1^2)*b2/(1+(2*pi.*X*b2))
>
> M_a = ((b1*b4)+b6+b1+b3)/(b4*(b1+b6)+(1+((w_1/2*pi.*X).^2)*b5)*(b1+b3+b6));
>
> When I run the code I get errors about matrix size and whatnot, which
> doesn't allow me to make sure the entire code runs correctly. Am I
> misunderstanding the syntax of the code?

Hi -

Presumably, you have six different runs with six different values of w_1, and
that's why your original Y matrix has six columns. Do you want to estimate
six different sets of parameters b1 through b5, one set for each run? It
would also be possible to combine all the data into a single vector, use the
various values of w_1 as another column of the X matrix, and make a single
estimate of beta. I can't tell what you are trying to do.

h2 should take a vector that is as long as the number of parameters you are
estimating. That would seem to be five, not six, as b6 is a function of b2
and some constants. Actually, the calculation of b6 seems to not make sense,
as you have a slash operator (do you mean "./"?) with a column vector. Also,
the computation of M_a seems to have the same problem. It also would seem to
have some problems with parameter identifiability: for example, b1 and b6
only ever appear as (b1+b6). It will not be possible to estimate them
separately. There may be other similar issues.

The model function should take a vector of current parameter values, and a
matrix (which, as in your case, may only have one column). It should return
something that is that same size as whatever your y vector is. Your h2
function appears not to do that. Take a look at the HOUGEN function (type
"type hougen") and the example for NLINFIT (type "help nlinfit").

0 new messages