Can vpasolver work in simulink model?

7 views (last 30 days)
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;

Accepted Answer

Uday Pradhan
Uday Pradhan on 16 Dec 2020
Edited: Uday Pradhan on 16 Dec 2020
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 Comments
Gordon
Gordon on 13 Jun 2022
I get the error that numvars = 0. So it's as if still not evaluating variables.
Paris Pasqualin
Paris Pasqualin on 14 Jun 2022
Hi Gordon,
You actually do not need the vpasolve for simulink. You run the vpasolve once without spacifing any of the parameters and you should get equations that correlate the output parameters with the input ones. In my case I have:
Cp1 = (Cf*(156250*A1*Ps + 156250*A1*Lp*P - 156250*A1*Lp*P*sigma - 13*Cf*Lp*T*i1*sigma + 13*Cf*Lp*T*i1*sigma^2))/(13*Cf*Lp*T*i1*sigma^2 - 13*Cf*Lp*T*i1*sigma + 156250*A1*Ps) - (24414062500*A1^2*Ps^2 - 317382812500*A1*Ps*((A1^2*Lp^2*P^2)/169 + (2*A1^2*Lp*P*Ps)/169 + (A1^2*Ps^2)/169 - (A1*Cf*Lp^2*P*T*i1*sigma^2)/1015625 + (A1*Cf*Lp*Ps*T*i1*sigma^2)/1015625 + (Cf^2*Lp^2*T^2*i1^2*sigma^4)/24414062500)^(1/2) + 24414062500*A1^2*Lp*P*Ps - 169*Cf^2*Lp^2*T^2*i1^2*sigma^3 + 169*Cf^2*Lp^2*T^2*i1^2*sigma^4 + 26406250*Cf*Lp*T*i1*sigma*((A1^2*Lp^2*P^2)/169 + (2*A1^2*Lp*P*Ps)/169 + (A1^2*Ps^2)/169 - (A1*Cf*Lp^2*P*T*i1*sigma^2)/1015625 + (A1*Cf*Lp*Ps*T*i1*sigma^2)/1015625 + (Cf^2*Lp^2*T^2*i1^2*sigma^4)/24414062500)^(1/2) - 26406250*Cf*Lp*T*i1*sigma^2*((A1^2*Lp^2*P^2)/169 + (2*A1^2*Lp*P*Ps)/169 + (A1^2*Ps^2)/169 - (A1*Cf*Lp^2*P*T*i1*sigma^2)/1015625 + (A1*Cf*Lp*Ps*T*i1*sigma^2)/1015625 + (Cf^2*Lp^2*T^2*i1^2*sigma^4)/24414062500)^(1/2) + 2031250*A1*Cf*Lp^2*P*T*i1*sigma + 4062500*A1*Cf*Lp*Ps*T*i1*sigma^2 - 2031250*A1*Cf*Lp^2*P*T*i1*sigma^2 - 2031250*A1*Cf*Lp*Ps*T*i1*sigma)/(26*Lp*T*i1*sigma*(13*Cf*Lp*T*i1*sigma^2 - 13*Cf*Lp*T*i1*sigma + 156250*A1*Ps));
Cp2 = (Cf*(156250*A1*Ps + 156250*A1*Lp*P - 156250*A1*Lp*P*sigma - 13*Cf*Lp*T*i1*sigma + 13*Cf*Lp*T*i1*sigma^2))/(13*Cf*Lp*T*i1*sigma^2 - 13*Cf*Lp*T*i1*sigma + 156250*A1*Ps) - (24414062500*A1^2*Ps^2 + 317382812500*A1*Ps*((A1^2*Lp^2*P^2)/169 + (2*A1^2*Lp*P*Ps)/169 + (A1^2*Ps^2)/169 - (A1*Cf*Lp^2*P*T*i1*sigma^2)/1015625 + (A1*Cf*Lp*Ps*T*i1*sigma^2)/1015625 + (Cf^2*Lp^2*T^2*i1^2*sigma^4)/24414062500)^(1/2) + 24414062500*A1^2*Lp*P*Ps - 169*Cf^2*Lp^2*T^2*i1^2*sigma^3 + 169*Cf^2*Lp^2*T^2*i1^2*sigma^4 - 26406250*Cf*Lp*T*i1*sigma*((A1^2*Lp^2*P^2)/169 + (2*A1^2*Lp*P*Ps)/169 + (A1^2*Ps^2)/169 - (A1*Cf*Lp^2*P*T*i1*sigma^2)/1015625 + (A1*Cf*Lp*Ps*T*i1*sigma^2)/1015625 + (Cf^2*Lp^2*T^2*i1^2*sigma^4)/24414062500)^(1/2) + 26406250*Cf*Lp*T*i1*sigma^2*((A1^2*Lp^2*P^2)/169 + (2*A1^2*Lp*P*Ps)/169 + (A1^2*Ps^2)/169 - (A1*Cf*Lp^2*P*T*i1*sigma^2)/1015625 + (A1*Cf*Lp*Ps*T*i1*sigma^2)/1015625 + (Cf^2*Lp^2*T^2*i1^2*sigma^4)/24414062500)^(1/2) + 2031250*A1*Cf*Lp^2*P*T*i1*sigma + 4062500*A1*Cf*Lp*Ps*T*i1*sigma^2 - 2031250*A1*Cf*Lp^2*P*T*i1*sigma^2 - 2031250*A1*Cf*Lp*Ps*T*i1*sigma)/(26*Lp*T*i1*sigma*(13*Cf*Lp*T*i1*sigma^2 - 13*Cf*Lp*T*i1*sigma + 156250*A1*Ps));
Then you use these equations in simulink.
Kind regards,
Paris

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Tags

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!