Contact Us!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

| Download
Views: 13
Image: ubuntu2204
Kernel: Octave 8.2

To start this question, first execute the following code cell

radii = [1, 3, 5, 9];

Using a for loop (see lab 1) and the recommended parametrization of a circle (see lab 2) plot a circle with each radius in the array radii centered at (x0,y0)=(1,3)(x_0, y_0) = (1,-3).

Make sure all of the circles appear in the same figure and are not overwritten.

Label the axes with xx and yy

Include comments explaining what each line of the code does.

radii = [1, 3, 5, 9]; % Define the center of the circles x0 = 1; y0 = -3; % Define theta values for full circles theta = linspace(0, 2*pi, 100); % Create a figure figure; hold on; % Ensures all circles are plotted on the same figure axis equal; % Keep aspect ratio of circles correct % Loop through each radius in the array for r = radii % Parametric equations for the circle x = x0 + r * cos(theta); y = y0 + r * sin(theta); plot(x, y, 'LineWidth', 4); end % Label axes xlabel('x'); ylabel('y'); title('Circles of Different Radii'); % Show grid grid on; hold off;
Image in a Jupyter notebook

Repeat the plots above, but plotting only the left half of the circles.

radii = [1, 3, 5, 9]; % Define the center of the circles x0 = 1; y0 = -3; % Define theta values for the left half-circle (π/2 to 3π/2) theta_left = linspace(pi/2, 3*pi/2, 50); % Create a new figure figure; hold on; axis equal; % Loop through each radius in the array for r = radii % Parametric equations for the left half-circle x = x0 + r * cos(theta_left); y = y0 + r * sin(theta_left); % Plot the left half-circle plot(x, y, 'LineWidth', 4); end % Label axes xlabel('x'); ylabel('y'); title('Left Half of Circles'); xlim([-10, 5]); ylim([-15, 7]); grid on; hold off;
Image in a Jupyter notebook