Plotting a Quarter Circle in MATLAB

  • Thread starter Thread starter jhnreid86
  • Start date Start date
  • Tags Tags
    Matlab Plot
Click For Summary
To plot a quarter circle in MATLAB, the user is attempting to create a vector x ranging from 0 to 1 and calculate corresponding y values using the equation y = sqrt(1 - x^2). The user encounters an error due to attempting to access the zeroeth index of the vector x, which is not valid in MATLAB as indexing starts at 1. The solution involves modifying the loop to start from 1 instead of 0 to avoid this indexing issue. With the correct indexing, the plot should display the desired quarter circle accurately.
jhnreid86
Messages
1
Reaction score
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
you are trying to access the zeroeth index, MATLAB indices start with 1 and not 0.
 

Similar threads

  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
7
Views
2K
  • · Replies 6 ·
Replies
6
Views
2K
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 10 ·
Replies
10
Views
2K
Replies
2
Views
1K
  • · Replies 3 ·
Replies
3
Views
2K