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.
Clear all active variables in the workspace by entering "clear all" in the MATLAB command window.
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.
Create the "y" data by inputting the equation for a parabola into MATLAB. The general equation for a parabola is "y=(x^2)/(4_p)" where "p" is the focal distance. Inputting the general parabola into MATLAB with "p=1" gives "y=(x.^2)/(4_1);" which creates an array of 201 elements. The "x." indicates array multiplication.
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.
- 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."
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."