How to create a function that calculates and returns the volume and cross-sectional area of a cylinder based on the radius and height?
45 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Emre Tunc
il 5 Ott 2016
Commentato: Emre Tunc
il 5 Ott 2016
Hello to matlabs user Please help me I am stuck on a problem :( Does anyone have code for a function that calculates and returns the volume and cross-sectional area of a cylinder based on the radius and height? I also need code for a function that radius and height can not be negative. Does anyone have this or have an idea how to do this? Thanks so much.
0 Commenti
Risposta accettata
Massimo Zanetti
il 5 Ott 2016
Here it is
function A=sect_area_cylinder(R,H,alpha)
%Cylinder of radius R and height H,
%its base-circle center coincide with the point (0,0,0).
%The intersecting plane is supposed to rotate around the
%line (x=0,y=H/2) with angle ALPHA (in degrees)
if (R<=0)||(H<=0)
error('Input positive R,H');
end
if alpha==0
%the cross-section is a circle
A=R^2*pi;
elseif alpha==90
%the cross section is a rectangle
A=2*R*H;
elseif (0<alpha)&&(alpha<90)
%the cross section is an ellipse
%of short radius R and long radius R/cos(alpha)
A=pi*R*R*cos(alpha*pi/180);
else
disp('alpha in [0,90]');
end
2 Commenti
Massimo Zanetti
il 5 Ott 2016
Cross section is a circle only if alpha=0 (the intersecting plane is horizontal). Alpha is used for calculation on in the case it is greater than 0 and less than 90 because the radii of the ellipse depend on it.
If this answer helped you, please accept it.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Surface and Mesh Plots in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!