How to get the answer?

조회 수: 3 (최근 30일)
Abo Mohammed
Abo Mohammed 2018년 3월 28일
편집: Walter Roberson 2018년 3월 28일
Create a function to calculate the area of three circles with different radius in your choice. use for loop to call the function and display the results as a column vector.
  댓글 수: 5
Birdman
Birdman 2018년 3월 28일
Share what you have done so far.
Abo Mohammed
Abo Mohammed 2018년 3월 28일
편집: Walter Roberson 2018년 3월 28일
I created below function but still cannot understand how to disply the results as a column vector.
function Ca=Circle_area(r)
Ca=pi*r^2;
end

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

답변 (1개)

ES
ES 2018년 3월 28일
I have just reused your function.
function homework()
arrRadius = [5,3.5,6];%Random radii
arrArea = zeros(size(arrRadius, 2),1);%preallocate a array (column vector)
for iLoop=1:length(arrRadius)
arrArea(iLoop,1) = Circle_area(arrRadius(iLoop));
end
disp(arrArea);
end
function Ca=Circle_area(r)
Ca=pi*r^2;
end
  댓글 수: 1
Guillaume
Guillaume 2018년 3월 28일
arrRadius = [5,3.5,6];%Random radii
sic!

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by