Function instead of polyval

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.

 Réponse acceptée

Sean de Wolski
Sean de Wolski le 7 Août 2012

1 vote

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

2 commentaires

Sean de Wolski
Sean de Wolski le 7 Août 2012
Assumes row vectors for p and x
Yash
Yash le 7 Août 2012
thanks :)

Connectez-vous pour commenter.

Plus de réponses (1)

Azzi Abdelmalek
Azzi Abdelmalek le 7 Août 2012
Modifié(e) : Azzi Abdelmalek le 7 Août 2012

1 vote

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 commentaires

Yash
Yash le 7 Août 2012
can this be like having the same syntax has the polyval as in the same way i call polyval, over here i have to define the function f in terms of x and then evaluate, i need the syntax in terms of polyval.
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 le 7 Août 2012
giving error
??? Index exceeds matrix dimensions.
Error in ==> @(p,x)sum((x.^[length(p)-1:-1:0].*p))
Yash
Yash le 7 Août 2012
thanks but i got it done :)

Connectez-vous pour commenter.

Catégories

En savoir plus sur MATLAB dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by