Using roots() and poly() for multivariable functions

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])
p = 1×5
1.0000 0 -0.6875 -0.2812 -0.0312
r = root(p,z1,z2)
Error using sym/root
First argument must be scalar.

5 commentaires

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
Eqn = 
[Z_1,Z_2] = solve(Eqn)
Z_1 = 
Z_2 = 
EvalEqn1 = subs(Eqn, {z_1,z_2},{Z_1(1),Z_2(1)}) % Verify Following EDIT
EvalEqn1 = 
0
EvalEqn2 = subs(Eqn, {z_1,z_2},{Z_1(2),Z_2(2)}) % Verify Following EDIT
EvalEqn2 = 
0
sol1 = solve(Eqn, 'returnconditions',1)
sol1 = struct with fields:
z_1: z_2/(2*z_2 - 1) parameters: [1×0 sym] conditions: z_2 ~= -1/2 & z_2 ~= 1/2
sol = solve(Eqn, z_1, 'returnconditions', true) % Run Responding To Walter's Observation
sol = struct with fields:
z_1: z_2/(2*z_2 - 1) parameters: [1×0 sym] conditions: z_2 ~= -1/2 & z_2 ~= 1/2
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.)
.
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.
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)
Z_1 = 
Z_2 = 
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)
ans = 
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)
sol = struct with fields:
z_1: z_2/(2*z_2 - 1) parameters: [1×0 sym] conditions: z_2 ~= -1/2 & z_2 ~= 1/2
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 = struct with fields:
z_1: z_2/(2*z_2 - 1) parameters: [1×0 sym] conditions: z_2 ~= -1/2 & z_2 ~= 1/2
sol1.conditions
ans = 
sol2 = solve(Eqn, z_2, 'returnconditions', true)
sol2 = struct with fields:
z_2: [2×1 sym] parameters: [1×0 sym] conditions: [2×1 sym]
sol2.z_2
ans = 
sol2.conditions
ans = 
simplify(sol2.conditions)
ans = 
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
Eqn = 
subs(Eqn,z_2,-1/2)
ans = 
0

Connectez-vous pour commenter.

Réponses (1)

[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

Question posée :

le 22 Fév 2023

Commenté :

le 23 Fév 2023

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by