Polynomial Factorisation
% Definition of the polynomial
syms x
p = 2*x^3 - 14*x - 12; % PLACE THE POLYNOMIAL HERE
% Automatic factorization of the polynomial
factored_form = factor(p);
% Get the leading coefficient
coefficients = coeffs(p, 'All'); % Store all coefficients in an array
leading_coefficient = coefficients(1); % The leading coefficient (2)
% Find the roots of the polynomial
roots_of_p = double(solve(p == 0, x));
% Display the original polynomial
disp('Original polynomial:');
disp(p);
% Display the factored form in the desired format with correct signs
disp('Factored form of the polynomial:');
fprintf('%.1f * ', leading_coefficient);
for i = 1:length(roots_of_p)
root = roots_of_p(i);
if root > 0
fprintf('(x - %.1f)', root);
else
fprintf('(x + %.1f)', abs(root));
end
end
fprintf('\n');
% Display the final factored result
disp('Final factored result:');
disp(factored_form);
Example [2, x - 3, x + 2, x + 1] , first number is
never root
FActorisation with denominator
% Define the symbolic variable
syms x
% Define the numerator and denominator polynomials directly
numerator = 2*x^5 - 4*x^4 - 16*x^3; % Replace with your numerator polynomial
denominator = x + 2; % Replace with your denominator polynomial
% Perform polynomial long division
[quotient, remainder] = quorem(numerator, denominator); % Use quorem to get
quotient and remainder
% Display the results of the division
disp('Quotient of the polynomial division:');
disp(quotient);
disp('Remainder of the polynomial division:');
disp(remainder);
% Get the leading coefficient of the quotient
leading_coefficient = coeffs(quotient, 'All'); % Get all coefficients
if ~isempty(leading_coefficient)
leading_coefficient = leading_coefficient(1); % The leading coefficient of the quotient
disp('Leading coefficient:');
disp(leading_coefficient);
else
disp('No leading coefficient (quotient is zero).');
end
% Find the roots of the quotient polynomial
roots_of_quotient = double(solve(quotient == 0, x));
% Display the factored form in the desired format with correct signs
disp('Factored form of the quotient polynomial:');
fprintf('%.1f * ', leading_coefficient);
for i = 1:length(roots_of_quotient)
root = roots_of_quotient(i);
if isreal(root)
if root > 0
fprintf('(x - %.1f)', root);
else
fprintf('(x + %.1f)', abs(root));
end
else
fprintf('(x - %.1f + %.1fi)', real(root), imag(root)); % Handle complex roots
end
end
fprintf('\n');
% Display the final quotient polynomial
disp('Final quotient polynomial:');
disp(quotient);