How to use vpasolve to solve a vector of equations (Without using loops)?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Jaynik
il 21 Set 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
il 21 Set 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.
Risposte (0)
Vedere anche
Categorie
Scopri di più su Symbolic Math Toolbox in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!