how can i calculate the derivative of an x vector?

1 次查看(过去 30 天)
Starts with an x vector created using linspace with a starting point of -5 and ends at +4 and at least 50 data points.
Evaluate the function f = 2x4 – 5x3 -12x2 + 30x +10 as a function of the MATLAB vector By hand, calculate the first derivative and then evaluate using the same x-vector. By hand, calculate the second derivative and then evaluate using the same x-vector.
Plot the three equations using different line color and different markers. You may use the extended plot command or roots.
Add a graph title, axes titles, and a legend.
  2 个评论
James Tursa
James Tursa 2018-9-5
What have you done so far? What specific problems are you having with your code? Do you know how to take the derivative of a polynomial by hand? Do you know how to evaluate polynomials in MATLAB?
Paul Alequin
Paul Alequin 2018-9-5
I don't know how to make this on matlab. I have my "by hand" calculate but i'm trying how to make this on the software.

请先登录,再进行评论。

采纳的回答

madhan ravi
madhan ravi 2018-9-5
编辑:madhan ravi 2018-9-5
Try the below:
syms f(x)
f = 2*x.^4 - 5*x.^3 -12*x.^2 + 30*x +10
first_derivative = diff(f)
second_derivative = diff(f,2)
%solved symbolically till here
%using numerical method from the above
x=linspace(-5,4,50)
subplot(3,1,1)
plot(subs(x),subs(first_derivative),'*r-')
xlabel('x')
ylabel('first derivative')
title('1ST DERIVATIVE')
legend('FIRST DERIVATIVE')
subplot(3,1,2)
plot(subs(x),subs(second_derivative),'og-')
xlabel('x')
ylabel('second derivative')
title('2ND DERIVATIVE')
legend('SECOND DERIVATIVE')
subplot(3,1,3)
plot(subs(x),subs(f),'sqb-')
xlabel('x')
ylabel('equation')
title('FUNCTION')
legend('FUNCTION')
Start getting familiar with the Matlab functions soon , the sooner the better.

更多回答(0 个)

类别

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