How to get the answer?

2 visualizaciones (últimos 30 días)
Abo Mohammed
Abo Mohammed el 28 de Mzo. de 2018
Editada: Walter Roberson el 28 de Mzo. de 2018
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 comentarios
Birdman
Birdman el 28 de Mzo. de 2018
Share what you have done so far.
Abo Mohammed
Abo Mohammed el 28 de Mzo. de 2018
Editada: Walter Roberson el 28 de Mzo. de 2018
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

Iniciar sesión para comentar.

Respuestas (1)

ES
ES el 28 de Mzo. de 2018
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

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by