problem with symbolic factorization with two symbols

The output is not a factorized one. I want this form : (s+s1)*(s+s2)*(s+s3). What is the problem?
syms s K
factor(s^3 + 10*s^2 + (21+K)*s + 4*K, [s, K],'FactorMode','full')
The output is
4*K + 21*s + K*s + 10*s^2 + s^3

1 commentaire

It is factorized according to the inputs given.
From the documentation - F = factor(x,vars) returns an array of factors F, where vars specifies the variables of interest. All factors not containing a variable in vars are separated into the first entry F(1). The other entries are irreducible factors of x that contain one or more variables from vars.
Note the last sentence.
What is the expected output from the vectorization?

Connectez-vous pour commenter.

 Réponse acceptée

John D'Errico
John D'Errico le 21 Oct 2023
Modifié(e) : John D'Errico le 21 Oct 2023
That you want to see a simple set of factors is not relevant. You essentially need to obtain the roots of this cubic polynomial in s, where K is a parameter, which would give you that factorization.
syms s K
sroots = solve(s^3 + 10*s^2 + (21+K)*s + 4*K,s,'maxdegree',3)
sroots = 
As you can see, they are fairly messy, and depending on the value of K, they may well be complex even if K is real. This is expected for any cubic polynomial, that we may find exactly two conjugate complex roots.
The factors now are just
prod(s-sroots)
ans = 
We can expand that to show the result recovers your original polynomial.
simplify(expand(ans))
ans = 
Finally, why did not factor understand what you wanted to see? You gave it two variables s and K. How should factor possibly know that you wanted it to do what I just did, essentially, that s is the variable of interest, and K a symbolic parameter in the problem? Software cannot read your mind, at least, not yet.

7 commentaires

It also doesn't seem to work if you only specify s instead of [s,K] in
syms s K
factor(s^3 + 10*s^2 + (21+K)*s + 4*K, s,'FactorMode','full')
ans = 
Actually at first i tried with s only. After that i tried with both. I forgot to undo the changes before i put it in here sorry for that and thanks all for the help.
I think the problem is, even though factor seems like it should solve this, it looks for only more obvious factors. Can factor handle a simpler problem? Well, yes.
syms x
factor(x^2 + 4*x +4,x)
ans = 
How about this one? It handled that one.
syms K
factor(x^2 - 4*K*x + 4*K^2,x)
ans = 
But what if I give it something slightly less obvious?
factor(x^2 + 4*K^2 - 4*K,x)
ans = 
So factor was unable to solve even that one, even though we can write it simply enough in terms of sqrt(-4*K^2+4*K). Yet solve would handle it with not even a sweat.
I feel that the question should be - Why is factor() not able to do so?
Maybe I should raise a query to TMW about this.
Torsten
Torsten le 21 Oct 2023
Modifié(e) : Torsten le 21 Oct 2023
Maybe it factors only expressions with "nice" outcome :-)
Factorization of expressions with real components (or components of unknown reality) traditionally only proceeds to the point where any further factoring would require use of imaginary components.
syms x
factor(x^2 + 1)
ans = 
factor(x^2 - 1)
ans = 
P1 = expand((x-2) * (x+7) * (x-7))
P1 = 
factor(P1)
ans = 
P2 = expand((x-2) * (x+7i) * (x-7i))
P2 = 
factor(P2)
ans = 
P3 = expand((x-2i) * (x+7) * (x-7))
P3 = 
factor(P3)
ans = 
I cannot see a rule when "factor" works and when if does not work.
syms x
P2 = expand((x-2) * (x+7i) * (x-7i))
P2 = 
factor(P2,x,'FactorMode','complex')
ans = 

Connectez-vous pour commenter.

Plus de réponses (1)

Here are the factors:
syms s K
eqn = s^3 + 10*s^2 + (21+K)*s + 4*K == 0;
factors = solve(eqn,s,'MaxDegree',3)
factors = 

2 commentaires

Shouldn't the factors be
s - roots_of_equation
Yes, I should have said: -s1, -s2 and -s3 from the factorization (s+s1)*(s+s2)*(s+s3).

Connectez-vous pour commenter.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by