Matlab help to designing a program of a falling object

In summary, the conversation discusses a problem involving a falling object and the need to end the script when the object reaches the ground. The script currently uses an if/for loop to calculate the height and velocity, but there may be other approaches that could be more effective. Suggestions include using the "find" function or a while loop, and considering additional factors such as air resistance in the equations. It is advised to continue experimenting and seeking assistance from other scientists or resources.
  • #1
e_brock123
14
0

Homework Statement


I'm currently new to Matlab and have just started trying to solve a few problems with it. So I have to make a program that will display the results of height and velocity of a falling object, as well as plotting the overall function.

My main concern is I am using an array for t = [0:0.1:20] seconds were I would rather have time go on till h=0. For these equations:
h = (-0.5*g*t.^2 + u*t) + h0
v = u + g*t

So I was just wondering how I can make my script end time when the ball has reached the ground? I am guessing it will be some kind of if/for loop but still a bit unsure.

Homework Equations





The Attempt at a Solution


This is the script I have wrote so far, any help will be greatly appreciated.

% Script file: Position_velocity_ball.m

% constants
g = 9.81; % Acceleration due to gravity
t = 0:0.1:20;

% Get the initial height from the user
h0 = input('Enter the initial height (m):');

% Get the initial velocity from the user
u = input ('Enter the initial velocity (m/s):');

% Calculate the current height of the ball
h = (-0.5*g*t.^2 + u*t) + h0;
disp(['The height of the ball is ' num2str(h) 'm.']);

% Calculate the current velocity
v = u + g*t;
disp(['The velocity of the ball is ' num2str(v) 'm/s']);

% plot the result
plot(v,h);
xlabel('velocity');
ylabel('height');
title('Height versus Velocity');
grid on;
 
Physics news on Phys.org
  • #2


it is important to think about the problem holistically and consider all possible solutions. In this case, you are correct in thinking that an if/for loop could be used to end the script when the ball reaches the ground. However, there may be other approaches that could also work.

One possible solution could be to use the "find" function to determine the index of the time array where the height is equal to or less than zero. This index can then be used to set the upper limit of the time array, effectively stopping the script when the ball reaches the ground.

Another approach could be to use a while loop, where the condition is set to continue until the height is equal to or less than zero. Within the loop, the height and velocity can be recalculated based on the new time array.

It is also important to consider any additional factors that may affect the motion of the falling object, such as air resistance or changes in acceleration. Including these variables in the equations and adjusting the script accordingly will provide a more accurate representation of the object's motion.

Overall, the key is to continue experimenting and trying different approaches until you find a solution that works best for your specific problem. Don't be afraid to ask for help from other scientists or consult resources such as the Matlab documentation for guidance. Good luck with your project!
 

1. What is Matlab and how can it help me design a program for a falling object?

Matlab is a high-level programming language commonly used by scientists and engineers for data analysis, modeling, and simulation. It has built-in functions and tools that can help you create a program to simulate the motion of a falling object, taking into account factors such as gravity and air resistance.

2. Do I need prior programming experience to use Matlab for this task?

While prior programming experience can be helpful, it is not necessary to use Matlab for designing a program for a falling object. Matlab has a user-friendly interface and many resources available, such as tutorials and documentation, to help beginners get started.

3. Can Matlab help me visualize the motion of a falling object?

Yes, Matlab has powerful visualization tools that can help you create graphs and animations to visualize the motion of a falling object. These visualizations can provide valuable insights and aid in understanding the behavior of the object.

4. How accurate are the results generated by a Matlab program for a falling object?

The accuracy of the results will depend on the accuracy of the input parameters and the complexity of the program. Matlab has a high level of precision and can handle complex calculations, so if the program is designed well and the inputs are accurate, the results should be highly accurate.

5. Can I use Matlab to optimize the design of a falling object for a specific goal?

Yes, Matlab has optimization tools that can help you find the optimal design for a falling object based on a specific goal, such as minimizing air resistance or maximizing speed. These tools can save time and effort in the design process and help you achieve the desired outcome.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
1
Views
914
  • Engineering and Comp Sci Homework Help
Replies
2
Views
764
  • Engineering and Comp Sci Homework Help
Replies
3
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
15
Views
2K
  • Introductory Physics Homework Help
Replies
25
Views
386
  • Introductory Physics Homework Help
Replies
34
Views
595
  • Engineering and Comp Sci Homework Help
Replies
10
Views
2K
  • Introductory Physics Homework Help
2
Replies
38
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
3K
Back
Top