Answer to Question #303085 in MatLAB for MR Z

Question #303085

Write a short comment explaining the code:


function DrawCircle(a, b, r)

%DRAWCIRCLE draws a circle on the coordinate plane

% a and b are the x-axis and y-axis coordinates of the center

% of the circle and r is its radius


t = 0:pi/180:2*pi;

x = r*cos(t) + a;

y = r*sin(t) + b;


plot(x, y, '-', a, b, '.');

axis equal

axis padded


text(a, b,'\leftarrow center')

title("The circle of radius " + string(r));

xlabel("X");

ylabel("Y")


end


1
Expert's answer
2022-03-01T15:34:35-0500
function DrawCircle(a, b, r)

%DRAWCIRCLE draws a circle on the coordinate plane

% a and b are the x-axis and y-axis coordinates of the center

% of the circle and r is its radius

%create array of parameters from 0 to 2pi with step pi/180
t = 0:pi/180:2*pi;

% calculate x and y coordinates for each t
x = r*cos(t) + a;
y = r*sin(t) + b;

% plot y vs x
plot(x, y, '-', a, b, '.');

% format graph
axis equal
axis padded
text(a, b,'\leftarrow center')
title("The circle of radius " + string(r));
xlabel("X");
ylabel("Y")

end

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS