Matlab outer file function

1 visualizzazione (ultimi 30 giorni)
Dawid
Dawid il 6 Set 2023
Commentato: Dawid il 10 Set 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

Risposta accettata

MarKf
MarKf il 6 Set 2023
Modificato: MarKf il 6 Set 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 Commento
Dawid
Dawid il 10 Set 2023
Yes it works thanks a lot <3 i hope you have a gr8 day

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by