### Yash (view profile)

on 7 Aug 2012
Accepted Answer by Sean de Wolski

### Sean de Wolski (view profile)

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 (view profile)

on 7 Aug 2012

fnotpolyval = @(p,x)sum(bsxfun(@(x,p)p*x.^(numel(p):-1:1),p',x))
or
fnotpolyval = @(p,x)sum(x'*p,2)'

Sean de Wolski

### Sean de Wolski (view profile)

on 7 Aug 2012
Assumes row vectors for p and x
Yash

on 7 Aug 2012
thanks :)

### Azzi Abdelmalek (view profile)

on 7 Aug 2012
Edited by Azzi Abdelmalek

### Azzi Abdelmalek (view profile)

on 7 Aug 2012

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

Show 1 older comment
Azzi Abdelmalek

### Azzi Abdelmalek (view profile)

on 7 Aug 2012
ok try this
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
Yash

### Yash (view profile)

on 7 Aug 2012
giving error
??? Index exceeds matrix dimensions.
Error in ==> @(p,x)sum((x.^[length(p)-1:-1:0].*p))
Yash

### Yash (view profile)

on 7 Aug 2012
thanks but i got it done :)