Function evaluates a polynomial

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 件のコメント

Guillaume
Guillaume 2015 年 4 月 30 日
Read this.
What is the problem you're having?
Ryan Wu
Ryan Wu 2015 年 4 月 30 日
Hi Guillaume,
So I figured out the formula that goes in the for loop to evaluate a polynomial. But I have problem writing the code for the main program and plotting the polynomial.
I would really appreciate any help or guidance.
Thanks, Ryan
for i:[length(coeff)-1] sum = vec[i] * X.^(L-1) total = sum + total;

サインインしてコメントする。

回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangePolynomials についてさらに検索

質問済み:

2015 年 4 月 30 日

編集済み:

2015 年 4 月 30 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by