# Plotting a Quarter Circle in MATLAB

• jhnreid86
The correct code would be "for i = 1:length(x)". This will plot a quarter of a circle by creating a vector of x values from 0 to 1 and then plotting the corresponding y values using the equation y = sqrt(1 - x^2).
jhnreid86

## Homework Statement

I am trying to plot simply a quarter of a circle but am having difficulty with it.

## The Attempt at a Solution

So far I have

x = 0:0.01:1;

for i = 0:length(x)

y = sqrt(1 - x(i)^2);

plot(x,y,'b-')

end

Basically what I am trying to do here is create a vector x with values from 0 to 1, and then plot each corresponding y coordinate.

I keep getting the following error

? Attempted to access x(0); index must be a positive integer or logical.

Error in ==> Untitled5 at 5
y = sqrt(1 - x(i)^2);

Any help would be greatly appreciated!

you are trying to access the zeroeth index, MATLAB indices start with 1 and not 0.

## 1. How do I plot a quarter circle in MATLAB?

To plot a quarter circle in MATLAB, you can use the "plot" function with the appropriate x and y values. For a quarter circle, the x values would be the range of angles from 0 to 90 degrees (or 0 to pi/2 in radians), and the y values would be the corresponding values on the circle, calculated using the sine or cosine function.

## 2. Can I change the size or shape of the quarter circle?

Yes, you can change the size or shape of the quarter circle by adjusting the range of angles and/or the values used to calculate the y values. For example, if you want a larger quarter circle, you can increase the range of angles or multiply the y values by a scaling factor.

## 3. How do I add labels and a title to my quarter circle plot?

To add labels and a title to your quarter circle plot, you can use the "xlabel", "ylabel", and "title" functions. These functions allow you to specify the text and formatting for each label and title.

## 4. Can I plot multiple quarter circles on the same graph?

Yes, you can plot multiple quarter circles on the same graph by using the "hold on" command before each "plot" function call. This will prevent the previous plot from being erased and allow you to add more plots to the same graph.

## 5. How can I save my quarter circle plot as an image file?

You can save your quarter circle plot as an image file by using the "saveas" function. This function allows you to specify the file name and format (e.g. PNG, JPEG) for the saved image.

• Engineering and Comp Sci Homework Help
Replies
1
Views
1K
• Engineering and Comp Sci Homework Help
Replies
10
Views
2K
• Engineering and Comp Sci Homework Help
Replies
6
Views
1K
• Engineering and Comp Sci Homework Help
Replies
2
Views
970
• Engineering and Comp Sci Homework Help
Replies
1
Views
1K
• Engineering and Comp Sci Homework Help
Replies
2
Views
1K
• Calculus and Beyond Homework Help
Replies
10
Views
1K
• Engineering and Comp Sci Homework Help
Replies
3
Views
967
• MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
407
• Engineering and Comp Sci Homework Help
Replies
7
Views
1K