NC LAB 3
NC LAB 3
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
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:
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:
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:
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:
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:
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.