MATLAB Answers

MATLAB time (seconds) vs velocity graph plotting questions

15 views (last 30 days)
Blake Sewell
Blake Sewell on 1 Sep 2020
Commented: Jon on 2 Sep 2020
Hi guys, I'm enquiring about a section of my homework again and its asking that I use strictly array creation and concatenation to plot the graph of the following question:
and the code I've written to try and solve this via youtube tutorials and lots of websites is:
%time interval of 0.1 seconds
%time establishment in intervals of 0.1 seconds
%acceleration establishment
axis([0 20 4 12])
hold on
plot([10 10],[5,10])
hold off
and the result i get is:
can anyone please tell me where im going wrong and what I need to do to fix, any help is appreciated, thankyou in advance <3


Sign in to comment.

Accepted Answer

Jon on 1 Sep 2020
Edited: Jon on 1 Sep 2020
First, I am glad that although you are asking for help on homework you have made a good attempt on your own and are now just struggling with some MATLAB issues. That's a good point to come to MATLAB answers for help.
You have a few problems.
First you want all of your accelerations to be 1D vectors. You are assigning some of them to be matrices for example:
creates a 10 row by length(t2) number of columns matrix. You want that first argument to just be 1 so that you make a row vector. (or you could use ones(length(t2),1) and make it a column vector, but you'd have to be consistent through out so the time vectors should then also be columns)
Next your accelerations magnitudes are not correct. Of course acceleration is change in velocity per unit time. So the first segment the acceleration is 10m/s/(10s) = 1m/s^2, The second segement it is zero, etc
Finally when you create the overall solution you have to consider the initial condition for the velocity. The way you are doing it you are calculating it as if you are starting at zero velocity for each segment. Of course the start velocity of the second segment is the end velocity of the first segment, etc.
So you could use something like
v2 = v1(end) + cumtrapz(a2)*dt
.and something similar for the final segment.
Hope this helps.
Note to format your code nicely you can use the code button in the MATLAB answers toolbar.


Blake Sewell
Blake Sewell on 1 Sep 2020
Thanks heaps ill be sure to give it a whirl when iv woken up abit more
Blake Sewell
Blake Sewell on 1 Sep 2020
It works !!! thankyou very much for your help I appreciate the in deoth run-down of what needed to be changed <3

Sign in to comment.

More Answers (0)





Community Treasure Hunt

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

Start Hunting!