Calculating Projectile Distance with MATLAB: Physics Homework Help

  • Thread starter Thread starter cphill29
  • Start date Start date
  • Tags Tags
    Matlab Physics
AI Thread Summary
The discussion focuses on creating a MATLAB script to calculate the necessary spring compression for a projectile launched at 45 degrees to achieve specific distances. The user expresses uncertainty about how to start coding in MATLAB, despite having basic computation skills. Participants recommend first solving the problem manually to understand the physics involved before translating it into code. They suggest utilizing MATLAB's capabilities for iterations and numerical methods, emphasizing the importance of learning programming for engineering applications. The conversation highlights the need for foundational knowledge in both physics and MATLAB to effectively tackle the assignment.
cphill29
Messages
16
Reaction score
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
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.
 
That's not the issue. I need help setting up the MATLAB code. I can deal with the units later.
 
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
start by determining how you would solve this by hand. Once you know that, you simply move the implementation into the code.
 
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.
 
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...
 
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.
 
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
Back
Top