Projectile motion in matlab help

In summary, the conversation discusses a need for a MATLAB program that will calculate ball movement and plot the results using user input from a GUI. The program will use given equations and the user will need to enter the height of the launcher, initial launch speed, and launch angle. A code is provided to set up the GUI and take user input, but the user will need to write their own code to calculate the ball movement and plot the result.
  • #1
caseyk
1
0
Hey guys, I'm pretty new to MATLAB and I've been messing around this for a couple hours now and I could use some help.

I need to "Write a MATLAB program that calls at least one user defined function to calculate the ball movement and plot the result in 0.01 second increment before the ball drops to the floor. Use GUI to take the following user input: the height of the launcher (in), initial launch speed (ft/sec), and launch angle from horizon (degree). "

There are a bunch of given equations I can use
"vx = vx0 + ax t x = x0 + vx0t + ½ ax t2 vx2 = vx02 + 2 ax (x – x0)
vy = vy0 + ay t y = y0 + vy0t + ½ ay t2 vy2 = vy02 + 2 ay (y – y0)
For projectile motion, ax = 0, ay = -g, gravity g = 32.2 ft/sec2"

What I need help with is creating the m file that can calculate the motion if the givens are entered into a gui. thanks!
 
Physics news on Phys.org
  • #2
Here is some code you can start with. This code sets up a GUI and takes the user input from the GUI. You will need to write your own code to calculate the ball movement and plot the result. %Create figure window f = figure('Name', 'Projectile Motion'); %Create GUI elements h1 = uicontrol('style','text','string','Height of Launcher (in)','position',[20 100 160 20]); h2 = uicontrol('style','edit','string','','position',[180 100 160 20]); h3 = uicontrol('style','text','string','Initial Launch Speed (ft/sec)','position',[20 60 160 20]); h4 = uicontrol('style','edit','string','','position',[180 60 160 20]); h5 = uicontrol('style','text','string','Launch Angle (degrees)','position',[20 20 160 20]); h6 = uicontrol('style','edit','string','','position',[180 20 160 20]); %Create pushbutton h7 = uicontrol('style','pushbutton','string','Calculate','position',[180 350 160 20],'callback',@calculate); %Callback function for pushbutton function calculate(~,~) %Get user input from GUI height = str2double(get(h2,'string')); speed = str2double(get(h4,'string')); angle = str2double(get(h6,'string')); %Calculate ball motion and plot result %Write code here end
 
  • #3


I would suggest breaking down the problem into smaller parts and tackling them one at a time. First, you can create a user-defined function that calculates the projectile motion using the given equations. This function can take in the initial parameters (height, speed, angle) as inputs and return the x and y coordinates of the projectile at each time increment.

Next, you can create a GUI that takes in the user input for the initial parameters and calls the user-defined function to calculate the motion. The GUI can also plot the trajectory of the projectile using the x and y coordinates from the function.

It may also be helpful to break down the problem into smaller tasks and test each part separately before putting it all together. This can help identify any errors or bugs in the code. Additionally, there are many resources available online for using MATLAB and creating GUIs, so utilizing those can also be helpful in completing this task. Good luck!
 

Related to Projectile motion in matlab help

1. What is projectile motion in Matlab?

Projectile motion in Matlab refers to the mathematical modeling and simulation of the motion of an object that is launched into the air and falls under the influence of gravity. This motion is typically described by the projectile's initial velocity, launch angle, and the acceleration due to gravity.

2. How do I plot the trajectory of a projectile in Matlab?

To plot the trajectory of a projectile in Matlab, you can use the "plot" function and input the x and y coordinates of the projectile at different time intervals. You can also use the "quiver" function to display the velocity vectors of the projectile at different points along the trajectory.

3. Can Matlab calculate the maximum height and range of a projectile?

Yes, Matlab has built-in functions such as "max" and "min" that can calculate the maximum height and range of a projectile. You can also use the "solve" function to find the exact values of these parameters by setting up and solving equations derived from the projectile motion equations.

4. How do I account for air resistance in my projectile motion simulation in Matlab?

To account for air resistance in your simulation, you can use the "ode45" function to solve the differential equations of motion that include the air resistance force. You will need to define the drag coefficient and the air density in your code to accurately model the effect of air resistance on the projectile's motion.

5. Can I use Matlab to optimize the launch angle of a projectile for maximum range?

Yes, you can use Matlab's optimization functions such as "fminbnd" or "fminsearch" to find the launch angle that will result in the maximum range for a given initial velocity and other parameters. You will need to define an objective function that calculates the range of the projectile for a given launch angle and use the optimization function to find the angle that maximizes this objective function.

Similar threads

  • Advanced Physics Homework Help
Replies
3
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
13
Views
2K
  • Introductory Physics Homework Help
Replies
12
Views
3K
  • Introductory Physics Homework Help
Replies
4
Views
1K
  • Introductory Physics Homework Help
Replies
7
Views
4K
  • Introductory Physics Homework Help
Replies
14
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • Programming and Computer Science
Replies
2
Views
16K
  • Introductory Physics Homework Help
Replies
1
Views
4K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
Back
Top