Coder and passing extra parameters
2 views (last 30 days)
Show older comments
Hi all,
I have been trying to speed up the passing of extra parameters to a function that is used in fzero(). I have been trying to create code that is compatible with and can be compiled by the coder. Since nested functions and function handles aren't compatible I have been trying to get the following code compiled.
function z = RxEqNest2(z1,pin2,pin3,pT,pVpore)%#codegen
global in2 in3 T Vpore
in2=pin2;
in3=pin3;
T=pT;
Vpore=pVpore;
z = fzero(@RxEqPoly2,z1);
end
function out1 = RxEqPoly2(z)
global in2 in3 T Vpore
%RXEQPOLY2
% OUT1 = RXEQPOLY2(Z1,IN2,IN3,T,VPORE)
% This function was generated by the Symbolic Math Toolbox version 5.7.
% 15-Sep-2011 22:07:14
Keq1 = in2(:,1);
Keq2 = in2(:,2);
Keq3 = in2(:,3);
Ot = in3(:,2);
t107 = z.^2;
out1 = T.*t107.*(5.774280410608897e15./1.7592186044416e13)+Ot.^2.*T.*(5.774280410608897e15./7.0368744177664e13)+Keq2.*T.*t107.*(5.774280410608897e15./8.796093022208e12)-Ot.*T.*z.*(5.774280410608897e15./1.7592186044416e13)+Keq2.^2.*T.*t107.*(5.774280410608897e15./1.7592186044416e13)-Keq1.^2.*Vpore.*z-Keq3.^2.*Vpore.*z-Keq1.*Keq3.*Vpore.*z.*2.0-Keq2.*Ot.*T.*z.*(5.774280410608897e15./1.7592186044416e13);
end
I get errors during the compilation of the subfunction, saying that it can not find size declarations of in2,in3,T. How can passing parameters efficiently be done when this step is a major bottleneck compared the time spent evaluating the function.
Thanks
Accepted Answer
Alexander Bottema
on 19 Sep 2011
Hello Joseph,
Could you show us the 'codegen' command you're using to compile your code with? You need to use '-globals' to specify initial values for the global variables (even though these values will not be used). The initial values are used to determine the class/size/complexness of the global variables.
Thanks, Alexander
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!