Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 33

NUMERICAL METHODS

WITH COMP. APPLICATION

ES 22
LABORATORY MANUAL

Engr. Rey M. Lagrada


Roselle Joy A. Dela Cruz

June 2019
NUMERICAL METHODS
WITH COMP. APPLICATION

ES 22
LABORATORY MANUAL

Name of Student: ______________________________________________

ID Number: ______________________________________________

Course and Year: ______________________________________________

Section and Time: ______________________________________________

Group Number: ______________________________________________

Instructor: ______________________________________________

GUIDE LINES FOR THE EXPERIMENTS AND REPORT PREPARATION


1. Preparation for the experiment:

Before conducting the experiment, the student is required to have read the experiment

background and procedure from the experiment manual and studied the related theory. The lab

instructor may, during the experiment, ask students questions pertaining to the procedure and theory.

The lab instructor may give negative points to and even prevent an unprepared student from conducting

the experiment. Tardy students may not be allowed to perform the experiment.

2. Laboratory teams:

The class will be divided in teams of three or four students. The composition of the teams (which

students will team up) is left to the preference of the students, but the lab instructor makes the ultimate

decision as to each team's composition. Each lab experiment requires a report. The lab reports are due

on the next lab meeting. The lab report for the final experiment is due a week after the final lab

meeting. Each team submits one report per experiment (unless otherwise required). The grade of the

report is given to all members of the team. Late reports are penalized by taking 5 points off per each day

past the due date of the report. The other grade components of the experiments are given to the

students individually. If a student misses or is dismissed from an experiment, the grade of that student

shall be zero for that experiment.

3. Preparation of the report:


The report must be hand-written. Tables showing data or results, as well as figures and graphs

may be produced electronically and embedded in the main body (e.g. using MATLAB or MS-Excel, MS-

Visio). Include captions and titles for figures, graphs and tables as well as numbers for equations. The

preferred language style is the use of the present tense and third person. The report must contain the

following sections:

a) Cover page: Include number and title of the experiment, date the experiment was performed

and the names of the team members.

b) Objective: Give a short description of the purpose of the experiment.

c) Theoretical background: Give a brief description of the relevant theory.

d) The experimental procedure: Summarize what was done for each experiment procedure.

Report the measurement and other experimental data. Tabulate measurements if necessary.

Include table number and title over tables.

(e) Analysis of experimental data: Analyze the data. Compare with theoretical results. Produce

graphs using MATLAB or MS-Excel and embed the graph figure into the main body of the report.

Include figure number and caption. Label axis. Show units. Tables and graphs should appear

inserted in the text close to the place they are first mentioned and in the same section. Add

remarks and calculations on each procedure if necessary.

f) Conclusions: Summarize the experiment and the results. Discuss the factual knowledge gained.
Experiment No.

Basic Features of MATLAB 1


Electrical Engineering

Introduction
MATLAB is a high-level language and interactive environment for numerical computation,
visualization, and programming. Using MATLAB, you can analyse data, develop algorithms, and create
models and applications. The language, tools, and built-inmath functions enable you to explore
multiple approaches and reach a solution faster than with spread sheets or traditional programming
languages, such as C/C++ or Java. You can use MATLAB for a range of applications, including signal
processing and communications, image and video processing, control systems, test and measurement,
computational finance, and computational biology. More than a million engineers and scientists in
industry and academia use MATLAB, the language of technical computing.
History
 Developed primarily by Cleve Moler in the 1970'sDerived from FORTRAN subroutines LINPACK and
EISPACK, linear and eigenvalue systems.
 Developed primarily as an interactive system to access LINPACK and EISPACK.
 Gained its popularity through word of mouth, because it was not socially distributed.
 Rewritten in C in the 1980's with more functionality, which include plotting routines.
 The Math Works Inc. was created (1984) to market and continue development of MATLAB.
