MATLAB: Can vpasolver work in simulink model

MATLABvpasolver

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;

Best Answer

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!