Lab 4 Solving Roots of Equations and Polynomials Using Packages and MATLAB

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

LAB 4

Solving roots of equations


and polynomials using
packages and MATLAB
EXCELL (ref to page 190)
Use EXCELL to locate roots of function by trial and error.

Examples 1;
1.) determine roots of f(x) = x cos x

Step 1. enter the x value in a cell of the spreadsheet.

Step 2. Introduce f(x) formulation in the cell


and used the listed x value from the first cell to determine the f(x)
value.

Step 3. Varies the x value until f(x) cell approaches zero.

Step 4. use Goal Seek function to locate the roots.


Examples 2;
Determine single root of using Goal Seek Function

f(x) = x cos x

Key in the required data in the worksheet.


Go to Data Tools.
What-If-Analysis
Goal Seek
Goal seek table will appear
Answer the required questions
Examples 3;
Determine roots of U(x,y) and V(x,y) simultaneously
using solver function.

U(x,y) = x2 + xy -10 = 0
V(x,y) = y + 3xy2 -57 = 0
initial values of x = 1 and y = 3.5
True value x = 2 and y = 3
Solution;

Step 1 Enter the initial values of x and y in the worksheet.


Step 2 Enter functions U and V in the worksheet.

Step 3 Enter sum of square of the functions U and V values.


(The result should be zero). If the value is not zero, the
function Solver can be used from the Tools menu.

Step 4 Use the function Solver and give the required


information.
MATLAB(refer to page 193)
The fzero function to locate one root of a single
function.

The syntax is;

fzero(f,xo,options)

where f is the function


xo is the initial guess
options are the optimization parameters
Example 1

Use MATLAB function fzero to find the roots of;


f(x) = x10 1

With the interval of xl = 0 and xu = 4.


The true roots are at x = -1 and 1.
Use the initial guesses of 0 and 1.3 to determine
the positive root.
With 2 initial guesses

>>xo = [0 1.3];
>>x=fzero(inline(x^10-1),xo)
x=
-1

with one initial guess:

>>xo = 0;
>>x=fzero(inline(x^10-1),xo)
x=
-1
Use MATLAB to determine the roots of
polynomials

Example 2

Determine the roots of polynomial of the


following equation;

f(x) = x5 3.5x4 + 2.75x3 + 2.125x2 - 3.875x + 1.25


>>a=[1 -3.5 2.75 2.125 -3.875 1.25];

to evaluate the polynomial function;


>>polyval(a,1)
ans =
-0.2500

to diffferentiate the polynomial;


>>polyder(a)
ans =
5.0000 -14.0000 8.2500 4.2500 -3.8750

to determine roots of the polynomial;


>>r = roots(a)
r=

You might also like