Evaluating polynomial functions to get integer as answer
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Rodrigo Toledo
il 4 Apr 2021
Modificato: Walter Roberson
il 4 Apr 2021
I am trying to evaluate:
syms x y
eq = (x^2 + y^3 == 31)
solve(eq)
eqs = [x^2 + y^3 == 31, x^2 == 31 - y^3]
S = solve(eq,[x y])
S.x and S.y still not 2 and 3
i am expecting to get as answer two integer: x=2 and y=3. How can i do it?
Thanks
0 Commenti
Risposta accettata
Walter Roberson
il 4 Apr 2021
Modificato: Walter Roberson
il 4 Apr 2021
syms x y integer
eq = (x^2 + y^3 == 31)
solx = solve(eq,x,'returnconditions',true)
soly = solve(solx.conditions)
X = subs(solx.x,y,soly)
Y = soly
Caution: this kind of process will not generally attempt to find more than one solution for solx.conditions. But you could
soly = solve(eq,y,'returnconditions',true)
solx = arrayfun(@solve, soly.conditions, 'uniform', 0)
X = solx{2}
Y = subs(soly.y(2), x, X)
0 Commenti
Più risposte (1)
darova
il 4 Apr 2021
solve can be used for simple problems. Use fsolve or vpasolve to get numerical results
1 Commento
Walter Roberson
il 4 Apr 2021
Not the point. The point is that solve() is having difficulty processing integer constraints in this case. fsolve and vpasolve have no chance of processing integer constraints.
Vedere anche
Categorie
Scopri di più su Symbolic Math Toolbox in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!