how to fit a curve in the form of A = (L^x)(D^y)

1 visualización (últimos 30 días)
Roule
Roule el 22 de Feb. de 2016
Comentada: Jos (10584) el 23 de Feb. de 2016
hi, i have some response data as vector A where the variables are L and D.
I just want to find the coefficients for L and D which will fit my data in the form mentioned in the title.
I want to fit a curved line, and not a surface.
I feel it should be fairly simple, but reading a few old answers also didn't help my case.
Is there some easy way to do this?
In case u want to see the data, here it is:
A = [0 0.06 0.12 0.44 0.56 0.94 1 1 0 0.04 0.58 0.74 0.86 1 1]
L = [100 100 100 100 100 100 100 100 43.7 49.7 56 61.5 65 77 93.8]
D = [11.3 10.1 8.9 8.5 8.1 7.7 6.5 5.3 5 5 5 5 5 5 5]
Thanks a lot.
More info:
I wrote the above equation as logA = xlogL + ylogD, and tried to use
X = [ones(size(logL)) logL logD];
b = regress(logA,X);
but Matlab didn't return any coefficients, it just gave b = NaN NaN NaN
  4 comentarios
Jos (10584)
Jos (10584) el 22 de Feb. de 2016
log(A(1)) → -Inf, causing the NaNs
Roule
Roule el 22 de Feb. de 2016
ya, instead of 0 i can use a very small number close to zero, or just ignore that particular data point altogether. in cftool, matlab just ignores that log(0).

Iniciar sesión para comentar.

Respuesta aceptada

Jos (10584)
Jos (10584) el 22 de Feb. de 2016
nlm = fitnlm([L(:) D(:)], A, 'y~(x1^b1)*(x2^b2)',[0 0])
  2 comentarios
Roule
Roule el 22 de Feb. de 2016
Editada: Roule el 22 de Feb. de 2016
Hey Jos, thanks so much. Your one line really did the work.
I am using 2013a so I had to just replace 'fitnlm' with 'NonLinearModel.fit'. I guess both will give the same results.
However the result shows very low R-squared: 0.48. Is there any way to improve this. I want to use only L and D may be in some other combination if that gives better R-squared value.
Below is the complete output:
nlm =
Nonlinear regression model: y ~ (x1^b1)*(x2^b2)
Estimated Coefficients:
Estimate SE tStat pValue
b1 0.92059 0.34937 2.635 0.02059
b2 -2.5503 0.90462 -2.8192 0.014488
Number of observations: 15, Error degrees of freedom: 13
Root Mean Squared Error: 0.31
R-Squared: 0.48, Adjusted R-Squared 0.44
F-statistic vs. zero model: 30.2, p-value = 1.31e-05
Jos (10584)
Jos (10584) el 23 de Feb. de 2016
I had the same outcome, so that's good. If you think you can come up with a better model you can fit that as well, of course. By the way, always plot your data, your fit and your residuals (fittedY - Y) to see how your model is doing.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Linear and Nonlinear Regression en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by