Function handles cannot be passed to extrinsic functions.

17 visualizaciones (últimos 30 días)
Ji Guo
Ji Guo el 16 de Abr. de 2015
Comentada: Nishanth Goli el 19 de Feb. de 2018
Hi,
I'm using a Matlab Function Block in simulink to calculate the minimum value of a objective function with constraints.
I get this error during my simulation:
Function handles cannot be passed to extrinsic functions.
Function 'MaxRange ' (#106.382.388), line 25, column 13: "@nlfun"
Launch diagnostic report.
Below are my codes:
function y=minLoss(a,b,c,d,e)
coder.extrinsic('fmincon');
global Pload;
global R1;
global R2;
global Vocv1;
global Vocv2;
Pload=a;
R1=b;
R2=c;
Vocv1=d;
Vocv2=e;
x0=[1;-1];
A=[];B=[];
Aeq=[];Beq=[];
LB=[];UB=[];
num.of.bat.pack=2;
y = coder.nullcopy(zeros(size(num.of.bat.pack)));
[y]=fmincon(@nlfun,x0,A,B,Aeq,Beq,LB,UB,@nlcon);
function f=nlfun(x)
global R1;
global R2;
f=R1*x(1)^2+R2*x(2)^2;
function [g,ceq]=nlcon(x)
global Pload;
global R1;
global R2;
global Vocv1;
global Vocv2;
g=[];
ceq=Vocv1*x(1)-R1*x(1)^2+Vocv2*x(2)-R2*x(2)^2-Pload;
nlfun is my objective function.
nlcon is my constraint function.
inputs (a,b,c,d,e) are the parameters for nlfun and nlcon.
Can anyone kindly advise on what actually went wrong? Much Thanks in advance!

Respuestas (2)

Nishanth Goli
Nishanth Goli el 19 de Feb. de 2018
Did you get the answer to this?

Walter Roberson
Walter Roberson el 19 de Feb. de 2018

Etiquetas

Aún no se han introducido etiquetas.

Community Treasure Hunt

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

Start Hunting!

Translated by