Strengths
 MATLAB may behave as a calculator or as a programming language
 MATLAB combine nicely calculation and graphic plotting.
 MATLAB is relatively easy to learn
 MATLAB is interpreted (not compiled), errors are easy to fix
 MATLAB is optimized to be relatively fast when performing matrix operations
 MATLAB does have some object-oriented elements
Weaknesses
 MATLAB is not a general purpose programming language such as C, C++, or FORTRAN
 MATLAB is designed for scientific computing, and is not well suitable for other applications
 MATLAB is an interpreted language, slower than a compiled language such as C++
 MATLAB commands are specific for MATLAB usage. Most of them do not have a direct equivalent
with other programming language commands
Competition
One of MATLAB's competitors is Mathematica the symbolic computation program.MATLAB is more
convenient for numerical analysis and linear algebra. It is frequentlyused in engineering community.
Mathematica has superior symbolic manipulation, making it popular among physicists. There are other
competitors: Scilab, GNU Octave, and Rlab
Experiment No.

Basic Features of MATLAB 1


Electrical Engineering

Key Features
 It is a high-level language for numerical computation, visualization and application
development.
 It also provides an interactive environment for iterative exploration, design and problem
solving.
 It provides vast library of mathematical functions for linear algebra, statistics, Fourier analysis,
filtering, optimization, numerical integration and solving ordinary differential equations.
 It provides built-in graphics for visualizing data and tools for creating custom plots.
 MATLAB's programming interface gives development tools for improving code quality,
maintainability, and maximizing performance.
 It provides tools for building applications with custom graphical interfaces.
 It provides functions for integrating MATLAB based algorithms with external applications and
languages such as C, Java, .NET and Microsoft Excel.
MATLAB's Power of Computational Mathematics
MATLAB is used in every facet of computational mathematics. Following are some commonly used
mathematical calculations where it is used most commonly:
 Dealing with Matrices and Arrays
 2-D and 3-D Plotting and graphics
 Linear Algebra
 Algebraic Equations
 Non-linear Functions Statistics
 Data Analysis
 Calculus and Differential Equations
 Numerical Calculations
 Integration
 Transforms
 Curve Fitting
 Various other special functions
Uses of MATLAB
MATLAB is widely used as a computational tool in science and engineering encompassing the fields of
physics, chemistry, math and all engineering streams. It is used in a range of applications including:
 Signal processing and Communications
 Image and video Processing
 Control systems
 Test and measurement
 Computational finance
 Computational biology
Experiment No.

Basic Features of MATLAB 1


Electrical Engineering

Understanding the MATLAB Environment


MATLAB development IDE can be launched from the icon created on the desktop. The main working
window in MATLAB is called the desktop. When MATLAB is started, the desktop appears in its default
layout:

The desktop includes these panels:


Current Folder - This panel allows you to access the project folders and files.

Command Window - This is the main area where commands can be entered at the command line. It is
indicated by the command prompt (>>).
Experiment No.

Basic Features of MATLAB 1


Electrical Engineering

Workspace - The workspace shows all the variables created and/or imported from files.

Command History - This panel shows or rerun commands that are entered at the command line.
Experiment No.

Basic Features of MATLAB 1


Electrical Engineering

You are now faced with the MATLAB desktop on your computer, which contains the prompt (>>) in the
Command Window. Usually, there are 2 types of prompt:
>>For full version
DU> for educational version
Note:
1. To simplify the notation, we will use this prompt, >>, as a standard prompt sign, though our
MATLAB version is for educational purpose.
2. MATLAB adds variable to the workspace and displays the result in the Command Window.
Managing workspace and file commands
Experiment No.

Basic Features of MATLAB 1


Electrical Engineering

Commonly used Operators and Special Characters


MATLAB supports the following commonly used operators and special characters:
Experiment No.

Basic Features of MATLAB 1


Electrical Engineering

Note:
If you end a statement with a semicolon, MATLAB performs the computation, butsuppresses the
display of output in the Command Window.
Special Variables and Constants
MATLAB supports the following special variables and constants:

