Clear Filters
Clear Filters

Problem in plotting vectorized inline function.

1 view (last 30 days)
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.

Accepted Answer

Star Strider
Star Strider on 29 Oct 2016
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 Comments
tauseef ashraf
tauseef ashraf on 29 Oct 2016
Thanks alot for the help buddy. Greatly appreciated
Star Strider
Star Strider on 29 Oct 2016
My pleasure.
If my Answer solved your problem, please Accept it.

Sign in to comment.

More Answers (0)

Categories

Find more on Function Creation in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!