27.5k views
3 votes
In MATLAB please.

Write a function called circle that takes a scalar input r. It needs to return an output called area that is the area of a circle with radius r and a second output, cf that is the circumference of the same circle. You are allowed to use the built-in function pi. In fact, you need to use it to get the value of π as accurately as possible.

User Drby
by
4.4k points

1 Answer

3 votes

Answer:

function [Area,Perimeter,L]=f_circle(x)

% Area: pi*x^2 area of circle with radius x

% Perimeter: 2*pi*x perimeter length of circle with radius x

% x can be a vector

minargs=1;maxargs=1;narginchk(minargs,maxargs); % only 1 input accepted

if ~isequal('double',class(x)) 5 input has to be type double

disp('input type not double');

return;

end

Area=pi*x.^2;

Perimeter=2*pi*x;

end

User Andranikasl
by
5.1k points