Naming Variables
Variable names consist of a letter followed by any number of letters, digits or underscore. MATLAB is
case-sensitive. Variable names can be of any length; however, MATLAB uses only first N characters,
where N is given by the function namelengthmax.
Saving Your Work
The save command is used for saving all the variables in the workspace, as a file with .mat extension,
in the current directory. For example, save myfile You can reload the file anytime later using the load
command. load myfile
Experiment No.

Basic Features of MATLAB 1


Electrical Engineering

Date Performed: __________


Time Started: __________
Time Finished: __________

Objective:
 To Know the history and features of MATLAB
 To Know the local environment of MATLAB

Materials Required:
 MATLAB R2013a.
 Windows 7/XP SP2.

Procedure:
1. Open MATLAB and click on it on the start menu.
2. In the command window, type the command define below and then hit enter to run the
command.
a) Define the following column arrays in MATLAB:𝑎 = (24) 𝑎𝑛𝑑 𝑏 = (31)
Then issue the following commands:
a’ a * b’ a’ * b a .* b 3 .* b
b) Perform the following operation : a*b
c) Perform the following:
c= a+b
d= a+b;
3. Do not forget to save the program you created.
4. Print a hard copy of the program you created for oral defense.
5. Always double check before transmitting your files.
Experiment No.

Basic Features of MATLAB 1


Electrical Engineering

Questions:
1. From command A, what do each of these three operators ( ’ * .*)do?

2. From command B, what is the error message and what does it mean? What is the correct fix?

3. From command C, what does the ; do?

Conclusion:
Experiment No.

Study of Basic Matrix


Operations 2
Electrical Engineering

Discussion:

Common tools: % and ;

• % indicates a comment, not a command to be executed MATLAB ignores comments. % can be placed
at the end of an executable line to comment on that line
>> weight=input(‘give weight’); %getting weight
• a ; following an assignment will suppress display of the command result. ; signals the end of a single
command, and can be used to separate multiple sequential statements on the same line.
>> density = 1.25; diameter = 10.2;
Operators
+ Addition - Subtraction * Multiplication
/ Division ^ Power ' Complex conjugate transpose (swaps columns and
rows)
( ) Specify evaluation order
Order of Operations
() ‘ ^ highest level, first priority
* / next priority level
+ - last operations to be performed

Adding matrices
Add two matrices together is just the addition of each of their respective elements. If A and B are both
matrices of the same dimensions (size), then
C=A+B
produces C, where the ith row and jth column are just the addition of the elements (numbers) in the ith
row and jth column of A and B
Transpose
Transposing a matrix means swapping rows and columns of a matrix. No matrix dimension restrictions.
Multiplication
Multiplication of matrices is not as simple as addition / subtraction. It is not an element by element
multiploication as you might suspect it would be. Rather, matrix multiplication is the result of the dot
products of rows in one matrix with columns of another. Consider:
C=A*B
Matrix multiplcation gives the ith row and kth column spot in C as the scalar results of the dot product
of the ith row in A with the kth column in B. In equation form this looks like:
Experiment No.

Study of Basic Matrix


Operations
2
Electrical Engineering

Date Performed: __________


Time Started: __________
Time Finished: __________

Objectives:
 To study the basic of matrix operations

Materials Required:
 MATLAB R2013a.
 Windows 7/XP SP2.
Procedure:
6. Open MATLAB and click on it on the start menu.
7. In the command window, type the command define below and then hit enter to run the
command when given by this numerical:
A= 3 2 1 B= 1 3 0
0 3 4 2 6 4
-1 1 -1 -1 0 2
A. A=[ 3 2 1; 0 3 4; -1 1 -1]
B= [1 3 0; 2 6 4; -1 0 2]

Sum: A+ B
Subtraction: A–B
Multiplication: A* B
Division: A/B or A\B
Inverse of A: inv(A)
B. a=magic(3)
a= rand(3)
C. a= ones(3)
b= 2*ones(3)
D. a+2
E. a(2,2)
a(2:3, :)
a(:, 2:3)
a(2:3,1:2)
a(:,2)
Experiment No.

