Using Fminsearch to Minimize Data difference
2 views (last 30 days)
Show older comments
I need to create a function that can be passed to fminsearch. I want to get argmink =||ak-d||^2, where a is a time series output ie x,y (amplitude/time) and d is another different time series output signal. I need to find the value of k that will cause convergence or give the minimum difference value between a and d. So I want to use fminsearch to do this. Some pointer will be very useful. Thanks.
0 Comments
Answers (1)
Star Strider
on 26 Feb 2016
If I understand correctly what you want to do, this works:
d = randi(9, 10, 1); % Create Data
a = randi(9, 10, 1); % Create Data
argmin_k = @(k) norm(a*k-d).^2; % ‘argmin’ Function
[k,normval] = fminsearch(argmin_k, 1);
3 Comments
Star Strider
on 26 Feb 2016
Thank you!
I am not certain what you want to do. For ‘k’ to be a vector, ‘k’ would have to be the same length as ‘a’ and ‘d’, and you would then use element-wise multiplication (.*) in your ‘argmin_k’ function.
The code changes to:
d = randi(9, 10, 1); % Create Data
a = randi(9, 10, 1); % Create Data
argmin_k = @(k) norm(a.*k-d).^2; % ‘argmin’ Function
K0 = ones(size(d)); % Vector ‘k’ Is The Same Length As The Data Vectors
[k,normval] = fminsearch(argmin_k, K0);
See Also
Categories
Find more on Nonlinear Optimization in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!