working out acceleration from 2 matrices- HELP

1 vue (au cours des 30 derniers jours)
EEEmatlab
EEEmatlab le 24 Nov 2017
Commenté : EEEmatlab le 25 Nov 2017
I have 2 matrices: velocity and time
velocity = [0,56.40,97.23,136.25,226.16,403.86,440.44,1265.23]
time = [0,10,15,20,30,59,62,125]
it asks to work out acceleration
This is what i have done:
clc;
clear all;
close all;
time = [0,10,15,20,30,59,62,125];
velocity = [0,56.40,97.23,136.25,226.16,403.86,440.44,1265.23];
for i=1:length(time)
for ii=1:length(velocity)
for x=1:1:7
%%accelertaion = change in velocity / change in time%%
acceleration(x) = (velocity(1,(x+1))-velocity(1,x))/(time(1,(x+1))-time(1,x))
end
end
end
So this gives me:
acceleration = Columns 1 through 6
5.6400 8.1660 7.8040 8.9910 6.1276 12.1933
Column 7
13.0919
So my question is: how do i put a 0 in column 1 of the acceleration matrix and shift everything else? i need 1*8 matrix.
i want to plot a graph of acceleration against time so the size of matrix needs to be the same.

Réponses (2)

Roger Stafford
Roger Stafford le 24 Nov 2017
Modifié(e) : Roger Stafford le 25 Nov 2017
Assuming your 'time' and 'velocity' vectors are corresponding row vectors (have only one row,) you can use the following code to produce second order approximations to the accelerations corresponding to points in 'time' that will produce an equal number of acceleration values. You need to have a minimum of three values in 'time' and 'velocity' vectors for this to work.
n = length(time); %Assume velocity vector is same length
te = [time(3),time,time(n-2)];
ve = [velocity(3),velocity,velocity(n-2)];
t1 = te(1:n); t2 = te(2:n+1); t3 = te(3:n+2);
v1 = ve(1:n); v2 = ve(2:n+1); v3 = ve(3:n+2);
t21 = t2-t1; t32 = t3-t2; t31 = t3-t1;
v21 = v2-v1; v32 = v3-v2;
ac = (v21./t21.*t32+v32./t32.*t21)./t31; % Approx. acceleration values

Kaushik Lakshminarasimhan
Kaushik Lakshminarasimhan le 24 Nov 2017
It is not correct to put a 0 when you don't know the value of acceleration. Instead, you should define a new vector of time points that correctly reflects the times at which you actually computed your acceleration. This would be the mid-points of the time-intervals. Also, there's a simpler way to compute acceleration from your data without constructing a loop:
acc = diff(velocity)./diff(time);
t_acc = 0.5*(time(1:end-1) + time(2:end));
plot(t_acc,acc);
  5 commentaires
Kaushik Lakshminarasimhan
Kaushik Lakshminarasimhan le 24 Nov 2017
It does not matter if acceleration is not constant. Displacement is always equal to the time-integral of velocity, so you can use area under the velocity-time graph to calculate displacement (which is equal to distance in your case). To compute the integral, you need to provide the trapz function with the complete data, not just one time point. So you need to use:
distance = trapz(time,velocity);
EEEmatlab
EEEmatlab le 25 Nov 2017
The thing is the question asks me for the distance covered for each time interval. If i use trapz(velocityChange,timeChange) it gives me a zero matrix and only the sum of all the distances.. how do i get the distance for each time interval?
Also i was saying that when u draw the graph the time interval connects with straight lines which is kind of wrong because it could be a curve since the acceleration is not constant and so using area under that graph will only be an approximation of the distance. This is a differentiation and integration topic so i am asking is there not a way to compute the exact area?

Connectez-vous pour commenter.

Catégories

En savoir plus sur Numerical Integration and Differentiation dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by