Writing an m-file with ODE45 for a projectile problem

  • Context: MATLAB 
  • Thread starter Thread starter faust9
  • Start date Start date
  • Tags Tags
    Matlab
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
1 reply · 3K views
faust9
Messages
690
Reaction score
2
ARGH! Matlab trouble!

Ok, I'm having a big problem as described here: https://www.physicsforums.com/showthread.php?t=46950

Basically, I've never used MATLAB and was given an assignment on friday which requires that I use matlab. First off, could someone please help me with my projectile problem?

Next, how the heck does one write an m-file. I know how to open the editor and the simple stuff but actually using ODE45 is killing me. The help file is about as useful as a man file--good for pro's lousy for novices.

Any help would be greatly appreciated.
 
Physics news on Phys.org
If you haven't already figured it out, there's nothing much to an .m file. Since i do not warez matlab, I'm using vim (a text editor) and octave. Basically what goes in a .m file is something like this
Code:
function returnValue = f(x)
     returnValue = 2*x^2 + 3*x+2
end

format long %for displaying more digits
result1 = f(4)
results = zeros(1,10); %creates a vector full of zeros, 10 big
results(1) =  f(6);
results(5)  = f(24);