Matlab Calculate Roots Function
The MATLAB roots() function calculates the roots of a polynomial equation. This calculator helps you determine the roots of any polynomial you input.
What is the MATLAB roots() function?
The roots() function in MATLAB is used to find the roots of a polynomial equation. A polynomial is an expression consisting of variables and coefficients, involving only the operations of addition, subtraction, multiplication, and non-negative integer exponentiation.
The roots of a polynomial are the values of the variable that satisfy the equation. For example, the roots of the polynomial x² - 5x + 6 = 0 are x = 2 and x = 3.
The general form of a polynomial is:
aₙxⁿ + aₙ₋₁xⁿ⁻¹ + ... + a₁x + a₀ = 0
where aₙ, aₙ₋₁, ..., a₀ are coefficients and x is the variable.
How to use the roots() function
To use the roots() function in MATLAB, you need to provide the coefficients of the polynomial in descending order of powers of x. The function returns a column vector containing the roots of the polynomial.
Syntax
roots(coefficients)
where coefficients is a vector containing the coefficients of the polynomial in descending order.
Example
To find the roots of the polynomial x² - 5x + 6 = 0, you would use the following MATLAB code:
> coefficients = [1, -5, 6];
> roots(coefficients)
ans =
3
2
The output shows that the roots of the polynomial are 3 and 2.
Example calculations
Let's look at a few examples of how to use the roots() function in MATLAB.
Example 1: Quadratic Polynomial
Find the roots of the polynomial 2x² + 3x - 5 = 0.
> coefficients = [2, 3, -5];
> roots(coefficients)
ans =
1.0000
-1.5000
The roots are 1 and -1.5.
Example 2: Cubic Polynomial
Find the roots of the polynomial x³ - 6x² + 11x - 6 = 0.
> coefficients = [1, -6, 11, -6];
> roots(coefficients)
ans =
3
2
1
The roots are 3, 2, and 1.
FAQ
What is the difference between roots() and poly() functions in MATLAB?
The roots() function calculates the roots of a polynomial given its coefficients, while the poly() function generates the coefficients of a polynomial given its roots.
Can the roots() function handle complex roots?
Yes, the roots() function can handle complex roots. For example, the roots of the polynomial x² + 1 = 0 are i and -i.
What happens if I provide the coefficients in the wrong order?
If you provide the coefficients in the wrong order, the roots() function will calculate the roots of a different polynomial. Always ensure the coefficients are in descending order of powers of x.