Function evaluates a polynomial
Show older comments
Hello All,
I have an assignment that I'm having difficulty with. If someone would help me out that would be awesome.
Write a function that evaluates a polynomial. This function takes two arguments, coeff and s. coeff is a vector of any size and represents the coefficients of a polynomial in descending order. s is a scalar and represents the variable in the polynomial.
For example, POLY([ 2 4 0 -9], 3) outputs the value 2 * 3^3 + 4 * 3^2 – 9 POLY([ 2 0 4 0 -9], 3) outputs the value 2*3^4 + 4* 3^2 – 9
Write a main program that asks the user to enter a vector for the coefficients and plot the polynomial.
This is what I have so far: I have figured out the pseduocode for the for loop.
for i:[length(coeff)-1]
sum = vec[i] * X.^(L-1)
total = sum + total;
But I am having difficulty writing the code as I don't understand plots in Matlab. Any help or advise would be greatly appreciated.
Thanks, Ryan
2 Comments
Ryan Wu
on 30 Apr 2015
Answers (0)
Categories
Find more on Polynomials in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!