MATLAB Answers

Numerical Differentiation that returns column vector

1 view (last 30 days)
David Fariyike
David Fariyike on 17 Jun 2020
Answered: David Hill on 17 Jun 2020
I am trying to numerically differentiate inside a for loop and return a column vector. In short I have a value theta1inv that is solved inside a for loop and I am trying to find the change with respect to time. The time is 0 to 2 with increments of .005 and I am using that as the for loop condition.
tt=t0:0.005:tf;
for ii=1:length(tt)
Theta1inv has 401 values in a column vector and I am trying to find the change with repect to time. I have used this but it doesn't make a column vector nor does it work in the for loop. But it does give me the correct values from what I can tell.
thetadot1 = gradient(theta1inv(:)) ./ gradient(tt(:));
If I put (ii) after the thetadot1, I get the error code: "Unable to perform assignment because the left and right sides have a different number of elements." It does give me the correct values but not in a column vector and doesn't work in the for loop.
Lastly, theta1inv gives 1x401 double and thetadot gives 401x1 double.

  0 Comments

Sign in to comment.

Answers (1)

David Hill
David Hill on 17 Jun 2020
If the time interval is constant (.005 between readings), it should be as simple as:
thetadot=diff(theta1inv)/.005;
You will go down to 400x1.

  0 Comments

Sign in to comment.