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 fun
Show older comments
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.
Answers (2)
Image Analyst
on 14 Aug 2016
3 votes
1 Comment
Image Analyst
on 20 Aug 2016
From your comment to John, it doesn't appear that you read or took the advice in the link I gave you, so you can unaccept my Answer since it didn't help you, though it could have.
I have fixed your formatting so people can read it.
John BG
on 14 Aug 2016
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
6 Comments
Prabhleen Kaur
on 19 Aug 2016
John BG
on 20 Aug 2016
Dear Prabhleen Kaur
you have marked as accepted answer the link of Image Analyst to the recommendations how to ask questions.
That is not answering your or any other question, it's just advice how to ask questions.
Regarding the error, may I read the code you use to run the function?
Please post here the test you run to use the function.
I consider once we have fixed the type double error, my answer deserves to be marked as accepted.
Awaiting your code, post it here or send it to my email
regards
John BG
the error code that Prabhleen gets it's clearly from attempting to invoke a function called
f_circle
with
circle
any one can see that Prabhleen understood this point, AFTER having posted the question mentioning the error message
Undefined function or method 'circle' for input arguments of type 'double'.
Prabhleen has realised that there is a MATLAB function called circle, Smith chart related, which is not the function at all answering this particular question.
Therefore, because the function works, and because the only one who has supplied a working answer here is me, I honestly consider that I deserve this Accepted Answer.
- suggesting it's homework is not an answer
- changing the question tag to 'this is homework' may cause an adverse attitude to this and other forum users towards Prabhleen questions and answers, which may be, without evidence, considered discriminatory.
I don't know whether Prabhleen's question is homework, but I assume it isn't and I have answered it correctly.
Attempting to prevent others supplying answers to questions that have reasonable grounds to be considered not homework, is also, against MATLAB forum rules.
Acting on grounds of unknown towards a constructive solution, like providing a working answer, is far more beneficial to every one that attempting to prevent on same unknown grounds.
With all the time that from the question posted to present, no one else has supplied a valid answer, therefore, for this and the above points I consider I deserve this Accepted Answer
thanks for your attention
John BG
Walter Roberson
on 9 Mar 2017
If this question was not homework, then it was an inappropriate Command that we do something, and I would have to remove it...
James Tursa
on 9 Mar 2017
The question was obviously homework from the very beginning as we all know ...
Categories
Find more on Title in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!