Using roots() and poly() for multivariable functions
Afficher commentaires plus anciens
How would I go about using poly() and roots() to solve the roots for this multivariable function?
This is my attempt
syms z1 z2
p = poly([1 -.5 -.25 -.25])
r = root(p,z1,z2)
5 commentaires
Star Strider
le 22 Fév 2023
Modifié(e) : Star Strider
le 22 Fév 2023
I am not certain about using roots for that, however the correct result can be found symbolically —
syms z_1 z_2
Eqn = 1 - 1/2*1/z_1 - 1/4*(1/z_1*1/z_2) - 1/4*1/z_2^2
[Z_1,Z_2] = solve(Eqn)
EvalEqn1 = subs(Eqn, {z_1,z_2},{Z_1(1),Z_2(1)}) % Verify Following EDIT
EvalEqn2 = subs(Eqn, {z_1,z_2},{Z_1(2),Z_2(2)}) % Verify Following EDIT
sol1 = solve(Eqn, 'returnconditions',1)
sol = solve(Eqn, z_1, 'returnconditions', true) % Run Responding To Walter's Observation
EDIT — (22 Feb 2023 at 17:12)
I solved for both, just to see what the correct result is, and returning the conditions there produces the same result as solving for ‘z_1’. It appears that if ‘z_2’ equals -1/2 then the denominator of ‘z_2/(2*z_2 - 1)’ would be 0 with an infinite result. Using subs with the appropriate root pairs gives the expected value for the function.
Perhaps solve is just being compulsive. (My apologies for the anthropomorphism.)
.
Walter Roberson
le 22 Fév 2023
Star Strider, could you confirm something I am seeing?
sol = solve(Eqn, z_1, 'returnconditions', true)
I am being told that one of the conditions is z_2 ~= -1/2, but (A) -1/2 is one of the two specific values you had returned, and (B) I cannot see any reason why -1/2 should be a problem at all.
Dyuman Joshi
le 22 Fév 2023
Modifié(e) : Dyuman Joshi
le 22 Fév 2023
In my understanding -
syms z_1 z_2
Eqn = 1 - 1/2*1/z_1 - 1/4*(1/z_1*1/z_2) - 1/4*1/z_2^2;
[Z_1,Z_2] = solve(Eqn)
Here, it has not been specified for which variable to solve the equation. And by default, solve determines the variable via symvar, which are
symvar(Eqn)
So solve() solves for both the variable and we get explicit solutions.
In this case, a variable is specified to solve the equation for, and the solve returns the solution accordingly
sol = solve(Eqn, z_1, 'returnconditions', true)
However, I do not know why does it repeat the same condition. Edit - my bad, they are not the same condition.
Odd. Notice that when you solve for z_2 that it singles out z2 = -1/2 as a specific solution that is always true, but that when you solve for z_1 that it singles out z2 = -1/2 as a specific case in which the z1 solution does not apply.... even though there is no mathematical problem with z2 = -1/2 ...
syms z_1 z_2
Eqn = 1 - 1/2*1/z_1 - 1/4*(1/z_1*1/z_2) - 1/4*1/z_2^2;
sol1 = solve(Eqn, z_1, 'returnconditions', true)
sol1.conditions
sol2 = solve(Eqn, z_2, 'returnconditions', true)
sol2.z_2
sol2.conditions
simplify(sol2.conditions)
Walter, for z_2 = -1/2, the equation becomes null, and thus we can't solve for z_1
syms z_1 z_2
Eqn = 1 - 1/2*1/z_1 - 1/4*(1/z_1*1/z_2) - 1/4*1/z_2^2
subs(Eqn,z_2,-1/2)
Réponses (1)
Walter Roberson
le 22 Fév 2023
[N D] = numden(Eqn)
sol = root(N, z_1)
You will get
root(4*z_1*z_2^2 - z_1 - z_2 - 2*z_2^2, z_1)
But you would have followed your requirements that root() specifically be involved in the process.
Catégories
En savoir plus sur Mathematics dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!






