Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Need some help with basics of MATLAB

  1. May 18, 2009 #1
    I need some help with some basic MATLAB questions.

    1) When writing a MATLAB code, do I create a blank new M-file, and write it there?

    2) I need the program to calculate values for an equation, as I vary two variable within the equation. I'm unsure how to do this (for example, how do I define the variables, etc)

    For example, say the equation is y = x^(-0.5) +z^(ln(x));

    I want the program to give me values for y when i input different values for x and z. How is this accomplished?

    If anyone can point me to good MATLAB tutorials that go into this kind of detail, I'd appreciate it. I've looked, including MATLABs help, and havent found anything regarding equations and variables, etc.

    Lastly, how do you comment in MATLAB?
  2. jcsd
  3. May 18, 2009 #2


    User Avatar
    Science Advisor

    There are hundreds of web pages out there that give the basics for how to do these things in Matlab. A quick Google search will get you going.
  4. May 18, 2009 #3


    User Avatar
    Science Advisor
    Gold Member

    And the Help-files that come with Matlab are actually very good...
  5. May 18, 2009 #4

    Can anyone provide some actual help regarding these questions?
  6. May 18, 2009 #5


    User Avatar
    Science Advisor

    Regarding this specific question, you're probably looking for an inline function:

    That's the serial way of doing things. However, you can often perform operations on entire vectors. If you wanted to calculate, say, sin(x) between 0 and 2pi, in increments of 1/200*pi (and then plot the result), you'd do the following:

    >> x=0:1/200*pi:2*pi %The colon format goes start:increment:end
    >> y=sin(x) %This will generate a vector of y values for a bunch of x's
    >> plot(x,y)

    Additionally, perhaps start here:

    Or here:

    But if you need a quick reference for a command within MATLAB, just type help COMMAND, for instance, getting help about the identity matrix creation function:
    >> help eye
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Similar Discussions: Need some help with basics of MATLAB