Plotting a Quarter Circle in MATLAB

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).
  • #1
jhnreid86
1
0

Homework Statement



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




Homework Equations





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!
 
Physics news on Phys.org
  • #2
you are trying to access the zeroeth index, MATLAB indices start with 1 and not 0.
 

FAQ: Plotting a Quarter Circle in MATLAB

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.

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.

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.

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.

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.

Similar threads

Replies
10
Views
2K
Replies
1
Views
1K
Replies
6
Views
1K
Replies
1
Views
1K
Replies
10
Views
1K
Replies
1
Views
2K
Replies
8
Views
862
Back
Top