How to Plot a Parabola in MATLAB

Written by michael peter
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to Plot a Parabola in MATLAB
Create a parabola in MATLAB by inputting the parabola equation and plotting the results. (Comstock/Comstock/Getty Images)

The technical computing software MATLAB allows users to create data which is stored in arrays and matrices for further manipulation and processing. Often it is necessary to input this data into an equation which creates an entirely new data set that is a function of the original data. While no MATLAB functions directly create a parabola, one can be created in MATLAB by inputting a general parabola equation. After doing this, the data can be plotted using the plotting functions built into MATLAB.

Skill level:


  1. 1

    Clear all active variables in the workspace by entering "clear all" in the MATLAB command window.

  2. 2

    Create the "x" data. Input "x=-100:1:100;" into the Command window. This creates a 201 element array starting at -100 and ending at 100.

  3. 3

    Create the "y" data by inputting the equation for a parabola into MATLAB. The general equation for a parabola is "y=(x^2)/(4p)" where "p" is the focal distance. Inputting the general parabola into MATLAB with "p=1" gives "y=(x.^2)/(41);" which creates an array of 201 elements. The "x." indicates array multiplication.

  4. 4

    Plot the data created in Step 2 and 3 by inputting "plot(x,y)" into the Command window. A new window titled "Figure 1" will appear showing a parabola using a solid line. Change the focal distance "p" to see the effect that parameter has on the appearance of the parabola.

Tips and warnings

  • Omitting the "." gives the error "??? Error using ==> mpower Inputs must be a scalar and a square matrix."
  • Rotate the parabola 90 degrees by using the equation "y^2=4*p*x."

Don't Miss

  • All types
  • Articles
  • Slideshows
  • Videos
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the site, you consent to the use of cookies. For more information, please see our Cookie policy.