Function handles cannot be passed to extrinsic functions.
이전 댓글 표시
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
2018년 2월 19일
0 개 추천
Did you get the answer to this?
Walter Roberson
2018년 2월 19일
0 개 추천
댓글 수: 1
Nishanth Goli
2018년 2월 19일
Thank you, I checked out that and it actually worked.
카테고리
도움말 센터 및 File Exchange에서 Simulink Model에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!