The word roots has many meanings. Today I'd like to look at mathematical roots.
What are roots?
Roots are values or variables that cause a function to equal zero. For example, in the equation, y(x)=(x+2)(x-4), x=-2 and x=4 are roots of the function y(x) because these values make the function evaluate to zero.
Graphically, real roots can be found on plots as the x values where y is equal to zero. When searching for a root in a program such as Matlab, you'll most likely need to make a reasonable estimate as to where the root lies. You can do this by plotting the function first then eye-balling. A valid bracket on the root would span the root. The sign of the function is different at the lower and upper side of the bracket. Keep in mind that you're graphics may contain multiple roots. For continuous functions, they'll contain at least one root.
Repeated roots in even numbers will cause the function to reach zero, but not cross the zero axis. To find repeated roots, methods depending on bracketing cannot be used since the function does not change signs at the location of the root.
We can find the roots of a function several ways. One, of course, is to do it by hand. Another is to use a couple core Matlab commands to do it for you.
Let's look at what both entail. First, by hand...
One method to finding roots by hand is bisection.
Here are the steps:
1. Start with a bracket (this is the range of x values where the sign of the function changes from one side to the other).
2. Evaluate the function at the end points.
3. Find the midpoint and evaluate the function at the midpoint.
4. Determine where the function changes sign (between the lower bracket and the midpoint or between the midpoint and the upper bracket).
5. Reassign the lower or upper bracket to the midpoint value so that the new bracket values still bracket the point where the function changes sign.
6. Continue to evaluate the midpoint and reassign brackets until the roots have been found to the desired accuracy.
--For this method to work, you need to be able to determine a solid starting bracket. It is also useful to be able to figure the x-tolerance (0.5*(xr-xl)) and the f-tolerance (|f(xm)|).
Another very useful method to finding roots by hand is the Newton-Raphson Method.
This method evaluates the derivative of a function at the estimate of the root, then follows a tangent line to the x-axis.
Here are the steps:
1. If xk is the current estimate of the root, and xk+1 is the next estimate of the root, the next estimate is found using the following equation (derived by finding where the slope crosses zero):
1. roots function.
*Many thanks to Dr. G in Duke University's Pratt School of Engineering for the information contributing to this post.
What are roots?
Roots are values or variables that cause a function to equal zero. For example, in the equation, y(x)=(x+2)(x-4), x=-2 and x=4 are roots of the function y(x) because these values make the function evaluate to zero.
Graphically, real roots can be found on plots as the x values where y is equal to zero. When searching for a root in a program such as Matlab, you'll most likely need to make a reasonable estimate as to where the root lies. You can do this by plotting the function first then eye-balling. A valid bracket on the root would span the root. The sign of the function is different at the lower and upper side of the bracket. Keep in mind that you're graphics may contain multiple roots. For continuous functions, they'll contain at least one root.
Repeated roots in even numbers will cause the function to reach zero, but not cross the zero axis. To find repeated roots, methods depending on bracketing cannot be used since the function does not change signs at the location of the root.
We can find the roots of a function several ways. One, of course, is to do it by hand. Another is to use a couple core Matlab commands to do it for you.
Let's look at what both entail. First, by hand...
One method to finding roots by hand is bisection.
Here are the steps:
1. Start with a bracket (this is the range of x values where the sign of the function changes from one side to the other).
2. Evaluate the function at the end points.
3. Find the midpoint and evaluate the function at the midpoint.
4. Determine where the function changes sign (between the lower bracket and the midpoint or between the midpoint and the upper bracket).
5. Reassign the lower or upper bracket to the midpoint value so that the new bracket values still bracket the point where the function changes sign.
6. Continue to evaluate the midpoint and reassign brackets until the roots have been found to the desired accuracy.
--For this method to work, you need to be able to determine a solid starting bracket. It is also useful to be able to figure the x-tolerance (0.5*(xr-xl)) and the f-tolerance (|f(xm)|).
Another very useful method to finding roots by hand is the Newton-Raphson Method.
This method evaluates the derivative of a function at the estimate of the root, then follows a tangent line to the x-axis.
Here are the steps:
1. If xk is the current estimate of the root, and xk+1 is the next estimate of the root, the next estimate is found using the following equation (derived by finding where the slope crosses zero):
xk+1=xk-[f(xk)/f'(xk)]
2. Start with a guess for the root.
3. Evaluate the function at the guess and check to see if accuracy has been reached -- if so, stop. If not, continue through to the next guess.
4. Calculate the next estimate of the root using the above equation.
5. Determine if the f-tolerance, x-tolerance, or max number of guesses has been reached. If so, stop. If not, repeat.
-- This is a quicker method of finding the roots than bisection. If you set everything up in a nice chart, tracking every new guess and evaluation becomes much easier. You can find pretty complex roots using this method. And instead of a bracketed guess, you need only make one initial estimate of the root.
x-tolerance for N-RM is (|x(N)-x(N+1)|) and the f-tolerance is (|f(x(N))|).
And what about the built-in Matlab functions?
1. roots function.
This function is useful in that it can find all of the roots, even the imaginary ones. Let's go through an example of how to use this function find the roots of the polynomial x^3-6x^2-72x-27.
First, you need to represent it in a way Matlab can read it. Take the coefficients and do this:
P=[1 -6 -72 -27]
The roots will be returned in a column vector by:
R = roots(P)
R =
12.1229
-5.7345
-0.3884
2. fzero function.
This function can be used to find the root of a continuous function of one variable. It's pretty versatile, so let's look at a couple examples. These can be found on the Mathworks site directly.
Example 1
Calculate π by finding the zero of the sine function near 3.
x = fzero(@sin,3) x = 3.1416
Example 2
To find the zero of cosine between 1 and 2
x = fzero(@cos,[1 2]) x = 1.5708
Note that cos(1) and cos(2) differ in sign.
Example 3
To find a zero of the function f(x) = x3 – 2x – 5, write an anonymous function f:
f = @(x)x.^3-2*x-5;
Then find the zero near 2:
z = fzero(f,2) z = 2.0946
Because this function is a polynomial, the statement roots([1 0 -2 -5]) finds the same real zero, and a complex conjugate pair of zeros.
2.0946 -1.0473 + 1.1359i -1.0473 - 1.1359i
*Many thanks to Dr. G in Duke University's Pratt School of Engineering for the information contributing to this post.
No comments:
Post a Comment