optmization code for sumsqure of error
조회 수: 1 (최근 30일)
이전 댓글 표시
i have a question about my optmization problem this is my problem formlation
it should be this way
min z = (ep1)^2+(ep2)^2+(ep3)^2+(ep4)^2.....(epk)^2
!1;
UA1= x1*(f1)+x2*(f2)+x3*(f3)+x4*(f4);
UB1= x1*(f1)+x2*(f2)+x3*(f3)+x4*(f4);
UC1= x1*(f1)+x2*(f2)+x3*(f3)+x4*(f4);
UD1= x1*(f1)+x2*(f2)+x3*(f3)+x4*(f4);
UA1-UB1+ep1>=0;
UA1-UC1+ep2>=0;
UA1-UD1+ep3>=0;
and so on
i am comparing my code to results i obtained using another optmization program
in my matlab my cod i got everything good expect my minmize z (ie SSE) ? i dont know what i am doing worng please help
% Clearing Command Window
clc
clearvars
close all
f = xlsread('data.xlsx');
% Finding Size of Data
[m, n] = size(f);
lb = [0 0 0 0];
ub = [1 1 1 1];
%Initial values of ep
ep=rand(4,1);
% Guessing Initial Values of [ x(1) x(2) x(3) x(4)]
x0 = [ 0.25 0.25 0.25 0.25];
A=f(1:4:16,1:4);
B=f(2:4:16,1:4);
C=f(3:4:16,1:4);
D=f(4:4:16,1:4);
fun = @(x)[(x(1)*A(:,1)+x(2)*A(:,2)+x(3)*A(:,3)+x(4)*A(:,4))-(x(1)*B(:,1)+x(2)*B(:,2)+x(3)*B(:,3)+x(4)*B(:,4))+ep(:,1);
(x(1)*A(:,1)+x(2)*A(:,2)+x(3)*A(:,3)+x(4)*A(:,4))-(x(1)*C(:,1)+x(2)*C(:,2)+x(3)*C(:,3)+x(4)*C(:,4))+ep(:,1);
(x(1)*A(:,1)+x(2)*A(:,2)+x(3)*A(:,3)+x(4)*A(:,4))-(x(1)*D(:,1)+x(2)*D(:,2)+x(3)*D(:,3)+x(4)*D(:,4))+ep(:,1);
x(1)+x(2)+x(3)+x(4)-1;];
% Solving Equation using - lsqnonlin
options=optimset('DerivativeCheck','off','Display','off','TolX',1e-12,'TolFun',1e-12,...
'Diagnostics','off','MaxIter',10e+6);
[x,SSE] = lsqnonlin(fun,x0,lb,ub,options);
clc
fprintf('\n\tThe w(1) = %E',x(1))
fprintf('\n\tThe w(2) = %E',x(2))
fprintf('\n\tThe w(3) = %E',x(3))
fprintf('\n\tThe w(4) = %E',x(4))
fprintf('\n\tThe Mimimum SSE = %f\n',SSE)
the whole issue is with SSE and ep plese and thier minimization
thank you for your help
댓글 수: 2
Alan Weiss
2020년 5월 20일
I'm sorry, but I do not understand what you are trying to do. Can you please briefly explain what size your optimization variable has? What the objective function is in terms of the optimization variable? What the bounds are, if any?
Alan Weiss
MATLAB mathematical toolbox documentation
답변 (1개)
Raunak Gupta
2020년 6월 24일
Hi,
The objective function you have mentioned in the question is not what you are trying to minimize. As the combination of UA1,UB1,UC1,UD1 represents the constraints you need to use fmincon to clearly mention those constraints. Here you are trying to find x, so constraints should be mentioned in terms of x. Also, objective function should be in terms of x but need to be calculated from ep1,ep2,….epk constraints. The main challenge is deriving the objective function because right now it's not represented in terms of optimization variable.
I suggest to write the optimization problem to be solved using fmincon because lsqnonlin doesn’t take account of constraints in the problem and is used for curve fitting applications.
댓글 수: 0
참고 항목
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!