Function instead of polyval

6 views (last 30 days)
Yash on 7 Aug 2012
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.

Accepted Answer

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

More Answers (1)

Azzi Abdelmalek
Azzi Abdelmalek on 7 Aug 2012
Edited: Azzi Abdelmalek on 7 Aug 2012
fval=@(p,x) sum((x.^[length(p)-1:-1:0].*p));
p=[2 4 5 3]; x=2;
result=fval(p,x) % fval is your new function
Yash on 7 Aug 2012
thanks but i got it done :)

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by