Solve system of equations without Symbolic Math Toolbox for Compiler
11 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Daniel Wirth
le 12 Mai 2022
Réponse apportée : Song-Hyun Ji
le 14 Juin 2023
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!
0 commentaires
Réponse acceptée
Torsten
le 12 Mai 2022
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.
Plus de réponses (1)
Song-Hyun Ji
le 14 Juin 2023
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
0 commentaires
Voir également
Catégories
En savoir plus sur Symbolic Math Toolbox dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!