MATLAB- graphing time versus velocity

New to MATLAB here. Trying to graph time versus velocity for something going down an incline ramp. Everything seems to work okay up until I get my graph. I want an increasing line showing 10 intervals, but it just shows a single dot in the middle of the graph. Does anyone see what I'm doing wrong? Any help is appreciated!
% A cart is rolling down a frictionless inclined plane
% Prompt user for ramp length
S=input('What is the ramp length? ');
% Prompt user for ramp incline
theta=input('What is the degree of the ramp incline? ');
% Calculation for acceleration(a) with g as a constant =9.81
% Formula for acceleration is a=gsind(theta)
a=9.81*sind(theta);
Acceleration=a
% Solved for Time (t)
t=((2*S)/a)*0.5;
Time=t
% Calculate velocity
v=S/t;
Velocity=v
% Graph to show velocity of cart at 10 intervals
T=0:t/10:t;
y=v
x=t
plot(x,y,'-.dr');
xlabel('Time')
ylabel('Velocity')
title('Velocity vs Time of cart rolling down ramp')

Answers (1)

I took some liberties with your code, however the problem is that you are defining only one value of ‘t’ and one value of ‘v’. You need to use the vector ‘T’. This produces the sort of plot you want:
T=0:t/10:t;
y=a*T;
x=T;
plot(x,y,'-.dr');

Products

Tags

No tags entered yet.

Asked:

on 18 Sep 2015

Answered:

on 18 Sep 2015

Community Treasure Hunt

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

Start Hunting!