# How to draw a circle using matlab

Written by joe friedman
• Share
• Tweet
• Share
• Email

MATLAB is a powerful mathematical and engineering computer software program capable of advanced mathematical calculations and engineering simulations. One of its common uses is plotting data. Plotting a circle, however, takes a small trick. The equation of a circle of radius "q" is y = +/- sqrt(q^2 - x^2), and MATLAB doesn't handle a "+/-" term well. The solution is to plot two graphs on the same axes -- one the positive version of the equation and one the negative version of the equation.

Skill level:
Moderately Easy

## Instructions

1. 1

Define a range of "x" values over which to plot the circle. Type "x = [-1:0.01:1];" and press "Enter."

2. 2

Define the top half of the circle by typing "y = sqrt(1-x.^2);" Notice in this case that the radius "q" is 1.

3. 3

Define the bottom half of the circle by typing "z = -sqrt(1-x.^2);" Notice in this case that the radius "q" is still 1.

4. 4

Plot the circle by plotting both halves on the same axes. Type "plot(x,y,x,z)" and a window will pop up with the circle. Notice that the top half and bottom half of the circle will have different colours, representing the two different equations that were actually graphed to make the complete circle.

### Don't Miss

#### References

• All types
• Articles
• Slideshows
• Videos
##### Sort:
• Most relevant
• Most popular
• Most recent