Function handles cannot be passed to extrinsic functions.

11 ビュー (過去 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 日
  1 件のコメント
Nishanth Goli
Nishanth Goli 2018 年 2 月 19 日
Thank you, I checked out that and it actually worked.

サインインしてコメントする。

タグ

タグが未入力です。

Community Treasure Hunt

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

Start Hunting!

Translated by