working out acceleration from 2 matrices- HELP
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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.
0 Commenti
Risposte (2)
Roger Stafford
il 24 Nov 2017
Modificato: Roger Stafford
il 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
0 Commenti
Kaushik Lakshminarasimhan
il 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 Commenti
Kaushik Lakshminarasimhan
il 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);
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!