Function handles cannot be passed to extrinsic functions.

조회 수: 17 (최근 30일)
Ji Guo
Ji Guo 2015년 4월 16일
댓글: Nishanth Goli 2018년 2월 19일
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!

답변 (2개)

Nishanth Goli
Nishanth Goli 2018년 2월 19일
Did you get the answer to this?

Walter Roberson
Walter Roberson 2018년 2월 19일

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by