Writing program to evaluate a polynomial at point x=c

function [output] = function_1(a,c) a=[a0 a1 ... an]; c=x; output=polyval(a,x);
This is the program I tried running, but will not work. I am having trouble how to have c as an input equal to x, and also my output polyval(a,x) is wrong.

回答 (2 件)

Wayne King
Wayne King 2012 年 1 月 23 日

0 投票

Hi Brianne, Your problem is that in polyval(), the first element in the input a is expected to be the coefficient for the N-th power of x. It looks like you have it listed from the 0-th order to the N-th order.
polyval([1 2 2],2)
evaluates x^2+2*x+2 at x=2
Dr. Seis
Dr. Seis 2012 年 1 月 23 日

0 投票

reverse your a, a = [an ... a1 a0]

カテゴリ

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

質問済み:

2012 年 1 月 23 日

Community Treasure Hunt

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

Start Hunting!

Translated by