optmization code for sumsqure of error

조회 수: 1 (최근 30일)
Abdulaziz Altowijri
Abdulaziz Altowijri 2020년 5월 18일
답변: Raunak Gupta 2020년 6월 24일
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
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
Abdulaziz Altowijri
Abdulaziz Altowijri 2020년 5월 21일
my data file consists of 4 columns and 16 rows
each column is represent by f: so f1, f2, f3, f4,
each row represents a choice
A1
B1
C1
D1
then the next set
A2
B2
C2
D2
.
.
UA4= x1*(f1)+x2*(f2)+x3*(f3)+x4*(f4);
UB4= x1*(f1)+x2*(f2)+x3*(f3)+x4*(f4);
UC4= x1*(f1)+x2*(f2)+x3*(f3)+x4*(f4);
UD4= x1*(f1)+x2*(f2)+x3*(f3)+x4*(f4);
UA4-UB4+ep10>=0;
UA4-UC4+ep11>=0;
UA4-UD4+ep12>=0;
so in total i have 4 sets.
my objective function is
min z = (ep1)^2+(ep2)^2+(ep3)^2+(ep4)^2.....(epk)^2
subject to
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;
epi>0,x1+x2+x3+x4=1, x1>=0, x2>=0, x3>=0, x4>=0,
with my code i am able to get the fs i need my only issue, i dont believe my (ep) is coded correctly meaning i am not minmizing ep1^2 +ep2^2 .....ep12^2?
i hope this explains the issue, i believe i am using lsqnonlin the wrong way or my function is coded wrong
thanks

댓글을 달려면 로그인하십시오.

답변 (1개)

Raunak Gupta
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.

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by