How can I have Matlab create a polynomial function from a vector of coefficients without invoking some other implemented function?

32 ビュー (過去 30 日間)
Here is some of my initial thinking.
function y = f(x)
clc;
clear;
a = [0,1,1,1,1,1];
n = length(a);
y = 0;
for i = 1:n
while i<=n
y = y + a(i)*x^(i-1);
end
end
end

回答 (2 件)

Erik Keever
Erik Keever 2018 年 10 月 31 日
If you're asking for the most efficient way to do it, call the function Mathworks implemented for us:
>> help polyval
POLYVAL Evaluate polynomial.
Y = POLYVAL(P,X) returns the value of a polynomial P evaluated at X. P
is a vector of length N+1 whose elements are the coefficients of the
polynomial in descending powers.
Y = P(1)*X^N + P(2)*X^(N-1) + ... + P(N)*X + P(N+1)|
Which is also an m-file you can view to see how it's done

madhan ravi
madhan ravi 2018 年 10 月 31 日
a = [0,1,1,1,1,1]
poly2sym(a) % requires symbolic toolbox
  1 件のコメント
madhan ravi
madhan ravi 2018 年 10 月 31 日
How can I have Matlab create a polynomial function from a vector of coefficients?
By the above method you can do it

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

カテゴリ

Help Center および File ExchangePolynomials についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by