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일

1 개 추천

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

댓글 수: 2

Sean de Wolski
Sean de Wolski 2012년 8월 7일
Assumes row vectors for p and x
Yash
Yash 2012년 8월 7일
thanks :)

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2012년 8월 7일
편집: Azzi Abdelmalek 2012년 8월 7일

1 개 추천

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일
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 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 :)

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터 및 File Exchange에서 MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by