Function handles cannot be passed to extrinsic functions.

26 views (last 30 days)
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!

Answers (2)

Nishanth Goli
Nishanth Goli on 19 Feb 2018
Did you get the answer to this?

Walter Roberson
Walter Roberson on 19 Feb 2018

Categories

Find more on Simulink Functions in Help Center and File Exchange

Tags

No tags entered yet.

Community Treasure Hunt

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

Start Hunting!