Trouble calculating Acceleration from given velocity vector.
22 次查看(过去 30 天)
显示 更早的评论
I want to create a for loop to use the iterative formula for acceleration using given velocity values:
ai = (vi+1 - vi) / dt
I have tried repeatedly but am new to MATLAB. I used the following:
a = diff(V)/diff(T)
where V is velocity and T is time
but the acceleration vector is then 1 smaller than I want to be able to plot the graph a,T
forgive my poor syntax, I am very new to MATLAB
In summary, I need to calculate Acceleration and keep it in the same vector size as Time in order to plot these, not one value smaller.
3 个评论
Saad Hussain
2021-5-6
Hey i was wondering if you still have your code file saved to this assignment and you can send me? ive got a similar one
回答(1 个)
darova
2020-4-7
So what about this formula?
a = diff(V)/diff(T)
Just forgot about ./ element-wise operator
a = diff(V)./diff(Time);
Then use for loop
ds_mapping = a*0;
for i = 1:length(a)
if a(i) >= 0.7
ds_mapping(i) = 1;
elseif a <= 2.81
ds_mapping(i) = 2;
elseif a <= 3.65
ds_mapping(i) = 3;
end
end
What are trying to do here? You want absolute value ?
if a <0
a=inv(a); %To receive positive values for acceleration
end
% a = abs(a);
Note: once you used diff you have one element less (because it calculates difference v(i+1)-v(i))
3 个评论
darova
2020-4-7
- I need to increase the size of the accceleration
Or you can plot without first value
plot(Time(2:end),a)
a(i) can be greater 0.7 and less than 2.81. What then?
if a(i) >= 0.7
elseif a <= 2.81
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!