How do I create a function finding Surface Area, Volume, and Density of a cone?

65 ビュー (過去 30 日間)
Russell Van Hoesen
Russell Van Hoesen 2021 年 2 月 10 日
回答済み: Christopher Stapels 2022 年 5 月 19 日
I've already created a function, and it reads as follows and gives me wildly incorrect answers. Is there something I'm missing?
function [SA,V,D] = coneProperties(r,m,h)
SA = pi*r*(r+sqrt(h.^2 + r.^2));
V = pi*r^2*(h/3);
D = m./V;
The surface area answer should be about 254, but it gave me 1.337628854861238e+03, which is very much not the right answer. I'm not sure what I've done wrong, so any help is appreciated!
  2 件のコメント
the cyclist
the cyclist 2021 年 2 月 10 日
Your formulas look correct to me.
What input values of r, m, and h did you use, to get those expected values?
Are you sure you entered the inputs in the correct order?
Russell Van Hoesen
Russell Van Hoesen 2021 年 2 月 10 日
You are totally right. I put them in the wrong order. Thank you! Also the variables were as follows
r = 5,
m = 80,
h = 10,

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

回答 (1 件)

Christopher Stapels
Christopher Stapels 2022 年 5 月 19 日
Looks like the OP had it right, but Im adding the formula back here for completeness.
function [SA,V,D] = coneProperties(r,m,h)
SA = pi*r*(r+sqrt(h.^2 + r.^2));
V = pi*r^2*(h/3);
D = m./V;
% Radius r, mass m, height h.
% Surface Area SA, Volume V, Density D.

カテゴリ

Help Center および File ExchangeIntroduction to Installation and Licensing についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by