Weighted nonlinear curve fitting
4 次查看(过去 30 天)
显示 更早的评论
I have the following code that do non-linear curve fiting. However i want to do weighted curve fitting so that it fits well when the value of x is above 45.
clear all
clc
x = [36.78 ,37.53 ,38.28 ,39.06 ,39.85 ,40.65 ,41.47 ,42.31,43.17 ,44.04 ,44.93 ,45.84 ,46.76 ,46.89 ,47.30 ,48.20 ];
y = [0.01 ,0.0152 ,0.023 ,0.035,0.0536 ,0.081 ,0.12 ,0.1891 ,0.287 ,0.438 ,0.66 ,1.01494 ,1.544 ,2.35,3.578 ,5.445 ];
f=0:0.2:3;
fun = @(params) [x - exp((params(2)-1)*f-1)/(params(2)-1)^2, log(y) - log(params(1)) - (params(2)+1)*f];
lb = [1e-10,-1+1e-10]; % Set lower bounds
ub = [inf,inf]; % Set upper bounds
params0 = [0.001,1.7]; % Set initial point.
options.Algorithm = 'levenberg-marquardt';
params = lsqnonlin(fun,params0,lb,ub,options)
figure(1)
plot(x,y,'ko',exp((params(2)-1)*f-1)/(params(2)-1)^2,params(1)*exp((params(2)+1)*f),'b-')
legend('Data','Best fit')
grid on
I tried this
W = [1 1 1 1 1 1 1 1 1 1 1 5 5 5 5 5]';
params = lsqnonlin(fun,params0,lb,ub,'Weights',W);
But it didnt work. Any help will be appreciated.
Thanks
4 个评论
Torsten
2016-3-1
Since you have a (1x32) vector to be fitted ([x,y]), your vector of weights also must have 32 entries.
I think after this change you will be able to use lsqnonlin for your purpose.
Best wishes
Torsten.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Interpolation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!