Study of Basic Matrix


Operations
2
Electrical Engineering

F. eye(3)
G. diag(a)
H. b = a’

8. Do not forget to save the program you created.


9. Print a hard copy of the program you created for oral defense.
10. Always double check before transmitting your files.

Questions:
1. What is a Matrix?

2. What is the dimension of a matrix?

3. What are the elements of a matrix?

4. What is a square matrix?

5. What are the basic matrix operations?

6. What is the Transpose of a matrix?

7. What are the commands in MATLAB to solve the various basic matrix operations?

Conclusion:
Experiment No.

Solving Linear Equations 3


Electrical Engineering

Discussion:

Linear Equation

A linear equation is any equation that can be written in the form


ax+b=0
Where a and b are real numbers and x is a variable. This form is sometimes called the standard form of
a linear equation. Note that most linear equations will not start off in this form. Also, the variable may
or may not be an x so don’t get too locked into always seeing an x there.

To solve linear equations we will make heavy use of the following facts.
 If a=b then a+c=b+c for any c. All this is saying is that we can add a number, c, to both sides of
the equation and not change the equation.
 If a=b then a−c=b−c for any c. As with the last property we can subtract a number, c, from both
sides of an equation.
 If a=b then ac=bc for any c. Like addition and subtraction, we can multiply both sides of an
equation by a number, c, without changing the equation.
 If a=b then ac=bc for any non-zero c. We can divide both sides of an equation by a non-zero
number, c, without changing the equation.

These facts form the basis of almost all the solving techniques that we’ll be looking at in this chapter so
it’s very important that you know them and don’t forget about them. One way to think of these rules is
the following. What we do to one side of an equation we have to do to the other side of the equation.
If you remember that then you will always get these facts correct.

Solving Linear Equation in MATLAB:


Solving a linear algebraic equation is easy in MATLAB. It is, perhaps, also the most used computation in
science and engineering. We will solve a set of linear algebraic equations given below:
5x= 3y-2z+10
8y+4z= 3x+20
2x+4y-9z=9
Experiment No.

Solving Linear Equations 3


Electrical Engineering

Date Performed: __________


Time Started: __________
Time Finished: __________

Objectives:
 To solve linear equations using MATLAB

Materials Required:
 MATLAB R2013a.
 Windows 7/XP SP2.

Procedure:
1. Rearrange equations: Write each equation with all unknown quantities on the left hand side
and all known quantities on the right hand side. Thus, for the equations given above, rearrange
them such that all terms involving x, y, and z are on the left hand side of the equal sign:
5x-3y+2z = 10
-3x+8y+4z = 20
2x+4y-9z = 9
2. Write the equations in matrix form: To write the equation in the matrix form [A]{x}={b} where
{x} is the vector of unknowns, we have to arrange the unknowns in matrix A and the constants
on the right hand side of the equations in vector b.
3. Solve the matrix equation in MATLAB: Enter the matrix A and vector b, and solve for vector x
with x=A\b (note that the \ is different from the division /):
4. Write a program to solve linear equation
1 5x= 5y-8z
9y+3z= x+6
10x+4y-z=7
5. Do not forget to save the program you created.
6. Print a hard copy of the program you created for oral defense.
7. Always double check before transmitting your files.
Experiment No.

Solving Linear Equations 3


Electrical Engineering

Questions:
1. What is a linear equation?

2. What operation in MATLAB should be used in solving linear equation?

Conclusion:
Experiment No.

Solution of Linear Equations for


Underdetermined and 4
Overdetermined cases Electrical Engineering

Discussion:

i. Overdetermined : Under such conditions, number of equations are more than the unknowns.
Overdetermined systems of simultaneous linear equations are often encountered in various
kinds of curve fitting to experimental data.
e.g.
x + 2y – z = 3
3x – y + 2z = 1
2x -2y +3z = 2
x- y + z = -1

