Having difficulty getting the program right
Mostrar comentarios más antiguos
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;
Respuestas (1)
Alan Stevens
el 2 de Ag. de 2020
Editada: Alan Stevens
el 2 de Ag. de 2020
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.
Categorías
Más información sobre Graphics Objects en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!