Solving Projectile Motion Problem Using ODE Solvers in MATLAB

  • Thread starter jcsolis
  • Start date
  • Tags
    Matlab
In summary, the student is working on a research project involving MATLAB problems using ODE solvers. One of the problems is about an object following a projectile motion and the student attempted to solve it using ode15s. However, there was a typo in the equation for acceleration, resulting in a plot that did not resemble a projectile path. The student is seeking help to correct the error.
  • #1
jcsolis
38
1
Hello guys, I will work next summer session doing research with a professor and he asked me to do a couple of MATLAB problems using ODE solvers so I can get more familiar since I will be using it. One of the problems is about an object following a projectile motion and I need to solve it using ode15s and then plot the trajectory of the object.

Homework Statement



The given data for the object mass, initial velocity, angle, and gravity
m = 0.25 kg
v0 = 10 m/s
alpha = 45 degrees
g = 9.81 m/s^2


Homework Equations



The system of first order ODEs is the following

y'1= y2
y'2 = 0
y'3 = y4
y'4 = -g/m

Initial Conditions

y1(0) = 0
y2(0) = 0
y3(0) = Vo Cos(alpha)
y4(0) = Vo Sin (alpha)

Attempted Solution

Here is my M-File

function ydot = exercise1(t,y)
ydot = zeros(4,1);
ydot(1) = y(2);
ydot(2) = 0;
ydot(3) = y(4);
ydot(4) = -g/m;


Then on the command window I set up the given data
>> m = 0.25;
g = 9.81;
v = 10;
alpha = pi/4;
a = v*cos(alpha);
b = v*sin(alpha);

I run the program using ode15s and here is the result:

>> [T Y] = ode15s(@exercise1, [0 15], [0 a 0 b])

T =

0
0.0002
0.0004
0.0005
0.0018
0.0030
0.0042
0.0055
0.0161
0.0266
0.0372
0.0478
0.1536
0.2594
0.3653
0.4711
1.5293
2.5876
3.6458
4.7040
6.2040
7.7040
9.2040
10.7040
12.2040
13.7040
15.0000


Y =

1.0e+003 *

0 0.0071 0 0.0071
0.0000 0.0071 0.0000 0.0071
0.0000 0.0071 0.0000 0.0071
0.0000 0.0071 0.0000 0.0070
0.0000 0.0071 0.0000 0.0070
0.0000 0.0071 0.0000 0.0070
0.0000 0.0071 0.0000 0.0069
0.0000 0.0071 0.0000 0.0069
0.0001 0.0071 0.0001 0.0064
0.0002 0.0071 0.0002 0.0060
0.0003 0.0071 0.0002 0.0056
0.0003 0.0071 0.0003 0.0052
0.0011 0.0071 0.0006 0.0010
0.0018 0.0071 0.0005 -0.0031
0.0026 0.0071 -0.0000 -0.0073
0.0033 0.0071 -0.0010 -0.0114
0.0108 0.0071 -0.0351 -0.0529
0.0183 0.0071 -0.1131 -0.0945
0.0258 0.0071 -0.2350 -0.1360
0.0333 0.0071 -0.4009 -0.1775
0.0439 0.0071 -0.7113 -0.2364
0.0545 0.0071 -1.1100 -0.2952
0.0651 0.0071 -1.5970 -0.3541
0.0757 0.0071 -2.1723 -0.4130
0.0863 0.0071 -2.8359 -0.4718
0.0969 0.0071 -3.5877 -0.5307
0.1061 0.0071 -4.3084 -0.5815

I plotted the y versus x

>> plot(Y(:,1),Y(:,3))

the plot is attached so you can see the result, it is supposedly to look as a projectile path but my plot looks like a projectile going all the way down.

if someone can help me to see what I am doing wrong I would be really appreciated

Thank You guys :cool:
 

Attachments

  • motion.jpg
    motion.jpg
    10.9 KB · Views: 384
Physics news on Phys.org
  • #2
It looks like everything is okay except for your acceleration value - why is your equation for acceleration -g/m?

If you look at your data, you will see that the object does move up before it goes down as it should. You have a typo in your 'Relevant Equations' section (what you have for y(3) should be under y(2)) but it appears you did that part correctly when you retyped it later on.

Also, fyi, you can use the 'axis equal' command to rescale the graph which may be appropriate for this exercise (both the x and y axes are in meters).
 

Related to Solving Projectile Motion Problem Using ODE Solvers in MATLAB

1. What is MATLAB and what can it be used for?

MATLAB is a programming language and interactive environment commonly used by scientists and engineers for data analysis, mathematical modeling, and simulation. It can also be used for creating and executing algorithms, developing graphical user interfaces, and creating applications.

2. How can I get help with a specific MATLAB problem?

There are several resources for getting help with MATLAB problems, including the official MATLAB documentation, online forums and communities, and paid support services. Additionally, many universities and research institutions offer workshops and courses on using MATLAB.

3. What are some common errors encountered while using MATLAB?

Some common errors in MATLAB include syntax errors, variable errors, and function errors. These can often be resolved by carefully checking the code and making necessary corrections. It is also helpful to consult the MATLAB documentation or online forums for troubleshooting advice.

4. How can I improve my skills in using MATLAB?

Practice is key to improving your skills in using MATLAB. You can also attend workshops or take online courses to learn new techniques and features. Additionally, reading through the official MATLAB documentation and solving practice problems can help you become more proficient in the language.

5. Can MATLAB be used for data analysis and visualization?

Yes, MATLAB is a powerful tool for data analysis and visualization. It offers a variety of built-in functions and tools for working with data, as well as the ability to create professional-looking visualizations such as plots, charts, and graphs. It also has the capability to work with large datasets and perform complex statistical analyses.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
3K
  • Introductory Physics Homework Help
Replies
5
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
4K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
8K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
5K
Back
Top