ii. Underdetermined: Underdetermined linear systems involve more unknowns than equations.
When they are accompanied by additional constraints, they are the purview of linear
programming. By itself, the backslash operator deals only with the unconstraint system. The
solution is never unique. MATLAB finds a basic solution, which has at most m nonzero
components, but even this may not be unique. The particular solution actually computed is
determined by the QR factorization with column pivoting. The complete solution of the
underdetermined system can be characterized by adding an arbitrary vector from the null
space, which can be found using the null function with an option requesting a “rational” basis
Z = null (a, ‘r’). When the equations are expressed by a* x = b.
It can be confirmed that a*Z is zero and that any vector x, where
x = b +Z*q
For any arbitrary vector q satisfies a*x = b.
e.g.
x + 2y – z = 3
3x – y + 2z = 1
Experiment No.

Solution of Linear Equations for


Underdetermined and 4
Overdetermined cases Electrical Engineering

Date Performed: __________


Time Started: __________
Time Finished: __________

Objectives:
1. To solve linear equations using MATLAB

Materials Required:
2. MATLAB R2013a.
3. Windows 7/XP SP2.

Procedure:
1. Open MATLAB and click on it on the start menu.
2. In the command window, type the command define below and then hit enter to run the
command.
3. Overdetermined
>> a = [1 2 -1; 3 -1 2; 2 -2 3; 1 -1 1];
>> b = [3 ; 1; 2; -1];
>> x = a\b
4. Underdetermined
>> a = [1 2 -1; 3 -1 2];
>> b = [3;1];
>> x = a\b
>> Z = null(a, ‘r’)
5. Do not forget to save the program you created.
6. Print a hard copy of the program you created for oral defense.
7. Always double check before transmitting your files.
Experiment No.

Solution of Linear Equations for


Underdetermined and 4
Overdetermined cases Electrical Engineering

Questions:
1. What do you mean by underdetermined system?

2. What do you mean by over determined system?

3. How do you solve linear equations of under determined system and over determined system
manually?

4. What are the commands to solve linear equations of under determined system and over
determined system in MATLAB?

Conclusion:
Experiment No.

Eigen Values and Eigen


Vectors of a Square Matrix
5
Electrical Engineering

Discussion:

For an n x n matrix A, the real number λ is called an Eigen value of A if there exists a nonzero vector x
in Rn such that Ax =λ x. The vector x is called an eigenvector belonging to λ . The equation Ax =λ x is
equivalent to (A-λI) x = 0, so all of the following are equivalent:

1.λ is an Eigen value of A.


2. (A-λI) x = 0 has a nontrivial solution.
3. A-λI is singular.
4. det(A-λI) = 0.

The eigenvectors for λ are the nonzero solutions x to (A-λI)x=0. These vectors together with the 0
vector is called the eigen space corresponding to eigen value λ. The expression det(A-λI) is a
polynomial in λ of degree n, called the characteristic polynomial. By property 4, the eigen values are
the roots of the characteristic equation det(A-λI) = 0.

Determining eigen values and eigenvectors with MATLAB:

Method 1: In MATLAB we can find the characteristic polynomial of a matrix A by entering poly (A). If A
is an n x n matrix, poly(A) is a row vector with n+1 elements that are the coefficients of the
characteristic polynomial. The command roots(C) computes the roots of the polynomial whose
coefficients are the elements of the vector C. Thus, roots (poly (A)) returns the eigen values of A in a
column vector.

To find the eigenvectors corresponding to each eigenvalue found above, we need to find the nonzero
solutions x to (A-I) x = 0. One way of doing this in MATLAB is to compute rref(A-I) and then use Gauss-
Jordan elimination
Experiment No.

Eigen Values and Eigen


Vectors of a Square Matrix
5
Electrical Engineering

Finding the eigenvector and eigenvalues of a square matrix A.

The reduced form of echelon form for A-2I gives the general solution to(A-2I)x =0 as
0 0
𝑥 = [ 𝑟 ] = 𝑟 [1],the form for eigenvectors corresponding to λ = 2.
𝑟 1

