フィルターのクリア

Solve system of equations without Symbolic Math Toolbox for Compiler

11 ビュー (過去 30 日間)
Daniel Wirth
Daniel Wirth 2022 年 5 月 12 日
回答済み: Song-Hyun Ji 2023 年 6 月 14 日
I have a system of 3 equations with 3 unknowns (X_sym, AbS_sym, AbB_sym) in my code and I want to solve it for different combinations of variables stored in vlist.
At the moment, I am using 'syms' and 'vpasolve' and it works fine:
syms AbB_sym AbS_sym X_sym
symvar_AbB_sym = parallel.pool.Constant(AbB_sym);
symvar_AbS_sym = parallel.pool.Constant(AbS_sym);
symvar_X_sym = parallel.pool.Constant(X_sym);
parfor i = 1:size(vlist,1)
X_sym = symvar_X_sym.Value;
AbS_sym = symvar_AbS_sym.Value;
AbB_sym = symvar_AbB_sym.Value;
eqns = [(X_sym*AbB_sym*AbS_sym)/(vlist(i,4)*vlist(i,5)) + 2*(X_sym*AbS_sym^2)/vlist(i,5)^2 + ...
(X_sym*AbS_sym)/vlist(i,5) + AbS_sym == vlist(i,1),...
(X_sym*AbB_sym*AbS_sym)/(vlist(i,4)*vlist(i,5)) + 2*(X_sym*AbB_sym^2)/vlist(i,4)^2 + ...
(X_sym*AbB_sym)/vlist(i,4) + AbB_sym == vlist(i,2),...
(X_sym*AbB_sym*AbS_sym)/(vlist(i,4)*vlist(i,5)) + (X_sym*AbB_sym^2)/vlist(i,4)^2 + ...
(X_sym*AbS_sym^2)/vlist(i,5)^2 + ...
(X_sym*AbB_sym)/vlist(i,4) + (X_sym*AbS_sym)/vlist(i,5) + X_sym == vlist(i,3)];
S = vpasolve(eqns,[X_sym AbB_sym AbS_sym],[0 Inf; 0 Inf;0 Inf]);
X(i,1) = S.X_sym;
AbB(i,1) = S.AbB_sym;
AbS(i,1) = S.AbS_sym;
end
However, I cannot use this approach, as I cannot compile my app into a standalone app with syms and vpasolve.
I tried looking into 'matlabfunction' according to this article:
But I don't think it is applicable here since I have a system of equations. Am I right?
How can I modify the code so it could be compiled into a standalone app?
Any help is appreciated! Thanks!

採用された回答

Torsten
Torsten 2022 年 5 月 12 日
Did you try "solve" on your system of equations with the numerical vlist coeffcients replaced also by symbolic variables ?
syms AbB_sym AbS_sym X_sym vlist1 vlist2 vlist3 vlist4 vlist5
eqns = [(X_sym*AbB_sym*AbS_sym)/(vlist4*vlist5) + 2*(X_sym*AbS_sym^2)/vlist5^2 + ...
(X_sym*AbS_sym)/vlist5 + AbS_sym == vlist1,...
(X_sym*AbB_sym*AbS_sym)/(vlist4*vlist5) + 2*(X_sym*AbB_sym^2)/vlist4^2 + ...
(X_sym*AbB_sym)/vlist4 + AbB_sym == vlist2,...
(X_sym*AbB_sym*AbS_sym)/(vlist4*vlist5) + (X_sym*AbB_sym^2)/vlist4^2 + ...
(X_sym*AbS_sym^2)/vlist5^2 + ...
(X_sym*AbB_sym)/vlist4 + (X_sym*AbS_sym)/vlist5 + X_sym == vlist3];
S = solve(eqns,[X_sym AbB_sym AbS_sym])
If this does not work, you will have to use the numerical solver "fsolve" for your system of equations.
  1 件のコメント
Daniel Wirth
Daniel Wirth 2022 年 5 月 13 日
Thanks for your answer!
Yes, I did try solving the equations with 'solve' first, but that didn't work...
I ended up going with your suggestion of using fsolve and it worked like a charm! Thanks a lot!!

サインインしてコメントする。

その他の回答 (1 件)

Song-Hyun Ji
Song-Hyun Ji 2023 年 6 月 14 日
You can get the solution in the following answers page.
- How to deploy when using 'syms' and 'solve' with function input arguments to consist the equation in MATLAB Compiler

カテゴリ

Help Center および File ExchangeSymbolic Math Toolbox についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by