Module (3): Finding Roots of Single Equation using Excel and MATLAB
Graphical methods, Bracket
methods and Open methods are different methods to solve the roots of a single
equation.
In Bracketing methods,
two guesses for the root are required, which must bracket the root. These
methods permanently reduce the width of the bracket, so they are said to be
always convergent. In contrast, Open Methods need either one guess for the root
or two guesses, but they don’t necessarily bracket the root.
Bracket
Methods |
Open
Methods |
Graphical Method |
Simple Fixed point |
Bisection Method |
Newton Raphson |
False Position Method |
Secant Method |
1.
Measures of Errors
There are four common measures of errors in numerical methods:
True Value=Approximation (Solution) + Error
1.
Graphical Method
A simple method for estimating the root
of
Both MatLab and Excel
can be used to find it as follows:
MatLab
1) Using linspae create
x points the potentially cover the function limits
x=linspace(-10,10,10)
2) Create the F(x)
function
3) Plot the function
Example 1:
x=linspace(4,20,20);
f=(9.81*68.1)./x.*(1-exp(-x./68.1*10))-40;
plot(x,f); grid on; axis([14,15,-0.5,0.5]);
Excel
1) Begin with two guesses that bracketing
the real root.
2) Check when
3) Take the related (x)
of the previous step as new brackets.
4) Repeat steps (3) and
(4) until getting a satisfactory result.
Example 2:
First Trail:
1.
Bisection Method
Using MATLAB to find Roots of Single Equation using Bisection method
Write a MATLAB code to find the single equation roots by using the Bisection
Method.
· The intervals are
2.5 and 3.5
· The Relative error
is 0.01
· The maximum
iteration is 50
Hint: To add the
equation as input, it should be written as
@(x)0.9*x^3-5.9*x^2+10.9*x-6
Using Excel to find Roots of Single Equation using Bisection method
Similarly,
if the condition can be used in MatLab to check the sign of the f(x) as follows
5.
Secant Method
The Newtonian method described in the
previous section depends on the function derivative. However, it can not be
implemented in some functions whose derivatives are complicated. Hence, the Secant
method uses the backward finite divided difference instead of the derivative.
It requires two approximations (x0, X1), and the connecting line (x1,f(x1)) and (x2, f(x1)) will cut x-axis to produce (x1). by repeating this step, the approximated (x) becomes closer and close, as shown in the following figure.
6.
MATLAB built-in functions to
find the root of a single equation.
fzero and roots are built-in
functions used in MATLAB to find the root of a single equation.
fzero Syntax
· fzero(@(x)equation,
x0)
In this syntax,
function uses the open method to find the root.
·
fzero(@(x)equation, [x0, x1])
In this syntax, the
function uses the bracket method to find the root. So, the two intervals must
have different sing solutions. Otherwise, it gives an error message.
Example:
use fzero build-in function to find the roots of the following equation using both
open and bracketing methods.
Note that: if the two values are not bracketing, you will receive
an error message, as shown above.
If you want to display all details of
iteration, use the optimist function as shown in the following syntax.
>> Z=optimset ('display', 'iter');
>> fzero(@(x) 0.95*x^3-5.9*x^2+10.9*x-6,2,Z)
7.
Finding roots of a single
equation using Excel Solver and Goal Seek
Goal Seek
and Solver are two beneficial functions that can be used in Excel to perform
iterations until reaching the solution. They are found in the Data Ribbon of
Excel, as shown below.
No comments:
Post a Comment