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
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?
采纳的回答
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 Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!