factorization of Multivariate polynomial

Hello, I want to factorize a multivariate polynomial in a complex field. I just don't understand why the result of this simple polynomial
syms x y
F = factor(x^2+y^2,'FactorMode','complex')
F = 
and not (x + i*y)*(x - i*y)?
Is there any third-party toolbox/code that can carry out the problem of factorization multivariate polynomial?
NOTE: in 1D it's equivalent to finding the roots of the polynomial3

Answers (2)

Hi Bruno,
As per my understanding, you want to factorize a polynomial in a complex field, and you are getting result of this simple polynomial.
The reason why the factorization of x^2+y^2 using ‘factor’ function in MATLAB returns a different result than (x + i*y)*(x - i*y) is because ‘factor’ function only returns factors with real coefficients by default.
Since the factors (x + i*y) and (x - i*y) have complex coefficients, they are not returned by the ‘factor’ function. If you want to obtain factors with complex coefficients, you can use the factor function with the option 'FactorMode','full'.
syms x y
F = factor(x^2+y^2,'FactorMode','full')
F = 
‘Factormode’ parameter set to ‘full’ will include complex conjugate pair of factors.
For further reference, please go through this link for knowing about symbolic factors:
I hope this resolves the issue you are facing.

14 Comments

Torsten
Torsten on 17 Mar 2023
Edited: Torsten on 17 Mar 2023
I don't see any factorization when running your command (see above).
@Manikanta Aditya I miss somethng it does not return (x+i*y)*(x-i*y) as expected
syms x y
F = factor(x^2+y^2,'FactorMode','full')
F = 
@Manikanta Aditya can you please confirm that factorization of x^2+y^2 in complex field is curretly out of reach by factor function ?
Bruno Luong
Bruno Luong on 23 Mar 2023
Edited: Bruno Luong on 23 Mar 2023
I'm sorry but I consider the issue is not resolve, my actual polynomial is more complicated than x^2+y^2. . I must find a third party toolbox that can handle corretly the factorization in complex field (not finite field and integer fraction).
Actually I have a candidate toolbox, I just want to know if MATLAB can solve this, obviously not entirely.
This doesn't factorize the polnomial in complex field
syms x y;
p = x^2 + y^2;
roots_p = roots(coeffs(p));
factors_p = prod(x + y - roots_p)
factors_p = 
Hi,
The command roots(coeffs(p)) calculates the roots of the polynomial p assuming that the coefficients are real. However, this assumption is not valid in the complex field, and therefore the roots obtained may be incorrect.
To correctly compute the roots of p in the complex field, you can use the command solve(p). This command computes the roots of p using a symbolic solver that can handle complex numbers. Here is the corrected code:
syms x y;
p = x^2 + y^2;
roots_p = solve(p);
factors_p = prod(x + y - roots_p)
The solve command returns a vector of two complex numbers that correspond to the roots of p. The prod command then computes the product of the factors (x+y-root_i) for each root root_i, which gives the factorization of p. Note that the factors are complex conjugates of each other, which is a general property of quadratic polynomials with complex coefficients.
I can't follow the logic, but the result is incorrect, if it is the last line must return 0
syms x y;
p = x^2 + y^2;
roots_p = solve(p);
factors_p = prod(x + y - roots_p)
factors_p = 
simplify(factors_p-p)
ans = 
Also it seem you head toward John's workaround below.
This method won't work for more complex polynomial.
It seems that there is a mistake in the calculation of factors_p. The product of x+y-roots_p should be equal to x+y-roots_p(1)*x+y-roots_p(2) if roots_p contains two distinct roots.
In your case, the expression for factors_p should be:
factors_p = (x+y-roots_p(1))*(x+y-roots_p(2))
This should give you the correct factors of p in terms of x and y.
Then, when you simplify factors_p-p, you should get 0 if the calculation is correct. Here's the updated code with the corrected expression for factors_p:
syms x y;
p = x^2 + y^2;
roots_p = solve(p);
factors_p = (x+y-roots_p(1))*(x+y-roots_p(2));
simplify(factors_p-p)
This should give you 0 as the output, indicating that the calculation is correct.
No it is NOT given 0. I believe threre is NOT misktake, just your logic of decomposition is unproven and incorrect @Manikanta Aditya, there is not equality - at least I don't see it - between P and product of (x+y-root(P))
syms x y;
p = x^2 + y^2;
roots_p = solve(p);
factors_p = (x+y-roots_p(1))*(x+y-roots_p(2));
simplify(factors_p-p)
ans = 
MATLAB output is totally correct, it can be verified by hand.
syms x y;
p = x^2 + y^2;
The following line isn't actually a documented syntax of solve. There is a note in the inputs section that says "By default, solve uses the variable determined by symvar." I think that should really be symvar(eqn,1). Contrast with diff and the very first syntax and its description.
roots_p = solve(p);
Anyway, this line actually soved for symvar(p,1), so the correct expression would be
factors_p = prod(symvar(p,1) - roots_p)
factors_p = 
@Paul, this is similar to @John D'Errico solution but without doing explicit division. This is neat, thanks.

Sign in to comment.

This is a bit of a hack of course, since factor seemingly should have solved the problem with the appropriate setting. The problem with the complex FactorMode is the polynomial is not one with constant coefficients.
syms x y a b
C = coeffs(x^2 + y^2 - (x + a*y)*(x + b*y),x)
C = 
[a,b] = solve(C == 0,a,b)
a = 
b = 
Thus finding the two solutions. Pick either one to factor the original polynomial.
As I said, a hack. But perhaps another idea is to non-dimensionalize the problem, factoring out the highest order of one variable. Essentially, divide by y^2 below. So we would have
P = x^2 + y^2
P = 
Q = P/y^2;
syms u
Q = simplify(subs(Q,x,u*y))
Q = 
QF = factor(Q,'FactorMode','full')
QF = 
simplify(y*subs(QF,u,x/y))
ans = 
This one seems a little more general, though still arguably a hack. It can at least work for bivariate polynomials.

4 Comments

Bruno Luong
Bruno Luong on 17 Mar 2023
Edited: Bruno Luong on 17 Mar 2023
Thanks. But my actual problem is not really this simple polynomial, it is a more complex with three variables to start with.
I just want to figure out if MATLAB factor is able to do correctly the work.
Obviously not for whatever reason.
PS: For fun, x^2+y^2+z^2 is actually irreducible in C[x,y,z].
Yes, I accept that. I was just thinking there might be some tricks like the one I show that would be helpful in some cases.
Before putting up the question I already gone through the above mention answer. Why we cant direct use the comammnad why to divide the expression by y^2 .Convert it into one variable and then substitute again.
Is it so that it didnt work for two variable ?

Sign in to comment.

Categories

Products

Release

R2022b

Asked:

on 6 Mar 2023

Commented:

on 2 Dec 2023

Community Treasure Hunt

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

Start Hunting!