Derivative of t when t is a number
Ältere Kommentare anzeigen
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 =
[]
Antworten (1)
Image Analyst
am 13 Sep. 2013
0 Stimmen
Make t and array then evaluate x with .^ instead of ^. Then take diff and look at the element where t=1.
6 Kommentare
Philosophaie
am 13 Sep. 2013
Bearbeitet: Philosophaie
am 13 Sep. 2013
Image Analyst
am 13 Sep. 2013
Why are you including t in diff()??? Don't do that!
Philosophaie
am 13 Sep. 2013
Image Analyst
am 13 Sep. 2013
If x(2) = 7, and x(1) = 6, then the difference = x(2)-x(1) = 7-6 = 1. How do you say it should be -4?
Philosophaie
am 13 Sep. 2013
Bearbeitet: Philosophaie
am 13 Sep. 2013
Image Analyst
am 13 Sep. 2013
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?
Kategorien
Mehr zu PDE Solvers finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!