0% found this document useful (0 votes)
2 views

NC LAB 3

The document outlines a lab report focused on applying basic mathematical operations related to polynomials using MATLAB, including finding roots, convolution, evaluating polynomial values, and computing derivatives. It also covers the use of looping and conditional statements in MATLAB. Two lab tasks are provided for practical application, involving polynomial operations and classification based on percentage divisions.

Uploaded by

235003
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

NC LAB 3

The document outlines a lab report focused on applying basic mathematical operations related to polynomials using MATLAB, including finding roots, convolution, evaluating polynomial values, and computing derivatives. It also covers the use of looping and conditional statements in MATLAB. Two lab tasks are provided for practical application, involving polynomial operations and classification based on percentage divisions.

Uploaded by

235003
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Numerical Analysis & Computation Lab

Lab Report # 3

Objective:
1. Demonstrate the application of basic mathematical operations relevant to polynomials
using MATLAB.
2. Demonstrate the application of looping and conditional statements in MATLAB.
Requirements:
Computer with MATLAB installed in it
Commands Covered:
1. Roots of polynomial
2. Convolution
3. Polynomial Value
4. Polynomial Derivative
5. Looping
6. Conditional Statements

Explanation:
1- Roots of Polynomial:

1- Defining the Polynomial: First, define the polynomial using MATLAB's polynomial
representation. You can do this by specifying the coefficients of the polynomial using the
poly function. For example, to define a polynomial 3x2+2x−1, you would use:

2- Finding Roots: MATLAB provides the roots function to calculate the roots of a
polynomial. Simply pass the coefficients of the polynomial as an argument to the roots
function. For the polynomial defined above

Department of Mechanical Engineering, Air University A&AC Kamra 1


Numerical Analysis & Computation Lab

2- Convolution:
Convolution of polynomials in MATLAB involves multiplying two polynomials together
to obtain their convolution. Here's an explanation of how to perform convolution of
polynomials in MATLAB:

1- Defining Polynomials: First, define the coefficients of the two polynomials that you want
to convolve. For example, let's define two polynomials:

2- Performing Convolution: MATLAB provides the conv function to perform convolution.


Use the conv function to convolve the two polynomials:

3- Polynomial Value:

To calculate the value of a polynomial at a specific point in MATLAB, you can use
the polyval function.

1- Defining the Polynomial: First, define the coefficients of the polynomial you want to
evaluate. You can represent the polynomial coefficients as a vector in MATLAB, with
the order of coefficients corresponding to the powers of the variable. For example, for
the polynomial 3x2+2x−1, you would define the coefficients as:

2- Evaluating the Polynomial: Use the polyval function to evaluate the polynomial at a
specific point. Pass the coefficients vector and the value at which you want to evaluate
the polynomial as arguments to the polyval function. For example, to evaluate the
polynomial at x=2, you would use:

Department of Mechanical Engineering, Air University A&AC Kamra 2


Numerical Analysis & Computation Lab

4- Polynomial Derivative:
To compute the derivative of a polynomial in MATLAB, you can use the polyder
function. Here's how you can do it:

1- Defining the Polynomial: First, define the coefficients of the polynomial you want
to differentiate. You can represent the polynomial coefficients as a vector in
MATLAB, with the order of coefficients corresponding to the powers of the variable.
For example, for the polynomial 3x2+2x−1, you would define the coefficients as:

2- Computing the Derivative: Use the polyder function to compute the derivative of
the polynomial. Pass the coefficients vector as an argument to the polyder function.
For example:

5- Looping:

For Loop:
In MATLAB, a for loop allows you to execute a sequence of statements multiple times.
Here's the basic structure of a for loop in MATLAB:

Department of Mechanical Engineering, Air University A&AC Kamra 3


Numerical Analysis & Computation Lab

 index is a loop index variable that takes on values from startValue to endValue.
 In each iteration of the loop, the statements within the loop body are executed.
 You can use the loop index variable (index) within the loop body to perform operations
that depend on the iteration number.

Example:

The Code will display

6- Conditional Statements:

IF ELSE statement:
In MATLAB, the if statement allows you to execute a block of code if a specified
condition is true. Optionally, you can include an else block to execute a different block of
code if the condition is false. Here's the basic syntax:

Department of Mechanical Engineering, Air University A&AC Kamra 4


Numerical Analysis & Computation Lab

 condition is the expression that evaluates to either true or false.


 If condition is true, the statements within the if block are executed.
 If condition is false and an else block is present, the statements within the else block are
executed.
Here's an example of how to use if and else in MATLAB to determine whether a number is
positive or negative:

This code will display:

Department of Mechanical Engineering, Air University A&AC Kamra 5


Numerical Analysis & Computation Lab

Lab Tasks
2
Q1: Consider the two polynomials p(s)=s +2s+1 and q(s)=s+1.Apply MATLAB to define
polynomials and execute the command to generate the results.
a. p(s)*q(s)
b. Roots of p(s) and q(s)
c. p(-1) and q(6)

Q2: Apply MATLAB to create a program that showcases the classification of divisions based on
the following criteria: achieving 1st division for percentages equal to or exceeding 60%,
obtaining 2nd division for percentages falling between 45% and 60%, securing 3rd division for
percentages between 30% and 45%, and considering any percentage below 45% as a fail.
Execute the program to generate the corresponding results.

Department of Mechanical Engineering, Air University A&AC Kamra 6

You might also like