Matlab outer file function

조회 수: 1 (최근 30일)
Dawid
Dawid 2023년 9월 6일
댓글: Dawid 2023년 9월 10일
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)
Invalid use of operator.
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

채택된 답변

MarKf
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).
  댓글 수: 1
Dawid
Dawid 2023년 9월 10일
Yes it works thanks a lot <3 i hope you have a gr8 day

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Surrogate Optimization에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by