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


  1. Oct 17, 2005 #1
    Maybe not the proper place to post... but it seems like physics forums is going through some type of "crazy" change right now. Anyways... I'm having trouble finding a website with directions on how to plot a system of equations in MATLAB. If anyone has a basic M-file they could show me, or a tutorial... that'd be really awesome! Thanks for the help :)
  2. jcsd
  3. Oct 17, 2005 #2


    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    Code (Text):

    x=[-5:.1:5]; % x is a vector containing the numbers -5, -4.9, -4.8, ..., 4.9, 5. Semicolon means don't display to screen
    y=4x.^3 - 2x.^2 - 12; % The '.'^ raises each element of the vector to the power listed.
                                    % If you just did ^ it would do matrix multiplication which doesn't work unless the matrix is square.

    plot(x,y,'r*') % Plot variable X on the horizontal axis, y on the vertical, and display the points as red stars
    Is that what you wanted, or did you need something more?
  4. Oct 17, 2005 #3
    Actually, I already knew about the plot command. What I didn't know is that you can plot multiple equations with it.



    But thanks for the reply :smile:
  5. Oct 17, 2005 #4


    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    Ah, ok.

    You can also skip the 'xxx' and have it automatically assign the colors.

    Another way to do it is to hold the plot like so:

    Code (Text):



    hold on


    hold off
    You can also simply type 'hold' to toggle it.
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Similar Discussions: MATLAB Help
  1. MATLAB help (Replies: 9)

  2. MATLAB help (Replies: 2)

  3. MATLAB help (Replies: 0)

  4. MATLAB help (Replies: 7)

  5. Matlab help (Replies: 6)