Optimization problem fitting arrays
显示 更早的评论
Hi there!
I'm not very good at matlab and I'm having trouble with what I think is an easy optimization problem. I have an array of points (called alp) and I intend to fit it using an ecuation with 12 parameters. This ecuation leads to another array of points that should fit the original array (alp) by modifying the 12 parameters. Therefore I use fmincon trying to minimize the error calculated as the square sum of the original values subtracting the estimated values (SSE in statistics). I'm not getting any error but the error is not close to zero and the arrays do not fit.
Does anybody know what might be happening?
%load alp and T
initialGuess = [0,0,0,0,0,0,10,10,10,10,10,10,];
% Define the lower and upper bounds
lowerBounds = [0,0,0,0,0,0,0,0,0,0,0,0];
upperBounds = [1,1,1,1,1,1,1000,1000,1000,1000,1000,1000,];
% Use fmincon to find the optimal parameters that minimize the error
options = optimoptions('fmincon', 'StepTolerance', 1e-14,'Display', 'iter', 'FiniteDifferenceStepSize', 1e-9);
paramsOpt = fmincon(@(params) objectiveFunction(params, T, alp), initialGuess, [], [], [], [], lowerBounds, upperBounds, [], options);
% Extract the optimal values for parameters
H1 = paramsOpt(1);
H2 = paramsOpt(2);
H3 = paramsOpt(3);
S1 = paramsOpt(4);
S2 = paramsOpt(5);
S3 = paramsOpt(6);
P1 = paramsOpt(7);
P2 = paramsOpt(8);
P3 = paramsOpt(9);
W1 = paramsOpt(10);
W2 = paramsOpt(11);
W3 = paramsOpt(12);
Y1= H1*exp(-log(2)/S1^2*(log(1+2*S1*(T-P1)/W1.^2)));
Y2= H2*exp(-log(2)/S2^2*(log(1+2*S2*(T-P2)/W2.^2)));
Y3= H3*exp(-log(2)/S3^2*(log(1+2*S3*(T-P3)/W3.^2)));
Y=Y1+Y2+Y3;
figure, clf
plot(T,alp)
hold on
plot(T,Y,'-o')
function SSE = objectiveFunction(params, T, alp)
h1=params(1);
h2=params(2);
h3=params(3);
s1=params(4);
s2=params(5);
s3=params(6);
p1=params(7);
p2=params(8);
p3=params(9);
w1=params(10);
w2=params(11);
w3=params(12);
y1 = h1*exp(-log(2)/s1^2*(log(1+2*s1*(T-p1)/w1.^2)));
y2 = h2*exp(-log(2)/s3^2*(log(1+2*s2*(T-p2)/w2.^2)));
y3 = h3*exp(-log(2)/s3^2*(log(1+2*s3*(T-p3)/w3.^2)));
V = y1+y2+y3;
%SSR = sum((V-mean(alp)).^2);
SSE = sum((alp - V).^2);
%Rsq=(SSR/(SSE+SSR))^(1/2);
end
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Least Squares 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

