How can I get more than one solution with solve()?
8 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
This is my code:
syms x y;
vars = [x,y];
eqn = x^3 + y^2 == 0;
solve(eqn,vars, 'Real', true)
But it really gives me one solution: x=0 and y=0
0 commentaires
Réponses (1)
John D'Errico
le 12 Nov 2020
Modifié(e) : John D'Errico
le 12 Nov 2020
You have ONE equation, and TWO unknowns. There are infinitely many solutions. Do you expect MATLAB to generate them all? Get some coffee, a large cup, as this may take some time and memory.
Instead, the best you can do is to solve for one of the variables as a function of the other. For example, we might expect:
y = +/- sqrt(x^3);
which is what we get.
syms x y;
eqn = x^3 + y^2 == 0;
ysol = solve(eqn,y)
ysol =
(-x)^(3/2)
-(-x)^(3/2)
Or, we could parameterize it for x as a function of y.
Voir également
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!