Similarly, the reduced echelon forms for A-1I and A-(-1)I allow us to determine eigenvectors of the
form
1 1
s [0]for λ = 1, and t[−1]corresponding to λ = -1.
1 1

Method 2: Determining the eigenvalues and eigenvectors in MATLAB is to use the eig function. For an
nxn matrix A, eig(A) returns a n x1 column vector whose elements are the eigenvalues of A. The
command in the form:
[𝑉 𝐷] = 𝑒𝑖𝑔(𝐴)
Computes both the eigenvalues and eigenvectors of A. V will be a matrix whose columns are
eigenvectors of A and D will be a diagonal matrix whose entries along the diagonal are eigenvalues of
A. The ith column of V, V(:, i), is the eigenvector corresponding to the eigenvalue D(i,i). A sample
session is shown for the matrix A above.
Experiment No.

Eigen Values and Eigen


Vectors of a Square Matrix
5
Electrical Engineering

Date Performed: __________


Time Started: __________
Time Finished: __________

Objectives:
 To determine eigen values and eigen vectors of a square matrix with MATLAB

Materials Required:
 MATLAB R2013a.
 Windows 7/XP SP2.

Procedure:
1. Open MATLAB and click on it on the start menu.
2. Write a program to determine the given eigen vector and eigen values of
A=[ 1 2 3; 4 5 6; 7 8 9]
3. Do not forget to save the program you created.
4. Print a hard copy of the program you created for oral defense.
5. Always double check before transmitting your files.

Questions:
1. What do you mean by eigen-values of a square matrix?

2. What do you mean by eigen-vectors of a square matrix?

3. How do you solve eigen-values and eigen-vectors of a square matrix manually?

4. How do you solve eigen-values and eigen-vectors of a square matrix in MATLAB?


Conclusion:
Experiment No.

Solving Differential
Equation Using MATLAB 6
Electrical Engineering
Discussion:

DIFFERENTIAL EQUATIONS:
A differential equation is a mathematical equation for an unknown function of one or several
variables that relates the values of the function itself and its derivatives of various orders.
Differential equations play a prominent role in engineering, physics, economics, and other
disciplines.

GIVEN NUMERICAL:

The function ‘dsolve’ computes symbolic solutions to ordinary differential equations. The equations
are specified by symbolic expressions containing the letter ‘D’ to denote differentiation. The
symbols D2, D3,….DN, correspond to the second, third,….,Nth derivative, respectively. Thus, D2y is
𝑑2/𝑑𝑡2. The dependent variables are those preceded by D and the default independent variable is t.
Note that names of symbolic variables should not contain D. The key issues in this example are the
order of the equation and the initial conditions.

To solve the ordinary differential equation, simply type:


y = dsolve(‘D3y=y’, ‘y(0)=1’, ‘Dy(0)=-1’, ‘D2y(0)=pi’, ‘x’)

Where D3y represents 𝑑3𝑦/𝑑𝑥3 and D2y(0) represents 𝑑2𝑦/𝑑𝑥2 at x = 0.

