【发布时间】:2013-12-04 01:22:45
【问题描述】:
我已经编写了计算多项式的代码
p(x)=a_0+x(a_1+x(a_2+x(a_3+...+x(a_(n-1)+xa_n)...)))
使用霍纳规则如下
function [answer ] = Simple( a,x )
%Simple takes two arguments that are in order and returns the value of the
%polynomial p(x). Simple is called by typing Simple(a,x)
% a is a row vector
%x is the associated scalar value
n=length(a);
result=a(n);
if (any(a~=floor(a))
error('The values in a must be integers')
end
for j=n-1:-1:1 %for loop working backwards through the vector a
result=x*result+a(j);
end
answer=result;
end
我现在正在尝试为这个 ie 的稀疏版本编写代码
p(x)=x^(i_1)(b_1+x^((i_2)-(i_1))(b_2+x^((i_3)-(i_2))(b_3+...+x^( (i_(k-1))-(i_(k-2)))(b_(k-1)+x^((i_k)-(i(k-1)))b_k)...)))
我认为我需要输入是 i 的行向量和 b 的行向量和标量值 x。我可以在哪里找到这个的任何想法?我不确定如何自己编写代码。
【问题讨论】:
标签: matlab