필터 지우기
필터 지우기

Problem in plotting vectorized inline function.

조회 수: 1 (최근 30일)
tauseef ashraf
tauseef ashraf 2016년 10월 29일
댓글: Star Strider 2016년 10월 29일
Hi, I am trying to workout plotting of a vectorized inline function but encountering an error. Please if somebody can help?
My code is
x=(0.5:0.5:4.5); p1 = [1 -7 14 -8]; %defining coefficients of polynomial 1 p2 = [1 -4 3]; %defining coefficients of polynomial 2 p=conv(p1,p1); %convolution of both these polynomial ps=poly2sym(p); %converting polynomial coefficient vectors into symbolic polynomial pt=char(ps); %converting symbolic polynimial to text string pf=inline(pt); %converting text string to inline function pv=vectorize(pf) %converting inline function to vectorized inline function yp1=polyval(pv,x) plot(x, ypi)
But the error being encountered is: Error using polyval (line 67) Inputs must be floats, namely single or double.
Please help.

채택된 답변

Star Strider
Star Strider 2016년 10월 29일
All the calls to the Symbolic Math Toolbox functions don’t make sense.
Just do this:
x=(0.5:0.5:4.5);
p1 = [1 -7 14 -8]; %defining coefficients of polynomial 1
p2 = [1 -4 3]; %defining coefficients of polynomial 2
p=conv(p1,p2); %convolution of both these polynomial
yp1=polyval(p,x);
plot(x, yp1)
Don’t use inline functions, regardless. They’re being (if they’ve not already been) deprecated in favor of ‘Anonymous Funcitons’. See the relevant section of Function Basics for details on writing and using Anonymous Functions.
  댓글 수: 2
tauseef ashraf
tauseef ashraf 2016년 10월 29일
Thanks alot for the help buddy. Greatly appreciated
Star Strider
Star Strider 2016년 10월 29일
My pleasure.
If my Answer solved your problem, please Accept it.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Function Creation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by