我試圖解決使用MATLAB fmincon功能的問題。我有一個下面顯示的公式,爲此我使用一些時間點生成了測試數據。我想根據生成的測試數據通過使用優化來估計參數x(1),x(2)和x(3)。目前使用fmincon估算的參數並不接近用於生成數據的初始參數。任何幫助將不勝感激。fmincon - 結果不接近原始參數
測試數據; 時間點= [10:10:300,500,700,1000]; x = [0.1,0.5,0.3];感興趣的%參數 Data = x(1)* sin(x(2)。* Timepoints)+ log(x(3)。* Timepoints); %使用測試方程式生成數據
% Parameters used to run the fmincon
x0 = [0, 0.1, 0.1]; % initial guess
lb = zeros(1, length(x0)); % lower bound of parameters
ub = ones(1, length(x0)); % upper bound of parameters
[x, fval, exitflag, output] = fmincon(@modelA1, x0, [], [], [], [], lb, ub, [], options, Timepoints, Data);
function fvalues = modelA(x, Timepoints, fvals)
Fvalues = zeros(1, length(Timepoints));
PreFvalues = zeros(1, length(Timepoints));
for Temp = 1:length(Timepoints)
tempY = x0(1)*sin(x0(2).*Timepoints(Temp))+log(x0(3).*Timepoints(Temp));
PreFvalues(Temp) = (fvals(Temp)-tempY)^2;
end
fvalues=sqrt(sum(PreFvalues));
感謝您尋找到這一點。當我運行腳本時,對於fmincon我得到了x = [0.0131,0.9772,0.2976],對於lsqcurvefit我得到了x = [0.0000,0.0000,0.2973]。我想知道這是不是你所得到的。 – TTZ