Matlab outer file function
조회 수: 1 (최근 30일)
이전 댓글 표시
so i have this code in my main file
nonlcon=@ogr_niel1;
x0=[1 1 1];
fun=@(x)exp(x(1)) *(4*x(1)^2 + 2*x(2)^2 + 4*x(1)*x(2));
A=[];
b=[];
Aeq=[];
beq=[];
lb=[];
ub=[];
x=fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon)
and this is my outer file
function [c.ceq] = ogr_niel1(x)
c=[x(1)*x(2)-x(1)-x(2)+1.5;-x(1)*x(2)-10]
ceq=[];
end
and it tells me that im missing a closing or there invalid syntax and i rly don't see what im doing wrong here. Sorry if thats something obvious i wasted a day trying to solve it and i just don't understand where mistake is
댓글 수: 0
채택된 답변
MarKf
2023년 9월 6일
편집: MarKf
2023년 9월 6일
Invalid use of operator "."
You can't tell a function to make an output a struct (since that might break things, you can only assign variables), but maybe you meant to put a comma there since you do not create a struct in the funtion but just 2 variables?
function [c, ceq] = ogr_niel1(x)
That's probably the case (since otherwise you'd just assign a struct field when calling the function in your script, but you are using it as a handle).
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Surrogate Optimization에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!