What MATLAB function is used to evaluate a polynomial at specific points?
The polyval function evaluates a polynomial at given points. You provide the polynomial coefficients and the points where you want to evaluate it.
Click to reveal answer
beginner
How do you find the roots of a polynomial in MATLAB?
Use the roots function with the polynomial coefficients as input. It returns the values where the polynomial equals zero.
Click to reveal answer
beginner
Given polynomial coefficients p = [1 -3 2], what polynomial does this represent?
It represents the polynomial x² - 3x + 2. The vector lists coefficients from highest degree to constant term.
Click to reveal answer
intermediate
What is the output of roots([1 -3 2]) in MATLAB?
The output is [2; 1], which are the roots of the polynomial x² - 3x + 2.
Click to reveal answer
beginner
How can you evaluate the polynomial x² - 3x + 2 at x = 5 in MATLAB?
Use polyval([1 -3 2], 5). This calculates 5² - 3*5 + 2 = 25 - 15 + 2 = 12.
Click to reveal answer
Which MATLAB function returns the roots of a polynomial given its coefficients?
Apolyfit
Bpolyval
Crootsolve
Droots
✗ Incorrect
The roots function finds the zeros of the polynomial.
What does the vector [2 -4 1] represent in MATLAB polynomial terms?
A2x² - 4x + 1
B2 + -4x + x²
Cx² - 4x + 2
D1x² - 4x + 2
✗ Incorrect
Coefficients are listed from highest degree to constant term.
What will polyval([1 0 -1], 1) return?
A0
B1
C-1
D2
✗ Incorrect
Evaluates x² - 1 at x=1: 1² - 1 = 0.
If a polynomial has coefficients [1 -2 1], what are its roots?
A[-1; -1]
B[1; 1]
C[0; 1]
D[2; -1]
✗ Incorrect
The polynomial x² - 2x + 1 factors as (x-1)², root at 1.
Which MATLAB function would you use to fit a polynomial to data points?
Aroots
Bpolyval
Cpolyfit
Dpolyroot
✗ Incorrect
polyfit fits a polynomial to data, not for evaluation or roots.
Explain how to represent a polynomial in MATLAB and how to evaluate it at a given point.
Think about how you write the polynomial as a list of numbers and then use a function to find its value.
You got /4 concepts.
Describe the process to find the roots of a polynomial using MATLAB and what the roots represent.
Roots are where the polynomial equals zero.
You got /4 concepts.
Practice
(1/5)
1. What does the MATLAB function polyval(p, x) do when p is a vector of polynomial coefficients and x is a number?
easy
A. Evaluates the polynomial at the value x.
B. Finds the roots of the polynomial p.
C. Plots the polynomial curve over x.
D. Calculates the derivative of the polynomial at x.
Solution
Step 1: Understand the function inputs
The vector p contains polynomial coefficients, and x is the point where we want to evaluate the polynomial.
Step 2: Identify the function purpose
polyval calculates the polynomial value at x using the coefficients in p.
Final Answer:
Evaluates the polynomial at the value x. -> Option A
Quick Check:
polyval = evaluate polynomial [OK]
Hint: polyval means evaluate polynomial at given points [OK]
Common Mistakes:
Confusing polyval with roots function
Thinking polyval finds zeros of polynomial
Assuming polyval plots the polynomial
2. Which of the following is the correct syntax to find the roots of a polynomial with coefficients stored in vector p in MATLAB?
easy
A. polyval(p)
B. roots(p)
C. findroots(p)
D. solve(p)
Solution
Step 1: Recall MATLAB root-finding function
MATLAB uses the function roots to find zeros of a polynomial given its coefficients.
Step 2: Check syntax correctness
The correct syntax is roots(p), where p is the coefficient vector.
Final Answer:
roots(p) -> Option B
Quick Check:
roots function syntax = roots(p) [OK]
Hint: Use roots() to find polynomial zeros in MATLAB [OK]
Common Mistakes:
Using polyval instead of roots
Trying non-existent functions like findroots
Passing wrong arguments to roots
3. What is the output of the following MATLAB code?
p = [1 -3 2]; % Represents x^2 - 3x + 2
r = roots(p);
medium
A. [1 2]
B. [3 2]
C. [2 1]
D. [-1 -2]
Solution
Step 1: Identify the polynomial
The vector p = [1 -3 2] represents the polynomial x^2 - 3x + 2.
Step 2: Find roots of the polynomial
Factoring: (x-1)(x-2) = 0 so roots are 1 and 2. MATLAB returns a column vector [2; 1], matching option [2 1].
Final Answer:
[2 1] -> Option C
Quick Check:
Roots of x^2-3x+2 = 1, 2 [OK]
Hint: Roots are where polynomial equals zero [OK]
Common Mistakes:
Mixing up coefficient order
Forgetting roots are values of x
Assuming roots are negative
4. The following MATLAB code is intended to evaluate the polynomial p = [2 -5 3] at x = 4. What is the error?
p = [2 -5 3];
y = roots(p, 4);
medium
A. The syntax is correct; no error.
B. The variable y is not defined before use.
C. The vector p should be transposed before calling roots.
D. roots does not take a second argument; use polyval instead.
Solution
Step 1: Understand function usage
The function roots only takes one input: the coefficient vector p.
Step 2: Identify correct function for evaluation
To evaluate polynomial at a point, use polyval(p, x), not roots.
Final Answer:
roots does not take a second argument; use polyval instead. -> Option D
Quick Check:
roots(p) finds zeros; polyval(p,x) evaluates [OK]
Hint: Use polyval to evaluate, roots only finds zeros [OK]
Common Mistakes:
Passing extra arguments to roots
Confusing roots and polyval functions
Assuming roots evaluates polynomial
5. You have a polynomial p = [1 -6 11 -6] representing x^3 - 6x^2 + 11x - 6. Which MATLAB code correctly finds the roots and evaluates the polynomial at x = 2?
hard
A. r = roots(p); y = polyval(p, 2);
B. r = polyval(p, 2); y = roots(p);
C. r = roots(2); y = polyval(p);
D. r = roots(p, 2); y = polyval(p, 2);
Solution
Step 1: Find roots of polynomial
Use roots(p) to get zeros of polynomial p.
Step 2: Evaluate polynomial at x=2
Use polyval(p, 2) to find polynomial value at 2.
Final Answer:
r = roots(p); y = polyval(p, 2); -> Option A
Quick Check:
roots(p) finds zeros, polyval(p,x) evaluates [OK]
Hint: roots() finds zeros; polyval() evaluates at points [OK]
Common Mistakes:
Swapping roots and polyval calls
Passing wrong arguments to roots
Using roots with two arguments
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.