When I try to run the script ,many errors prevent the running.Is this script correct for running?
No, you need to be using .* to do your vectorized multiplications. Also, you have many rows where x(:,2)=0 which cannot possibly agree with your model, and causes all kinds of NaNs to be generated during the iterative search.
Also, are the coefficients all supposed to be non-negative? If so, nlinfit will not let you apply positivity constraints. I would recommend lsqcurvefit instead,
load xyData
keep=all(x>0,2);
x=x(keep,:); y=y(keep);
X=log(x); Y=log(y);
e=ones(size(Y));
c0=[e,X]\Y; c0(1)=exp(c0(1));
f=@(c,x) c(1)*(x(:,1).^c(2)).*(x(:,2).^c(3)).*(x(:,3).^c(4));
[Beta,~,resid]=lsqcurvefit(f,c0,x,y);
I assume Alex did something similar, since the result I get from this is very close to his,
>> c0.',Beta.'
ans =
0.6438 0.7292 -0.2038 -0.4317
ans =
0.2564 0.7363 0.0000 -0.4029
5 Comments
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/578550-non-linear-fitting-for-more-than-three-variables#comment_970515
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/578550-non-linear-fitting-for-more-than-three-variables#comment_970515
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/578550-non-linear-fitting-for-more-than-three-variables#comment_970791
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/578550-non-linear-fitting-for-more-than-three-variables#comment_970791
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/578550-non-linear-fitting-for-more-than-three-variables#comment_970797
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/578550-non-linear-fitting-for-more-than-three-variables#comment_970797
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/578550-non-linear-fitting-for-more-than-three-variables#comment_970803
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/578550-non-linear-fitting-for-more-than-three-variables#comment_970803
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/578550-non-linear-fitting-for-more-than-three-variables#comment_970809
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/578550-non-linear-fitting-for-more-than-three-variables#comment_970809
Sign in to comment.