Matlab Write a function Mfile PlotCirclesm that accepts as i

Matlab: Write a function M-file, PlotCircles.m, that accepts as input a vector, r, having positive entries, and plots circles of radius r(i) centered at the origin on the same axes. If no input value for r is specified, the default is to plot a single circle with radius r=1. Test your function with r=1:5. Hint: Use matlab commands max, min, any. So far I have:

function PlotCircle(r)

theta = linspace(0,2*pi,200);

if nargin == 0

r = 1;

end

for i = min(r):max(r)

x = i*cos(theta);

y = i*sin(theta);

plot(x,y)

axis([-2*r 2*r -2*r 2*r])

axis square

end

But it is having errors.

Solution

// Here is the corrected method without any error

function PlotCircle(r)

   theta = linspace(0,2*pi,200);
   if nargin == 0
       r = [1];
   end
max_r = max(r)
   axis([-2*max_r 2*max_r -2*max_r 2*max_r])
   axis square  
   for i = min(r):max(r)
       x = i*cos(theta);
       y = i*sin(theta);
       plot(x,y)
   end
end

Matlab: Write a function M-file, PlotCircles.m, that accepts as input a vector, r, having positive entries, and plots circles of radius r(i) centered at the ori

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site