Can vpasolver work in simulink model?

조회 수: 9 (최근 30일)
Paris Pasqualin
Paris Pasqualin 2020년 12월 3일
댓글: Paris Pasqualin 2022년 6월 14일
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;

채택된 답변

Uday Pradhan
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
Gordon
Gordon 2022년 6월 13일
I get the error that numvars = 0. So it's as if still not evaluating variables.
Paris Pasqualin
Paris Pasqualin 2022년 6월 14일
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

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by