Sie sind auf Seite 1von 9

CHE555 NUMERICAL METHODS & OPTIMIZATION

LAB 2: ROOTS OF EQUATION


Task 1: Introduction to m-file
Home New script Editor
A typical m-file interface as shown below:

Task 2: TO FIND SINGLE ROOT USING MATLAB


Method 1:
(a) Type on the command window:
fx = @ (x) equation

%fx is equation name

(b) Then, use fzero command to find the root of x.


x = fzero (fx, x0)
% x0 - initial guess

Example:

f (c )

9.8 68.1
1 e ( c / 68.1)10 40
c

Prepared by Madam Rabiatul Adawiyah Abdol Aziz (2016)

Page 1

Method 2:
(a) Open m-file
(b) Type on the m-file:
function f = fx (x)

%fx is file name, later save the file name as this

f = equation ;
(c) After that, click save and run.
(d) Then, type in command window the fzero command to find the root of x.
x = fzero (fx, x0)
%fx is file name , x0 - initial guess
Example:

f (c )

9.8 68.1
1 e ( c / 68.1)10 40
c

In m-file:

Prepared by Madam Rabiatul Adawiyah Abdol Aziz (2016)

Page 2

Answer in command window:

Task 3 : TO FIND SINGLE ROOT USING EXCEL


Example:

f (c )

9.8 68.1
1 e ( c / 68.1)10 40
c

(a) Open Excel


(b) Generate the table for initial guess, function and sum of squares.

Prepared by Madam Rabiatul Adawiyah Abdol Aziz (2016)

Page 3

(c) Open Data Solver

i. Sum of squares set as Set Objective with value of 0


ii. Then, C set as Changing Variable Cells
iii. Click Solve
(d) Get the answer as:

Task 4 : TO FIND MULTIPLE ROOTS USING EXCEL


Example:

U ( x , y) x 2 xy 10
V ( x , y) y 3xy 2 57

Prepared by Madam Rabiatul Adawiyah Abdol Aziz (2016)

Page 4

(a) Open Excel


(b) Generate the table for initial guess, function and sum of squares.

(c) Open Data Solver

iv. Sum of squares set as Set Objective with value of 0


v. Then, X & Y set as Changing Variable Cells
vi. Click Solve

Prepared by Madam Rabiatul Adawiyah Abdol Aziz (2016)

Page 5

(d) Get the answer as:

Task 5 : TO FIND ROOTS OF POLYNOMIALS


Command: roots (polynomial coefficient)
Example:
1. P1(x) = x4 10x3 + 35x2 50x + 24
In matlab:

Other example:
2. P2(x) = x5 7x4 + 16x2 + 25x + 52
3. P3(x) = x4 28x3 + 289x2 1302x + 2160
Note: Please include terms whose coefficients are equal to zero.

Prepared by Madam Rabiatul Adawiyah Abdol Aziz (2016)

Page 6

Task 6 : TO FIND POLYNOMIAL EQUATION FROM KNOWN ROOTS


Command: poly (roots of polynomial)
Example:
1. Roots of polynomial: 1, 2, 3,4
In matlab:

Other example:
2. Roots of polynomial: 5, 6, 8, 9
3. Roots of polynomial: -1, -2, -3, -4+5j, -4-5j

Task 7 : TO FIND VALUE OF POLYNOMIAL EQUATION AT A SPECIFIED


VALUE
Command: polyval (polynomial equation, specified value)
Example:
1. P1 (x) = x2 5x + 6

at x = 1

Other example:
2. P2 (x) = x6 3x5 5x3 4x2 3x + 2 at x = -3
Prepared by Madam Rabiatul Adawiyah Abdol Aziz (2016)

Page 7

Task 8 : TO FIND MULTIPIES OF TWO POLYNOMIAL EQUATION


Command: conv (P1,P2)
Example:
P1(x) = x5 3x4 + 5x2 +7x + 9
P2(x) = 2x6 8x4 + 4x2 + 10x +12
In Matlab:

Task 9 : TO FIND DIVIDES OF TWO POLYNOMIAL EQUATION


Command: deconv (P2,P1)
Example:
P1(x) = x5 3x4 + 5x2 +7x + 9
P2(x) = 2x6 8x4 + 4x2 + 10x +12
In Matlab:

Prepared by Madam Rabiatul Adawiyah Abdol Aziz (2016)

Page 8

Task 10 : TO PRODUCES THE DERIVATIVE OF POLYNOMIAL EQUATION


Command: polyder (P1)
Example:
P1(x) = 2x6 8x4 + 4x2 + 10x +12
In Matlab:

Prepared by Madam Rabiatul Adawiyah Abdol Aziz (2016)

Page 9

Das könnte Ihnen auch gefallen