How to use vpasolve to solve a vector of equations (Without using loops)?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi,
Rather than using vpasolve to solve a single equation (for a single variable say x1), I would like to efficiently solve a number of similar equations (where x1 enters equation1, x2 enters equation2, x3 enters equation 3 etc). It's not clear to me why first declaring a vector of symbols (one for each equation) and then calling vpasolve on the vectorized code does not work. For example, the pseudo code is roughly as follows:
(1) x=sym('x%d', [NumEquations 1]);
(2) create matrix VectorEquations where x1 enters the expression in the first row, x2 enters the expression in the second row, x3 enters the expression for the third row etc
(3) vpasolve(VectorEquations==zeros(length(VectorEquations),1), x)
_____
Basically, the third step above attempts to call vpasolve to each row of VectorEquations, but it's unclear to me why the third line above fails to work. Do you have any thoughts or suggestions?
2 commentaires
Jaynik
le 21 Sep 2023
Hi Sherry,
Based on my understanding of the pseudo code you provided, you are trying to achieve this:
NumEquations = 3;
x = sym('x%d', [NumEquations 1]);
VectorEquations = [x(1) - 8; x(2) - 3; x(3) - 4]; %Some sample equations, works even for equations with degrees > 1
ans = vpasolve(VectorEquations == zeros(length(VectorEquations), 1), x);
I tried this on MATLAB R2023a and it seems to work correctly. It would be helpful if you can check the code for bugs or update your MATLAB to the latest version.
Thanks,
Jaynik
Dyuman Joshi
le 21 Sep 2023
"but it's unclear to me why the third line above fails to work."
What does "fails to work" mean in this context? Please specify.
Réponses (0)
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!