Help me Solve MATLAB Projectile Problem & Write an m-file

  • MATLAB
  • Thread starter faust9
  • Start date
  • Tags
    Matlab
In summary: Frequency response of sinusoid');In summary, the author is having trouble with MATLAB and needs help with a projectile problem. Next, the author does not know how to write an M-file and needs help from someone more experienced. Lastly, the author provides a summary of how to use an M-file and how to create a function in MATLAB.
  • #1
faust9
692
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
  • #2
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);
 
  • #3
Dont know about the projectile project but with the m - file i could help...
open a new m-file which can be found in File, then New... after which click on M-file...

Here u type in your code... when your done save it and give it a name (obviously... hehehe) now u can call your M-file from the command window in the main page...

however, if u want to make your own functions, wherein a created m-file will act like a regular function in matlab... all the functions in the MATLAB library have m-files as well... search for function in help to get details... to see what I am talking about type this: type specgram

upon pressing enter, the entire code will come up... that's basically the same thing u need to do... the help for function is fairly easy to use...

hope i helped! Ü
 
  • #4
Here's an example of an m-file i made

function [mag,f] = ffttrue(input,Fs)

framed = input;
lpf = lowpassf(framed,Fs) % fitered signal
X = fft(lpf); % FFT of signal
X(1) = 0;
N = length(X); % N = length of fft
mag = abs(X);
f = [0:N-1]*Fs/(N-1); % frequency vector

figure;plot(f,mag); % plot magnitude
xlabel('Frequency (Hertz)');
ylabel('X');
axis([0,680,0,max(mag)]); % display only frequencies < fs/2
 

What is a MATLAB Projectile Problem?

A MATLAB Projectile Problem is a physics problem that involves calculating the trajectory of an object launched into the air with a given initial velocity and angle. It is typically solved using the principles of projectile motion and requires the use of MATLAB programming language.

What is an m-file?

An m-file is a type of file that contains MATLAB code. It is used to write and store functions, scripts, and other MATLAB commands. These files have a .m extension and are the primary way of writing and executing code in MATLAB.

How can I solve a MATLAB Projectile Problem?

To solve a MATLAB Projectile Problem, you can use the built-in functions and commands in MATLAB that deal with projectile motion, such as "plot" and "solve." You can also write your own code using the principles of projectile motion and run it as an m-file.

What are the steps to solve a MATLAB Projectile Problem?

The steps to solve a MATLAB Projectile Problem include defining the initial conditions (velocity and angle), setting up the equations of motion, creating a time vector, using MATLAB functions to calculate the trajectory, and plotting the results. It is important to also check for errors and adjust the code if necessary.

Can you provide an example of a MATLAB Projectile Problem and its solution?

Yes, an example of a MATLAB Projectile Problem is finding the maximum height and horizontal distance traveled by a ball launched at an angle of 30 degrees with an initial velocity of 20 m/s. The solution involves using the equations of motion and plotting the trajectory using MATLAB functions. A sample m-file for this problem can be found online.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
995
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • Introductory Physics Homework Help
Replies
5
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
7
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
Back
Top