Trouble calculating Acceleration from given velocity vector.
Show older comments
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 Comments
darova
on 7 Apr 2020
Can you attach an example code? Your code?
Connor Watkins
on 7 Apr 2020
Saad Hussain
on 6 May 2021
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
Answers (1)
darova
on 7 Apr 2020
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 Comments
Connor Watkins
on 7 Apr 2020
darova
on 7 Apr 2020
- 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
Connor Watkins
on 7 Apr 2020
Categories
Find more on MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!