From: ImageAnalyst on
Well never mind then - you're better off using nlfit anyway.
From: ImageAnalyst on
And that trick I was thinking of wouldn't work in this case anyway now
that I think about it - sorry.
From: Wayne King on
"strat " <e-goum(a)hotmail.com> wrote in message <hsos0s$b4d$1(a)fred.mathworks.com>...
> > Hi Stratos, I'm trying to understand your model f=c+a*x1^a1+b*x2^a2. Specifically, are a1 and a2 parameters of your model or just known powers that the predictor variables are being raised to? If they are just powers like:
> > f=c+a*x1^2+b*x2^3
> >
> > and your parameters are [c,a,b] then you still have a regression model that is linear in the parameters. You can just construct your design matrix with the 2nd and 3rd columns as x1^2 and x2^3.
> >
> > Or is it the case that a1 and a2 are parameters that you are trying to estimate?
> >
> > If you really need to fit a nonlinear model, what do you mean by you've seen nlinfit, but that you "haven't made it." Are you having trouble with the concept of a function handle as an input?
> >--------------------------------------------------------------------
>
> Hi, I am trying to estimate a model that fits the best in data so i have to estimate the coefficients c,a,b,a1,a2 of the model f=c+a*x1^a1+b*x2^a2. They are not known.
> Nlinfit has a parameter called 'fun'. Here you type a function. I have read a matlab example that uses the hugen function but i can't understand how it works.
> What i need is to estimate the coefficients of that model f=c+a*x1^a1+b*x2^a2. I have made it with the linear f=c+a*x1+b*x2, but i want to see also the nonlinear.

Hi Stratos, That input argument is a function handle. What you can do is to define your model in a MATLAB function, something like:

function yhat = mynlinfunc(beta,X)

beta0 = beta(1);
beta1 = beta(2);
beta2 = beta(3);
beta3 = beta(4);
beta4 = beta(5);

yhat = beta0+beta1*X(:,1).^beta2+beta3*X(:,2).^beta4;

Make sure that function is in your MATLAB path. Then, you can call nlinfit with

BetaHat = nlinfit(X,y,@mynlinfunc,Initbeta);

where Initbeta is the 5 element vector containing your initial guess for your parameters. X is your data matrix (you have two predictor variables), and y is the response vector. Of course, you may want to make use of the statistics options available in nlinfit. See the documentation for an explanation.

Hope that helps,
Wayne
From: strat on
> Hi Stratos, That input argument is a function handle. What you can do is to define your model in a MATLAB function, something like:
>
> function yhat = mynlinfunc(beta,X)
>
> beta0 = beta(1);
> beta1 = beta(2);
> beta2 = beta(3);
> beta3 = beta(4);
> beta4 = beta(5);
>
> yhat = beta0+beta1*X(:,1).^beta2+beta3*X(:,2).^beta4;
>
> Make sure that function is in your MATLAB path. Then, you can call nlinfit with
>
> BetaHat = nlinfit(X,y,@mynlinfunc,Initbeta);
>
> where Initbeta is the 5 element vector containing your initial guess for your parameters. X is your data matrix (you have two predictor variables), and y is the response vector. Of course, you may want to make use of the statistics options available in nlinfit. See the documentation for an explanation.
>
> Hope that helps,
> Wayne

------------------------------------------------------------

It seems i am doing something wrong. I have 3 variables:
Name of variables:
y--> vector 50x1
x1--> vector 50x1
x2--> vector 50x1
----
X--> design matrix 50x2 (x1,x2 variables)
bInt--> vector 5x1 (initial values) (1 1 1 1 1)

i wrote the above code you sent me to an M-file and i got some errors when i run it:
CODE:
function yhat = mynlinfunc(beta,X)
beta0 = beta(1);
beta1 = beta(2);
beta2 = beta(3);
beta3 = beta(4);
beta4 = beta(5);
yhat = beta0+beta1*X(:,1).^beta2+beta3*X(:,2).^beta4;
BetaHat = nlinfit(X,y,@mynlinfunc,bInt);
''Input argument "beta" is undefined. Error in ==> mynlinfunc at 2 beta0 = beta(1);''
From: Wayne King on
"strat " <e-goum(a)hotmail.com> wrote in message <hstgcc$r9o$1(a)fred.mathworks.com>...
> > Hi Stratos, That input argument is a function handle. What you can do is to define your model in a MATLAB function, something like:
> >
> > function yhat = mynlinfunc(beta,X)
> >
> > beta0 = beta(1);
> > beta1 = beta(2);
> > beta2 = beta(3);
> > beta3 = beta(4);
> > beta4 = beta(5);
> >
> > yhat = beta0+beta1*X(:,1).^beta2+beta3*X(:,2).^beta4;
> >
> > Make sure that function is in your MATLAB path. Then, you can call nlinfit with
> >
> > BetaHat = nlinfit(X,y,@mynlinfunc,Initbeta);
> >
> > where Initbeta is the 5 element vector containing your initial guess for your parameters. X is your data matrix (you have two predictor variables), and y is the response vector. Of course, you may want to make use of the statistics options available in nlinfit. See the documentation for an explanation.
> >
> > Hope that helps,
> > Wayne
>
> ------------------------------------------------------------
>
> It seems i am doing something wrong. I have 3 variables:
> Name of variables:
> y--> vector 50x1
> x1--> vector 50x1
> x2--> vector 50x1
> ----
> X--> design matrix 50x2 (x1,x2 variables)
> bInt--> vector 5x1 (initial values) (1 1 1 1 1)
>
> i wrote the above code you sent me to an M-file and i got some errors when i run it:
> CODE:
> function yhat = mynlinfunc(beta,X)
> beta0 = beta(1);
> beta1 = beta(2);
> beta2 = beta(3);
> beta3 = beta(4);
> beta4 = beta(5);
> yhat = beta0+beta1*X(:,1).^beta2+beta3*X(:,2).^beta4;
> BetaHat = nlinfit(X,y,@mynlinfunc,bInt);
> ''Input argument "beta" is undefined. Error in ==> mynlinfunc at 2 beta0 = beta(1);''

Hi Stratos, if you do the following what happens:

bInt = ones(5,1);
% and assuming your design matrix is in the workspace
mymodel = @mynlinfunc;
test = mymodel(bInt,X);

Wayne