How to fit a power law equation using three variables?

조회 수: 4 (최근 30일)
Jonathan Macuroy
Jonathan Macuroy 2020년 2월 6일
댓글: Rik 2020년 2월 6일
Say I have three datasets namely X, Y, and Z. As per literature, I have to find the relationship between the three variables as given by the equation: (i.e. i have to find a, b, and c).
May I ask if you know how to do this? Thanks a lot in advance.
  댓글 수: 2
Rik
Rik 2020년 2월 6일
Do you have the curve fitting toolbox?
Jonathan Macuroy
Jonathan Macuroy 2020년 2월 6일
Hello, yes, I have the toolbox.

댓글을 달려면 로그인하십시오.

채택된 답변

John D'Errico
John D'Errico 2020년 2월 6일
편집: John D'Errico 2020년 2월 6일
The answer is simple, sort of. But it very much depends on your data. For example, if Z varies by multiple orders of magitude over the data, then it is likely that the small values of Z will be fit poorly in a relative sense.
Is this the case? I can only conjecture here, since I was given nothing. But when you have power law type models like that, it is VERY common to have data that does vary by multiple orders of magnitude, and as well, a heteroscedastic error structure, of some sort.
As such, a good choice is to log the model. That allows us to introduce the idea of a proportional error structure, which is often highly appropriate when you have data that does vary over multiple orders of magnitude. The idea is if your small numbers tend to have roughly the same proportional noise in them as the large values, then you needed to treat the model properly, by logging the data. Does that help any? Yes, in fact, it does. Because now your model looks like:
log(Z) = log(a) + b*log(X) + c*log(Y)
This is now a purely linear model. As well, if the noise was proportional noise in the original case, then it is now additive noise. Essentially, the log transform changes a lognormal error structure to a tradtional Gaussian one.
I cannot see your data, of course since you show nothing. However, the simple way to perform the above fit is as easy as...
n = numel(Z);
coef = [ones(n,1),log(X(:)),log(Y(:))] \ log(Z(:));
abc = [exp(coef(1));coef(2:3)];
Here, abc is now a vector of the coefficients as [a;b;c].
Could I have used the curve fitting toolbox? Of course. It depends on your data, and if you need to log the data or not.
  댓글 수: 2
Jonathan Macuroy
Jonathan Macuroy 2020년 2월 6일
Thank you! Your suggestion did the trick! Cheers!
Rik
Rik 2020년 2월 6일
Here is an example using the curve fitting toolbox, although reading John's answer I would have liked to come up with something similar.
%generate some data
[X,Y]=meshgrid(linspace(0,10,100));
a=5+rand;b=2+0.1*rand;c=3+0.2*rand;
Z=a.*X.^b.*Y.^c;
fitFun=@(a,b,c,x,y) a.*x.^b.*y.^c;
f=fit([X(:) Y(:)],Z(:),fitFun,...
'StartPoint',[4 1 1]);
clc
fprintf('true a=%.2f, fitted a=%.2f\n',a,f.a)
fprintf('true b=%.2f, fitted b=%.2f\n',b,f.b)
fprintf('true c=%.2f, fitted c=%.2f\n',c,f.c)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by