Function instead of polyval

3 Ansichten (letzte 30 Tage)
Yash
Yash am 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.

Akzeptierte Antwort

Sean de Wolski
Sean de Wolski am 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)'
  2 Kommentare
Sean de Wolski
Sean de Wolski am 7 Aug. 2012
Assumes row vectors for p and x
Yash
Yash am 7 Aug. 2012
thanks :)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Azzi Abdelmalek
Azzi Abdelmalek am 7 Aug. 2012
Bearbeitet: Azzi Abdelmalek am 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
  4 Kommentare
Yash
Yash am 7 Aug. 2012
giving error
??? Index exceeds matrix dimensions.
Error in ==> @(p,x)sum((x.^[length(p)-1:-1:0].*p))
Yash
Yash am 7 Aug. 2012
thanks but i got it done :)

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by