Examples
(i) dy/dt = -ay
(ii) dy/dt = -ay and y(0) =1
(iii) 𝑑2𝑦/𝑑𝑡2 = -−𝑎2 y and y(0)= 1, dy/dt(Π/a)=0
(iv) dy/dx = (xy - 𝑦2)/ 𝑥2 (
(v) dy/dx = tan(y/x) +y/x

COMMANDS:
(i) >> y=dsolve(‘Dy=-a*y’) %write ODE in inverted comma
(ii) >> y=dsolve(‘Dy=-a*y’, ‘y(0)=1’) %write ODE in inverted comma followed by initial condition,
separated by comma
(iii >> y=dsolve(‘D2y=-a^2*y’, ‘y(0)=1, Dy(pi/a)=0’) %write ODE in inverted comma followed
by initial condition, separated by comma
Note: In all the above cases, the independent variable is ‘t’ by default.
(iv) >> y = dsolve (‘Dy=(x*y –y^2)/ x^2’, ‘x’) % define independent variable as ‘x’ (
v) >> y = dsolve (‘Dy=tan(y/x) + y/x)’, ‘x’)
Experiment No.

Solving Differential
Equation Using MATLAB 6
Electrical Engineering

Date Performed: __________


Time Started: __________
Time Finished: __________

Objectives:
 To determine the solution of a differential equation using MATLAB

Materials Required:
 MATLAB R2013a.
 Windows 7/XP SP2.

Procedure:
1. Open MATLAB and click on it on the start menu.
2. Write a program to solve the following differential equations:
i) dy/dx = -(𝑦2 −𝑥2/2𝑥𝑦)
ii) dy/dx = (2y - x)/(2x -y)
iii) dy/dx = ytanx - 𝑦2 sec𝑥
iv) dy/dx = 3 𝑒𝑥𝑦3 - y
v) (𝑑2𝑦/ 𝑑𝑡2 )− 8𝑑𝑦 /𝑑𝑥 +15𝑦 = 0
3. Do not forget to save the program you created.
4. Print a hard copy of the program you created for oral defense.
5. Always double check before transmitting your files.

Questions:
1. What is a differential equation?

2. Give examples of differential equations.


3. What command is used to solve differential equations using MATLAB? Explain with examples.

Conclusion:
Experiment No.

Roots of a Polynomial 7
Electrical Engineering

Discussion:

POLYNOMIAL:
Polynomials are functions that have the form

The coefficients a1, a2, . . . . , an are often real numbers and n which is a nonnegative integer, is the
degree or order of the polynomial.

IN MATLAB:

Polynomials are described by using a row vector of the coefficients of the polynomial beginning with
the highest power of x and inserting zeros for “missing” terms:

f= [9 -5 3 7]
g= [6 -1 2]
ROOTS OF A POLYNOMIAL:
Roots of a polynomial f(x) = a0 +a1x +. . . + anxn are the values of x for which f(x) = 0. For example, the
roots of f(x) =x2-3x+2 are -1 and -2. There are n roots of a polynomial with degree n. The command
“roots” determines the roots of a polynomial. The usage of the function is:
r= roots (p)
where r is a column vector with the roots and p is a row vector with the coefficients of the polynomial.

PROGRAM:
Find the roots of the polynomial

>> p = [3 15 0 -10 0 4 0]
>> roots(p)
RESULT:
0
-4.8613
-0.6925 + 0.3093i
-0.6925 - 0.3093i
0.6232 + 0.2975i
0.6232 - 0.2975i
Experiment No.

Roots of a Polynomial 7
Electrical Engineering

Date Performed: __________


Time Started: __________
Time Finished: __________

Objectives:
 To determine the roots of a polynomial using MATLAB

Materials Required:
 MATLAB R2013a.
 Windows 7/XP SP2.

Procedure:
1. Open MATLAB and click on it on the start menu.
2. Write a program to solve the following equations:
i. 𝑥 4 − 16𝑥 3 + 86𝑥 2 − 176𝑥 + 105 = 0
ii. 𝑥 4 − 3𝑥 2 + 42𝑥-40=0
iii. 𝑥 4 + 12𝑥 − 5 = 0
3. Do not forget to save the program you created.
4. Print a hard copy of the program you created for oral defense.
5. Always double check before transmitting your files.

Questions:
1. What is a polynomial?

2. What command should be used to determine the roots of a polynomial equation?

Conclusion:
References

S. C. Chapra, Applied Numerical Methods with Matlab for Engineers

S. C. Chapra, Numerical Methods for Engineers

G.N. Kumar, Computational Mathematical Laboratory Manual

P. Scherz, Practical Electronics for Inventors, Fourth Edition

Kamal I. M. Al-Malah, MATLAB Numerical Methods with Chemical Engineering Applications

You might also like