parameter estimation using lsqcurvefit
Ältere Kommentare anzeigen
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
Akzeptierte Antwort
Weitere Antworten (1)
Anuj Anand
am 28 Jan. 2014
0 Stimmen
Kategorien
Mehr zu Get Started with Optimization Toolbox finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!