Ok so im a student and we've started doing matlab, unforunately I was ill for the last session so im currently doing it at home myself. The question is unassessed (we are given a few questions then a final assessed question with each session), so if any solutions could have a brief explanation of where they've come from so I understand whats going on.(adsbygoogle = window.adsbygoogle || []).push({});

The first question of the session (our 3rd session 'solving ode's with MATLAB') is as follows:

Using the following given function (projectile.m):

function dydt=projectile(t,y)

g=9.8;

dydt=zeros(2,1); %a column vector

dydt(1)=y(2);

dydt(2)=-g;

end

and the following commands:

>> [T,Y]=ode45(@projectile,[0 12],[0 10]);

>> plot(T,Y(:,1),'-',T,Y(:,2),'-.')

a) Modify the function so that you now solve differential equations for a projectile that is launched at an angle to the horizontal of 60 degrees with an initial velocity of 100m/s at x=0m and y=0m. Set the calculation span of 20 seconds with increments of 0.1 seconds.

My attempt:

[T,Y]=ode45(@projectile,[0:0.1:20],[0 100]);

I know that this will change the velocity and the time span, but how I do I change the angle, and make sure its at x=0?

b) Include the call to the ODE solver function in a seperate m-file script as well as the commands to plot the trajectory of the projectile i.e. y vs x. Use the script to prompt you to input the initial conditions including velocity, angle and intial x an y positions as well as the time interval over which you find the solutions.

My attempt:

As ive not done the first part ive not really started this, im not sure what the first part is asking but im guessing for the inputs I just do something along the lines of:

t_initial=input('Time Start = ')

t_increment=input('Time Increment = ')

t_final=input('Time Finish = ')

y0=input('Initial y = ')

v=input('Velocity = ')

[T,Y]=ode45(@projectile,[t_initial:t_increment:t_final],[y0 v]);

Then add the part for angle and initial x when I know what they are.

c) To check your solution, overlay a plot of the x and y positions calculated from the analytical solutions to these equations.

Not sure on this one

Matlab is all pretty new to me so im having a bit of trouble just understanding what some of the questions are asking.

**Physics Forums | Science Articles, Homework Help, Discussion**

Dismiss Notice

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Homework Help: MATLAB: Solving ode for particle falling under influence of gravity.

Can you offer guidance or do you also need help?

Draft saved
Draft deleted

**Physics Forums | Science Articles, Homework Help, Discussion**