Can vpasolver work in simulink model?
15 次查看(过去 30 天)
显示 更早的评论
Hello to everyone,
I wanted to create a function block on simulink with outputs calculated from the solution of vpasolver. When I run the simulink model I get an error saying
"Function 'syms' not supported for code generation. Function 'MATLAB Function' (#35.101.118), line 3, column 1: "syms Qp cp Qb cb" Launch diagnostic report."
Does this mean that vpasolver can't work on simulink? If yes, could there be a way to use it? Beneath it's the function I'm referring to.
Best regards,
Paris
function [Qp,cp,Qb,cb] = fcn(Q_in,c_in,r,P,i,T)
R = 0.0832; % Universal gas constant [L*atm/(K*mol)]
syms Qp cp Qb cb
S = vpasolve(r == 1-cp/c_in, Q_in == Qp+Qb, Q_in*c_in == Qp*cp + Qb*cb, P/(i*R*(T+273.15)) == cb-cp, [Qp cp Qb cb]);
Qp = S.Qp;
cp = S.cp;
Qb = S.Qb;
cb = S.cb;
0 个评论
采纳的回答
Uday Pradhan
2020-12-16
编辑:Uday Pradhan
2020-12-16
Hi,
I think a possible workaround to this would be to do the symbolic computations in a separte function script and call that function from your block as an extrinsic function. Example: Define 'fcn.m' that contains all the computations:
function [qp,cp,qb,cb] = fcn(Q_in,c_in,r,P,i,T)
R = 0.0832; % Universal gas constant [L*atm/(K*mol)]
syms Qp cp Qb cb
S = vpasolve(r == 1-cp/c_in, Q_in == Qp+Qb, Q_in*c_in == Qp*cp + Qb*cb, P/(i*R*(T+273.15)) == cb-cp, [Qp cp Qb cb]);
qp = double(S.Qp);
cp = double(S.cp);
qb = double(S.Qb);
cb = double(S.cb);
end
Then in the MATLAB function block call:
function [Qp,cp,Qb,cb] = fcn1(Q_in,c_in,r,P,i,T)
coder.extrinsic('fcn');
Qp = 0;
cp = 0;
Qb = 0;
cb = 0;
[Qp,cp,Qb,cb] = fcn(Q_in,c_in,r,P,i,T);
I hope this helps!
4 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 General Applications 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!