MATLAB: Write a function called circle that takes a scalar input x. It needs to return an output called area that is a area of a circle with radius x and a second output of that is the circumference of the same circle. You are allowed to use the built in f

this is my homework

Write a function called circle that takes a scalar input x. It needs to return an output called area that is a area of a circle with radius x and a second output of 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 pi accurately as possible.

Best Answer

Hi Prabhleen
let me call the function f_circle, to avoid conflict with for example the already existing function circle in the RF toolbox.
Your function:
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
Prabhleen
would you please be so kind to mark my answer as Accepted Answer?
To any other reader, please if you find this answer of any help solving your question,
please click on the thumbs-up vote link,
thanks in advance
John BG