Function instead of polyval

조회 수: 2 (최근 30일)
Yash
Yash 2012년 8월 7일
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일
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일
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일
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 :)

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

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by