Roots - 'Zero finding' in Matlab
To find polynomial roots
(aka 'zero finding'
process), Matlab has a specific command, namely 'roots'.
polynomial is an expression of finite length built from variables and
constants, using only the operations of addition, subtraction,
multiplication, and non-negative integer exponents.
If you type on the command window:
the Matlab online help
Find polynomial roots.
ROOTS(C) computes the roots of the polynomial whose
coefficients are the elements of the
vector C. If C has N+1
components, the polynomial is C(1)*X^N +
... + C(N)*X +
This means that the coefficients of the polynomial are placed in a
vector C and the built-in function returns the corresponding roots or zeros. It is simple
to use, but care is needed when entering the coefficients of the
For example, find the roots of the equation
3x5 − 2x4 + x3
You can use the simple Matlab code:
c = [3
-2 1 2 0 -1];
And Matlab will deliver the following five zeros (x-values that produce
a function f(x) = 0):
0.5911 + 0.9284i
0.5911 - 0.9284i
-0.5694 + 0.3423i
-0.5694 - 0.3423i
There’s a couple of things to note from this example:
coefficients are listed starting with the one
corresponding to the largest
power. It is important that zero-coefficients are included
in the sequence where necessary. A polynomial of order p has p + 1 coefficients,
this is, a quadratic has three coefficients and a polynomial of degree p will have p roots.
As long as the coefficients of the polynomial are real, the roots will
be real or
occur in complex
Built-in Command fzero
The Matlab command 'fzero'
is powerful. It actually chooses which internal method should be used
to solve a given problem, and can be used for non-polynomical functions.
Let us try the form of the command
The command uses many different forms but here we are looking for a
root of the function defined in 'func.m'
near the value x
= 3 and the options are set to 'display
For example, determine the zero of the function f(x) =
3x − 2x2 sin(x), closest to x = 2.
A fast plot of the function (for exploration
purposes) results in:
So we need to set up the code:
mf = myfunction(x)
mf = 3*x
and later we may use the inline command fzero like this (no
input vector is needed)
The Matlab answer is:
ans = 1.5034
operations with polynomials
'Polynomial Roots' to home
'Polynomial Roots' to 'Matlab Cookbook II'