Error in using * in Non-linear regression

Hello,
I would like to fit an equation in the form y=k*(x1^a)*(x2^b)*(x3^c), where I know the data of x1,x2,x3 and y.
I have to determine the coefficients k, a, b, and c.
I am using the following code:
% Fit a nonlinear regression model.
modelfun = @(b,x) b(1)*[x(:,1).^b(2)] * [x(:,2).^b(3)] * [x(:,3).^b(4)];
beta0 = [0.2 0.33 0.33 0.166];
mdl = fitnlm(X,y,modelfun,beta0)
The above code is giving an error saying:
Error in y_vs_x (line 29)
mdl = fitnlm(X,y,modelfun,beta0)
Caused by:
Error using *
Inner matrix dimensions must agree.
If I replace the second and third asterisk (*) by plus (+) then the code looks as below and is working:
modelfun = @(b,x) b(1)*[x(:,1).^b(2)] + [x(:,2).^b(3)] + [x(:,3).^b(4)];
Can anyone help me where I am going wrong?
Thanks in advacne!
vidyadhar

 Réponse acceptée

Torsten
Torsten le 5 Mar 2019
Modifié(e) : Torsten le 5 Mar 2019

0 votes

Elementwise multiplication is required:
modelfun = @(b,x) b(1)*(x(:,1).^b(2)).*(x(:,2).^b(3)).*(x(:,3).^b(4));

Plus de réponses (1)

Walter Roberson
Walter Roberson le 5 Mar 2019
Take the log of both sides.
log(y) = log(cons) + a * log(x1) + b * log(x2) + c * log(x3)
This is a linear system, so you can construct
v = [log(x1(:)), log(x2(:)), log(x3(:)), ones(length(x1),1)] \ log(y(:))
and then a = v(1), b = v(2), c = v(3), d = exp(v(4))

Catégories

En savoir plus sur Chemistry dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by