Programme for circle parameters calculation

조회 수: 7 (최근 30일)
Francis Adams Kwofie
Francis Adams Kwofie 2023년 3월 9일
댓글: Sarvesh Kale 2023년 3월 9일
Progamme that takes radius of a circle as a parameter ie. (function arguments) and computes diameter, circumference and area.

답변 (1개)

Sarvesh Kale
Sarvesh Kale 2023년 3월 9일
편집: Sarvesh Kale 2023년 3월 9일
please refer the following code
function [Area,circumference,diameter] = calculate(radius)
Area = pi*radius*radius;
circumference = 2*pi*radius ;
diameter = 2*radius ;
end
You need the define the function in a file and the name of the matlab file should be calculate.m, that is the same name as our function. then call the function as below
x = 5;
[A,c,d]=calculate(x);
fprintf("The Area of circle is %f\nCircumference is %f\nDiameter is %f",A,c,d);
I hope this helps your query
Thank you
  댓글 수: 2
Francis Adams Kwofie
Francis Adams Kwofie 2023년 3월 9일
Undefined function or variable 'r'.
Error in calculate (line 3)
circumference = 2*pi*r;
Sarvesh Kale
Sarvesh Kale 2023년 3월 9일
edited the code, try again

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by