parameter estimation using lsqcurvefit
5 次查看(过去 30 天)
显示 更早的评论
I have a strange problem. I wrote a function named "post_2" which uses lsqcurvefit command which interns calls a model function named "function_one" in which I pass few arguments as below. This works perfectly fine.
However, now I am not given the value of dVec (time lag for the signal eVec) so I cannot pass dVec as input. Therefore, I want to make 'd' (i.e. input to "function_one") as a variable i.e. k(3) so that the optimizer also estimates the value of k(3) from the model fitting. The condition on k(3) is that it can only take positive real integers values from 0-to-length(aVec). I have attached a matlab file 'testVar.mat'.
Kindly suggest how to do this. Many Thanks in advance.
if true
% Start script for calling the Function "post_2"
testVec = load('testVar.mat') ;
aVec = testVec(:,1);
bVec = testVec(:,2);
cVec = testVec(:,3);
dVec = testVec(1,4);
[X,Y] = post_2( aVec, [0 ; 0 ; bVec(1:end-2)] , cVec, 3 )
disp('The output should be X=0.0032 and Y=0.1984')
% End script for calling the Function "post_2"
% FUNCTION code
function [ X, Y ] = post_2( aVec , bVec , cVec , dVec )
eVec = [ zeros(dVec,1) ; cVec ];
lb = [0 0]; ub = [1 1]; initalCondition = [0.50 0.50];
ahat = lsqcurvefit( @(x,aVec) function_one(x,aVec,eVec,dVec),initalCondition,aVec,bVec,lb,ub);
X = ahat(1); Y = ahat(2);
function F = function_one(k,a,e,d)
conv_res = k(1) * conv( e , exp(-k(1)*a/k(2)) );
F = conv_res( 1:(length(e)-d) );
end
end
% -- -Function End---%
end
0 个评论
采纳的回答
Alan Weiss
2014-1-28
Unfortunately, Optimization Toolbox solvers do not accept integer-valued variables. So lsqcurvefit will not be able to optimizae over dvec.
You have two choices that I see. One is to optimize over dvec in an outside loop (I mean, do an exhaustive search over various dvec values, or use patternsearch to optimize over dvec where you take the initial point for patternsearch to be an integer vector, have the stopping criterion be when the mesh coes below size 1, and turn off mesh scaling). Or you could use integer ga to try to search the dvec values, realizing that ga is not all that reliable.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation
0 个评论
更多回答(1 个)
另请参阅
类别
在 Help Center 和 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!