factorization of Multivariate polynomial
Show older comments
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')
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')
‘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
I don't see any factorization when running your command (see above).
Bruno Luong
on 23 Mar 2023
Bruno Luong
on 23 Mar 2023
Bruno Luong
on 23 Mar 2023
Edited: Bruno Luong
on 23 Mar 2023
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)
Bruno Luong
on 23 Mar 2023
Manikanta Aditya
on 23 Mar 2023
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.
Bruno Luong
on 23 Mar 2023
Manikanta Aditya
on 23 Mar 2023
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.
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)
Bruno Luong
on 23 Mar 2023
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)
[a,b] = solve(C == 0,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
Q = P/y^2;
syms u
Q = simplify(subs(Q,x,u*y))
QF = factor(Q,'FactorMode','full')
simplify(y*subs(QF,u,x/y))
This one seems a little more general, though still arguably a hack. It can at least work for bivariate polynomials.
4 Comments
Bruno Luong
on 17 Mar 2023
Edited: Bruno Luong
on 17 Mar 2023
John D'Errico
on 23 Mar 2023
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.
yogeshwari patel
on 2 Dec 2023
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 ?
Walter Roberson
on 2 Dec 2023
(It appears the question referred to is https://www.mathworks.com/matlabcentral/answers/2054744-how-to-find-the-factors-of-the-polynomial-in-one-than-one-variable?s_tid=srchtitle )
Categories
Find more on Symbolic Math Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

