Fit a parameter to minimise a correlation between two vectors
2 次查看(过去 30 天)
显示 更早的评论
Hello,
I'm struggling to figure out how to formulate a fitting problem in Matlab 2017b.
Bassically I run an experimen and it spits out a number,
. However, this number is biased by some other parameters,
. There is hypothetical correction factor with the following relationship:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/269157/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/269158/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/269159/image.png)
where
are all values that can be extracted for a given experiment. δ is a common factor which is unknown, but should be the same for all my data.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/269160/image.png)
So, after acquiring a load of data,
are all vectors, and I want to find the value of the number, δ, that minimises the corelation between
and
.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/269161/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/269162/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/269163/image.png)
- Does Matlab have a good method to deal with this?
- If not, what is the best way to set it up as a minimisation problem?
Any advice would be appreciated!
Thanks!
0 个评论
回答(1 个)
Jeff Miller
2020-1-30
% Some fake data to use in testing:
% Presumably you have your own values for these.
nExpts = 10;
C = rand(nExpts,1);
V1 = rand(nExpts,1);
V2 = rand(nExpts,1);
R1 = rand(nExpts,1);
R2 = rand(nExpts,1);
Nraw = rand(nExpts,1);
% Some boundaries on where you think the best delta might lie.
minDelta = -100;
maxDelta = 100;
% This function call will give you the best delta and the low correlation that it produces:
[bestDelta, bestCorr] = findDelta(C,V1,V2,R1,R2,Nraw,minDelta,maxDelta)
% This function does the actual work:
function [bestDelta, bestCorr] = findDelta(C,V1,V2,R1,R2,Nraw,minDelta,maxDelta)
[bestDelta, bestCorr] = fminbnd(@fCorr,minDelta,maxDelta);
function theCorr = fCorr(tryDelta)
Ncorrected = C .* (V1 * tryDelta + V2) ./ (V1 .* R1 * tryDelta + V2 .* R2) .* Nraw;
theCorr = abs( corr(V1,Ncorrected) ); % I'm guessing you want the correlation close to zero, not -1
end
end
2 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Get Started with Curve Fitting Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!