Derivative of t when t is a number
1 次查看(过去 30 天)
显示 更早的评论
If t is a number. How do you take the derivative of t and get a numerical result without using syms?
x = 5*t^2 - 4*t + 6
t = 1
r = diff(x, t)
It gives the answer:
r =
[]
0 个评论
回答(1 个)
Image Analyst
2013-9-13
Make t and array then evaluate x with .^ instead of ^. Then take diff and look at the element where t=1.
6 个评论
Image Analyst
2013-9-13
I don't think you understand digital/quantized numerical analysis. Sure, the derivative is 10*t-4, which evaluates to -4 at t=0, and 6 at t=1, but when you've quantized it to only the nearest 1 for t, then you don't get the exact derivative. The slope is delta_x / delta_t as delta_t goes to zero, right? Now, if you're quantized so that you only have samples at t=0,1,2,3,4 then you're never going to be able to get that slope because you're too far away. You're getting sort of the average slope over that huge distance. Here, look at this code where I decreased the distance (increased the sampling rate). If you run this code and analyze it at t=1 you'll see you get very close to a derivative (slope) of 6, which is the theoretical answer.
t=0:.001:2;
x = 5 * t .^ 2 - 4 .* t + 6;
delta_x = diff(x);
% Evaluate at t = 1
% First, need to find the index where t = 1.
t1Index = find(t == 1)
% Now evaluate the slope there
slope = delta_x(t1Index) / (t(t1Index) - t(t1Index-1))
% t1Index =
% 1001
% slope =
% 6.00499999999914
If you make the steps in t even smaller, you'll get even closer. Does that explain it better?
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!