How do you write a function for the area of a circle?

42 ビュー (過去 30 日間)
John locke
John locke 2014 年 3 月 4 日
コメント済み: Walter Roberson 2021 年 7 月 10 日
This function computes the area of a circle based on the parameter r. write a script. This script asks the user to type r1 for circle 1, and r2 for circle 2. Then display areas of circle 1 and circle 2. And display which area is bigger, or they are equal. The script should call function CircleArea ().
  2 件のコメント
Akash Hongal
Akash Hongal 2021 年 7 月 10 日
The area of circle x2+y2=4 by using MATLAB script is given by
Walter Roberson
Walter Roberson 2021 年 7 月 10 日
The formula is missing from your comment, and without the formula, your comment does not appear to be guidenace to solve the question that was asked in 2014.

サインインしてコメントする。

採用された回答

Chandrasekhar
Chandrasekhar 2014 年 3 月 4 日
Function:
function [area] = CircleArea(radius)
area = pi * radius^2;
script:
rad1 = input('Enter Radius of Circle 1');
area1 = CircleArea(rad1);
disp(['Area of Circle1 = ' num2str(area1)])
rad2 = input('Enter Radius of Circle 2');
area2 = CircleArea(rad2);
disp(['Area of Circle2 = ' num2str(area2)])
if(area1 > area2)
disp('Area of Circle1 is greater than area of Circle2');
elseif (area1 < area2)
disp('Area of Circle1 is less than area of Circle2');
else
disp('Area of Circle1 is equal to area of Circle2');
end

その他の回答 (2 件)

Fahmida Rahman
Fahmida Rahman 2019 年 8 月 28 日
rad1 = input('Enter Radius of Circle 1');
area1 = CircleArea(rad1);
disp(['Area of Circle1 = ' num2str(area1)])
rad2 = input('Enter Radius of Circle 2');
area2 = CircleArea(rad2);
disp(['Area of Circle2 = ' num2str(area2)])
if(area1 > area2)
disp('Area of Circle1 is greater than area of Circle2');
elseif (area1 < area2)
disp('Area of Circle1 is less than area of Circle2');
else
disp('Area of Circle1 is equal to area of Circle2');
end

ghani abro
ghani abro 2020 年 7 月 29 日
rad1 = input('Enter Radius of Circle 1'); area1 = CircleArea(rad1); disp(['Area of Circle1 = ' num2str(area1)]) rad2 = input('Enter Radius of Circle 2'); area2 = CircleArea(rad2); disp(['Area of Circle2 = ' num2str(area2)]) if(area1 > area2) disp('Area of Circle1 is greater than area of Circle2'); elseif (area1 < area2) disp('Area of Circle1 is less than area of Circle2'); else disp('Area of Circle1 is equal to area of Circle2'); end

カテゴリ

Help Center および File ExchangeComputational Geometry についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by