Derivative of t when t is a number

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 =
[]

Answers (1)

Image Analyst
Image Analyst on 13 Sep 2013
Make t and array then evaluate x with .^ instead of ^. Then take diff and look at the element where t=1.

6 Comments

How do you make t an array with parameters to include "1"?
Do you evaluate at t=1, r(1)?
t=(0:5)
x=5*t.^2 - 4*t + 6
r = diff(x,t)
r(1)
?? Error using ==> diff
Difference order N must be a positive integer scalar.
Error in ==> test at 3
r = diff(x,t)
Why are you including t in diff()??? Don't do that!
The derivative of x should be:
dx = 10*t - 4
t=(0:5)
x=5*t.^2 - 4*t + 6
r = diff(x)
This should yield:
t=
0 1 2 3 4 5
x=
6 7 18 39 70 111
r=
-4 6 16 26 36 46
But instead it yields:
r=
1 11 21 31 41
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?
You are telling me that there is no way to substitute a number value for a syms variable.
syms t
x = 5*t^2 - 4*t + 6
r = diff(x, t)
then after you take the derivative of x into r there is no way of subtituting a number value for t.
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?

Sign in to comment.

Tags

No tags entered yet.

Asked:

on 13 Sep 2013

Community Treasure Hunt

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

Start Hunting!