Function instead of polyval

4 次查看(过去 30 天)
Is there a Matlab built in function that can be used instead of a polyval function. Or any few lines can work similarly like the polyval function because i dont want to use the polyval function.

采纳的回答

Sean de Wolski
Sean de Wolski 2012-8-7
fnotpolyval = @(p,x)sum(bsxfun(@(x,p)p*x.^(numel(p):-1:1),p',x))
or
fnotpolyval = @(p,x)sum(x'*p,2)'

更多回答(1 个)

Azzi Abdelmalek
Azzi Abdelmalek 2012-8-7
编辑:Azzi Abdelmalek 2012-8-7
fval=@(p,x) sum((x.^[length(p)-1:-1:0].*p));
%example
p=[2 4 5 3]; x=2;
result=fval(p,x) % fval is your new function
  4 个评论
Yash
Yash 2012-8-7
giving error
??? Index exceeds matrix dimensions.
Error in ==> @(p,x)sum((x.^[length(p)-1:-1:0].*p))
Yash
Yash 2012-8-7
thanks but i got it done :)

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by