Fit multiple sets of data with same function model to get optimal global parameter using lsqcurvefit
显示 更早的评论
Hello everyone. I have been using lsqcurvefit to get optimal parameter values for different sets of data. I want to find optimal values for delta_HG and K for each set of data. I can already do that separately, which means using lsqcurvefit on each set of data. The values I get are delta_HG=58 and K=1742 for data set pks_locs1, and delta_HG=1541 and K=1750 for data set pks_locs2. As you can see, delta_HG values are very different, but K values are very similar (as it should be). What I want to do now is to combine these fits into a single one. Output should be both delta_HG values and a single K value (the value which best fits BOTH data sets). I have been looking at similar questions asked here but none really helped me. Below is the code of what I've got so far. Any comments and/or suggestions are much appreciated.
G=2.529e-4;
R=[0.1:0.1:0.4 0.6:0.2:1.8 2.1 2.4:0.4:3.2 3.8 4.8 6 8.4 12.8 20 36];
pks_locs1=[136 123.5 121 120.5 124 119 118 114 111.5 109.5 108 103 103.5 101.5 98 97 96 90 84 77.5 74.5 56 63.5];
pks_locs2=[903 920 951.5 964.5 944 1006 1026 1050.5 1105.5 1112.5 1122.5 1169 1177 1201 1229 1247 1235.5 1321 1354 1404.5 1444 1499.5 1474.5];
init=[100 1000;100 1000];
R=[R;R];
pks=[pks_locs1;pks_locs2];
fitted=lsqcurvefit(@(param,x) func(param,x,pks,G),init,R,pks(:,2:end));
function f=func(param,R,pks_locs,G)
delta_HG=param(1);
K=param(2);
f=pks_locs(1)+(delta_HG-pks_locs(1))*(G*K.*(1+R)+1-sqrt((G*K.*(1+R)+1).^2-R.*(2*K*G).^2))./(2*K*G);
5 个评论
Javier Agustin Romero
2019-3-27
Javier Agustin Romero
2019-3-27
编辑:Javier Agustin Romero
2019-3-27
Catalytic
2019-3-27
The model function that you are trying to have is not clear. In the code you have posted, your model function has two unknowns, but your init has 4 unknowns. How many unknowns are there supposed to be?
Javier Agustin Romero
2019-3-27
采纳的回答
更多回答(1 个)
Jhon MT
2019-10-10
0 个投票
Hi everyone, please could you explain me what does "delta" do here? : "curve1=delta([delta_HG1,K] ,R,pks_locs1,G);", I have matlab R2017a and when I run the code this is what I got: Undefined function or variable 'delta'.
Thanks a lot.
Regards
类别
在 帮助中心 和 File Exchange 中查找有关 Get Started with Optimization Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!