Solve system of equations without Symbolic Math Toolbox for Compiler
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Daniel Wirth
el 12 de Mayo de 2022
Respondida: Song-Hyun Ji
el 14 de Jun. de 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 comentarios
Respuesta aceptada
Torsten
el 12 de Mayo de 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.
Más respuestas (1)
Song-Hyun Ji
el 14 de Jun. de 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 comentarios
Ver también
Categorías
Más información sobre Symbolic Math Toolbox en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!