I have error on my code.This slp method to minimize function
clear;
clc;
x=[1;1];
dxlb=[-1;-1];
dxub=[1;1];
Tolx=0.01;
TolCon=0.01;
[f,g]=f_SLPclass(x);
[gradf,gradg]=g_SLPclass(x);
coverged=false;
iter=0;
while converged
c=gradf';
a=gradg';
b=-g;
dx=linprog(c,a,b,[],[],dxlb,dxub);
x=x+dx;
[f,g]=f_SLPclass(x);
[gradf,gradg]=g_SLPclass(x);
iter=iter+1;
converged=max(abs(dx)<Tolx)&& max(g)<TolCon;
end
fprintf('\n number of iteration %f\n',iter);
fprintf('\n Optimum Point: (%f,%f,%f,%f,%f)\n',x1,x2,x3,x4,x5);

댓글 수: 2

Matt J
Matt J 2021년 3월 8일
What error?
Ous Chkiri
Ous Chkiri 2021년 3월 8일
Error using SLP>f_SLPclass
Too many output arguments.
Error in SLP (line 8)
[f,g]=f_SLPclass(x);

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

 채택된 답변

Matt J
Matt J 2021년 3월 8일
편집: Matt J 2021년 3월 8일

0 개 추천

Your functions f_ and g_SLPclass have missing parts.
function [f,g]=f_SLPclass(x) %return outputs
assert(length(x)==5, "x should be 5 elements long, but instead it is length " + length(x));
xcell=num2cell(x);
[x1,x2,x3,x4,x5]= deal(xcell{:});
f=0.0624*(x1+x2+x3+x4+x5);
g=-1+61/x1^3 +37/x2^3 +19/x3^3 +7/x4^3 +1/x5^3;
end

댓글 수: 6

Ous Chkiri
Ous Chkiri 2021년 3월 8일
same error : Error
using SLP>f_SLPclass (line 28)
x should be 5 elements long, but it is only length 2
Error in SLP (line 8)
[f,g]=f_SLPclass(x);
Matt J
Matt J 2021년 3월 8일
It is not the same error message.
Ous Chkiri
Ous Chkiri 2021년 3월 8일
clear;
clc;
x=[1;1];
dxlb=[-1;-1];
dxub=[1;1];
Tolx=0.01;
TolCon=0.01;
[f,g]=f_SLPclass(x);
[gradf,gradg]=g_SLPclass(x);
coverged=false;
iter=0;
while converged
c=gradf';
a=gradg';
b=-g;
dx=linprog(c,a,b,[],[],dxlb,dxub);
x=x+dx;
[f,g]=f_SLPclass(x);
[gradf,gradg]=g_SLPclass(x);
iter=iter+1;
converged=max(abs(dx)<Tolx)&& max(g)<TolCon;
end
fprintf('\n number of iteration %f\n',iter);
fprintf('\n Optimum Point: (%f,%f,%f,%f,%f)\n',x1,x2,x3,x4,x5);
function [f,g]=f_SLPclass(x) %return outputs
assert(length(x)==5, "x should be 5 elements long, but instead it is length " + length(x));
xcell=num2cell(x);
[x1,x2,x3,x4,x5]= deal(xcell{:});
f=0.0624*(x1+x2+x3+x4+x5);
g=-1+61/x1^3 +37/x2^3 +19/x3^3 +7/x4^3 +1/x5^3;
end
function [gradf,gradg]=g_SLPclass(x)
assert(length(x)==5, "x should be 5 elements long, but it is only length " + length(x));
xcell=num2cell(x);
[x1,x2,x3,x4,x5]= deal(xcell{:});
gradf=0.312;
gradg=-183/x1^4 - 111/x2^4 -57/x3^4 -21/x4^4 -3/x5^4;
end
Ous Chkiri
Ous Chkiri 2021년 3월 8일
I just run it and it gives me the same error :
Error using SLP>f_SLPclass (line 28)
x should be 5 elements long, but instead it is length 2
Error in SLP (line 8)
[f,g]=f_SLPclass(x);
Matt J
Matt J 2021년 3월 8일
편집: Matt J 2021년 3월 8일
Ous Chkiri
Ous Chkiri 2021년 3월 8일
Yes your right Sorry. It gives another error

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

추가 답변 (0개)

카테고리

도움말 센터 및 File Exchange에서 Programming에 대해 자세히 알아보기

제품

태그

질문:

2021년 3월 8일

편집:

2021년 3월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by