Matlab outer file function

2 views (last 30 days)
Dawid
Dawid on 6 Sep 2023
Commented: Dawid on 10 Sep 2023
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

Accepted Answer

MarKf
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).
  1 Comment
Dawid
Dawid on 10 Sep 2023
Yes it works thanks a lot <3 i hope you have a gr8 day

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!