non linear data fit (weighted least square)

9 ビュー (過去 30 日間)
Alessandro
Alessandro 2012 年 5 月 15 日
Hello, I would like to fit a data set (X,Y) with a non linear function y=f(x,a,b) where a and b are the paramters to be fitted.
In my case both X and Y have an uncertainty.
Is there a way to carry out a weighted least square with MATLAB?
Can the uncertainty on X be taken into account?
I spent nearly one hour looking around for a way to do that but I had no success.
Thank you,
  2 件のコメント
Thijs
Thijs 2012 年 5 月 15 日
what is the function?
Alessandro
Alessandro 2012 年 5 月 16 日
any function, take for example:
y=a*x^b

サインインしてコメントする。

採用された回答

Sargondjani
Sargondjani 2012 年 5 月 15 日
check:
-lsqcurvefit
-lsqnonlin (both are in optimization toolbox though)
im not sure how you want to take account of the uncertainty in x, but you can also program any optimization yourself. basically you just have to write an objective function and plug that into:
-fminsearch
or if you have optimization toolbox:
-fminunc (unconstrained optimization)
-fmincon (constrained opt.)
  1 件のコメント
Alessandro
Alessandro 2012 年 5 月 16 日
So, correct me if I'm wrong, I have to define my own function: e.g. if I want to fit y=f(X,a,b) and minimize sum((|y-f|/sigma_y)^2)
I will have to define the function g=g(X,sigma_y,a,b)=f/sigma_y
and replace the data set y with y/sigma_y
Thank you

サインインしてコメントする。

その他の回答 (2 件)

Geoff
Geoff 2012 年 5 月 16 日
Let's say you have your function:
f = @(x,a,b) = a * x.^b;
Now, you have your data set and weights:
X = [...];
Y = [...];
W = [...];
I'll assume that W is positive, where higher values have more influence...
So, you want an objective function that accounts for these weights:
wobj = @(p,x,y,w) = sum(w .* (f(x,p(1),p(2)) - y) .^ 2);
Here I've calculated the square difference between your function f and the data y, multiplied that by the weights, and then summed the result. That might not be the correct way, but bear with me - I'm not a mathematician!
Finally, you wrap it all together. Since I'm used to fminsearch I'll use that, but there are probably better functions available that will minimize on an objective function.
p0 = [a0, b0]; % Initial guess for a and b
p = fminsearch( @(p) wobj(p,X,Y,W), p0 );
a = p(1);
b = p(2);
If this isn't quite right, it ought to be close =) Perhaps I should've divided those weights? Erkk, brain doesn't want to think about it right now.

Frederic Moisy
Frederic Moisy 2012 年 5 月 16 日
Hello,
a simple non-linear fitting method is provided in the (free) Ezyfit toolbox:

カテゴリ

Help Center および File ExchangeSolver Outputs and Iterative Display についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by