Matlab outer file function
1 view (last 30 days)
Show older comments
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 Comments
Accepted Answer
MarKf
on 6 Sep 2023
Edited: MarKf
on 6 Sep 2023
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).
More Answers (0)
See Also
Categories
Find more on Surrogate Optimization in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!