Calculating Projectile Distance with MATLAB: Physics Homework Help

In summary, the conversation revolves around a student seeking help with writing a MATLAB script to calculate the horizontal distance of a projectile fired from a cannon. The necessary variables and equations are provided, but the student has no experience with MATLAB and is unsure how to approach the problem. Suggestions are given to spend time learning MATLAB and to break down the problem into smaller parts to solve it. The importance of being able to write basic code as an engineering major is also emphasized.
  • #1
cphill29
16
1

Homework Statement


I have to write a MATLAB script that calculates the horizontal distance of a projectile fired from a cannon set at 45 degrees by a compressed spring. I know that the spring constant is 6 lb/in, the unstretched length of the spring is 1 foot, the mass of the projectile is 0.1 lb, and the projectile has to land 10, 12, and 14 feet away. How much spring compression is needed to hit these three lengths?

Homework Equations


KE+PE=KE+PE

The Attempt at a Solution


I really have no idea how to even begin. I have this so far

>>g=-32.2
>>m=0.1
>>k=6
>>d=1

I think I need some kind of loop? I really need some help here.
 
Physics news on Phys.org
  • #2
I would start by adding some units, maybe converting to SI units. Sure it can be done using imperial but if you are not sure where to start, I think imperial units mat confuse you more. You have the Mass of the projectile in pounds (mass) and spring constant using pounds(force) to start.
 
  • #3
That's not the issue. I need help setting up the MATLAB code. I can deal with the units later.
 
  • #4
cphill29 said:
That's not the issue. I need help setting up the MATLAB code. I can deal with the units later.
Have you worked with programming langues before?
Typically you KNOW what you want the program to solve first. The implimentation comes later.

Do you know how to solve problems like this, and your question is purely about how MATLAB works?
Or are you struggling with how to solve the problem?
Or do you not know how to solve problems with programming langues?
 
  • Like
Likes scottdave
  • #5
start by determining how you would solve this by hand. Once you know that, you simply move the implementation into the code.
 
  • #6
donpacino said:
Have you worked with programming langues before?
Typically you KNOW what you want the program to solve first. The implimentation comes later.

Do you know how to solve problems like this, and your question is purely about how MATLAB works?
Or are you struggling with how to solve the problem?
Or do you not know how to solve problems with programming langues?

I have next to no experience with matlab. I would try and solve for the initial velocity that I need for each given distance, but I'm not sure how to make that into a MATLAB code. Getting that by trial and error by hand would take an eternity.
 
  • #7
cphill29 said:
I have next to no experience with matlab. I would try and solve for the initial velocity that I need for each given distance, but I'm not sure how to make that into a MATLAB code. Getting that by trial and error by hand would take an eternity.
Why do you have an assignment to use MATLAB to do this, and you have NO experience or instruction in using MATLAB? Something is not adding up here...
 
  • #8
berkeman said:
Why do you have an assignment to use MATLAB to do this, and you have NO experience or instruction in using MATLAB? Something is not adding up here...
Because MATLAB isn't required for chemical engineering majors at my school, but dynamics is, and this is a dynamics problem. I also didn't say I have no experience at all, but next to none, meaning very little. I can do basic computations but this one is out of my league.
 
  • #9
Then I'd recommend spending some time with some MATLAB learning resources. There are many of them, from the MATLAB website to YouTube videos to other tutorial and example web pages. We cannot write your code for you here -- that's not how the PF schoolwork help forums work.
 
  • #10
Is your problem statement the exact wording of the assignment? From what I read is not clear just *how* you are to make use of MATLAB to solve the problem.

MATLAB is capable of simply doing the math for expression that you type in, but it can also numerically "integrate" differential equations, or home in on solutions by iteration, or...

There are a lot of different ways to employ such a versatile tool. For example, you could use vector/matrix variables to solve several instances ("inputs") for the problem at once, or simply chug through the math separately for each of the inputs. Write a function to return the desired result for a given input perhaps.
 
  • Like
Likes berkeman
  • #11
You could write the formula that you want to solve. Then if it is something where there is not a nice closed form solution to get the amount of spring compression then you can use Matlab or something else (even a spreadsheet) to go through the iterations or do something like Newton's method.
 
  • Like
Likes donpacino and berkeman
  • #12
It's my opinion that every engineering major should be able to write some kind of code to do some loops and some basic iterative calculations (like Newton's method, Euler's method, etc). Whether it's Matlab or something else like Excel or Python, it's good to know how to whip something like that up. It's part of being a problem solver. It is good practice for you. As to how you figure how to code it in Matlab, there are lots of online resources for that as somebody else said.

stackoverflow.com or youtube are places to start.
 
  • Like
Likes donpacino and berkeman
  • #13
cphill29 said:
I have next to no experience with matlab. I would try and solve for the initial velocity that I need for each given distance, but I'm not sure how to make that into a MATLAB code. Getting that by trial and error by hand would take an eternity.

People have been solving these problems by hand way before computers. Computers simply preform the computations to make life easier.
How would you solve this problem if you were given it on a test. This is easily a problem that could be given in a physics test, maybe even a no calculator physics test. (note: by include on a test I mean setup the equations)
 
  • #14
to start, why don't you setup the equations for determining how fast the projectile has to be the moment it leaves the spring
 
  • Like
Likes scottdave

What is MATLAB and how is it used in physics?

MATLAB is a high-level programming language and interactive environment designed for scientific computing. It is commonly used in physics for data analysis, simulation, and visualization.

Can I use MATLAB for solving complex mathematical equations in physics?

Yes, MATLAB has a powerful built-in library of mathematical functions and tools that make it well-suited for solving complex equations in physics.

How can MATLAB help with data analysis in physics experiments?

MATLAB has a variety of tools and functions for data analysis, such as curve fitting, statistical analysis, and signal processing. These tools can help researchers extract meaningful insights from experimental data in physics.

Is it necessary to have a background in coding to use MATLAB for physics?

While having coding experience can be helpful, it is not necessary to have a background in coding to use MATLAB for physics. The user-friendly interface and extensive documentation make it accessible for beginners.

Can MATLAB be used for simulations in physics?

Yes, MATLAB has a simulation tool called Simulink that allows for the creation and analysis of dynamic systems. It is commonly used in physics for simulating complex physical systems and phenomena.

Similar threads

  • Introductory Physics Homework Help
Replies
11
Views
806
  • Introductory Physics Homework Help
Replies
4
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
5
Views
1K
  • Introductory Physics Homework Help
Replies
7
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
10
Views
2K
  • Engineering and Comp Sci Homework Help
2
Replies
40
Views
4K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
2K
  • Introductory Physics Homework Help
Replies
4
Views
978
  • Introductory Physics Homework Help
Replies
1
Views
2K
  • Introductory Physics Homework Help
Replies
1
Views
638
Back
Top