224 views (last 30 days)

Show older comments

Hi, I put a polynom ( x^2+x-1) in a form of a vector :

[1 1 -1].I don't know how to derivate this vector and how to evaluate it.

Thanks, Thierry.

Image Analyst
on 12 Apr 2015

Not sure how those 3 numbers came from that equation, but anyway....The derivative is the slope. You have two line segments, from 1 to 1 and from 1 to -1. So the slope of the first line segment is 0 and the slope of the second line segment is -2. You can get this from

slopes = diff(yourVector);

Star Strider
on 12 Apr 2015

If you want to evaluate your polynomial and do a numerical derivative, use the polyval function to evaluate it, then the gradient function to take the derivative:

h = 0.1; % Spacing Constant

x = -5:h:5; % Independent Variable Vector

y = polyval([1 1 -1], x); % Evaluate Polynomial

dydx = gradient(y, h); % Take Numerical Derivative At Each Value Of ‘x’

Note that unlike diff, the gradient function will produce a vector the same length as the original data vector.

Image Analyst
on 12 Apr 2015

Youssef Khmou
on 12 Apr 2015

additionally to the above answers, the simplest way to evaluate the polynomial is via anonymous function :

f=@(x) x.^2+x-1

x=0:0.1:10;

Generally, coefficients vector is used to find the roots. concerning the derivation, gradient is more efficient than diff, when you have the sample rate :

df=gradient(f(x),0.1);

plot(x,f(x),x,df,'r')

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

Start Hunting!