How to derivate a vector

조회 수: 452 (최근 30일)
Thierry Gelinas
Thierry Gelinas 2015년 4월 12일
댓글: Les Beckham 2023년 2월 1일
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.

채택된 답변

Claudio Contrada
Claudio Contrada 2023년 2월 1일
hi, use the polyder() function, which returns the coefficients of the derivate as a vector. so if p=[1 1 -1], we have p1=polyder(p). this assigns to p1 the arrray [2 1].
  댓글 수: 1
Les Beckham
Les Beckham 2023년 2월 1일
Although it is not completely clear from the original question, I believe that this is the correct answer.

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

추가 답변 (3개)

Image Analyst
Image Analyst 2015년 4월 12일
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
Star Strider 2015년 4월 12일
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.
  댓글 수: 3
Star Strider
Star Strider 2015년 4월 12일
Because I don’t know what the problem actually is.
Is Thierry supposed to evaluate the polynomial and then take the numerical derivative, or evaluate the polynomial and its analytic derivative at the same values of x?
I’m offering the best numerical derivative function as an option.
Image Analyst
Image Analyst 2015년 4월 12일
I agree with Star. The language in the question is so imprecise, it's impossible to determine if the [1 1 -1] vector is the x input vector or the polynomial y output vector. So I also gave a numerical answer. If the x location(s) where the derivative is known for certain, then you could just use calculus to determine the slope as 2*x+1 and plug in the x where you want the slope computed at.

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


Youssef  Khmou
Youssef Khmou 2015년 4월 12일
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')

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by