Having difficulty getting the program right

Hello, I'm taking a minicourse on MATLAB and I was given an assignment that I am having difficulties completing. The assignment is to prompt the user for initial height (in meters), and vertical velocity (in m/s) and plot the height and vertical velocity as a function of time. I'm ending up with only a single dot. I assume it has something to do with my time variable, but given that I'm still early on in my education I don't know where to make the correction
The code I have is as follows:
g = -9.81;
h = input('Enter the initial height of the ball in meters: ');
v0 = input('Enter the initial velocity of the ball in meters squared: ');
t = 0;
h = (0.5)*(g)*t.^2+(v0)*(t)+(h);
v = (g)*(t)+(v0);
% Plot the height and veloctiy as a function of time
plot(t,h);
hold on;
plot(t,v,'r');
title('Position and Velocity of a Ball');
xlabel('Time t (seconds)');
ylabel('Height h (meters)');
grid on;

답변 (1개)

Alan Stevens
Alan Stevens 2020년 8월 2일
편집: Alan Stevens 2020년 8월 2일

0 개 추천

Make h and v functions of time. For example;
h = @(t) (0.5)*(g)*t.^2+(v0)*(t)+h0;
Also, make sure you use a different symbol for the input value (i.e. h0 not just h)!
And, of course, you'll need to supply vaues of t.

카테고리

도움말 센터File Exchange에서 Graphics Objects에 대해 자세히 알아보기

질문:

2020년 8월 2일

편집:

2020년 8월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by