Too many input arguments?

3 ビュー (過去 30 日間)
David
David 2013 年 3 月 25 日
Hello. I'm trying to create a MATLAB function file which will determine the surface area and volume of partial sphere. The user will enter the sphere diameter and the angular portion of the sphere in degrees.
Here is my function so far.
function [Volume,SurfaceArea] = ObamaBarackSphereF(Diameter,Angle)
% This is a function that will determine the surface area and volume of a
% partial sphere. The input arguments are the sphere's diameter and the
% angular portion of the sphere in degress.
Radius = Diameter/2;
Proportion = Angle/360;
if Diameter > 0;
if Angle == 360;
Volume = (4/3)*pi*(Radius)^3;
SurfaceArea = 4*pi*Radius^2;
elseif Angle > 0 && Angle < 360;
Volume = Proportion*(4/3)*pi*Radius^3;
SurfaceArea = (Proportion*4*pi*Radius^2)+(pi*Radius^2);
end
end
end
However, when I try to run it, the command window says:
Error using ObamaBarackSphereF (line 6) Not enough input arguments.
Line 6 refers to the line that says "Radius = Diameter/2;"
What am I doing wrong here?
  1 件のコメント
Carlos
Carlos 2013 年 3 月 25 日
I have called the function in this way
>> ObamaBarackSphereF(2,20)
Giving this result
ans =
0.2327

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

回答 (1 件)

Image Analyst
Image Analyst 2013 年 3 月 25 日
編集済み: Image Analyst 2013 年 3 月 25 日
It runs just fine for me, I mean other than the formula being totally wrong. It doesn't say anything about not enough inputs. You do know that using angles between 0 and 360 for a sphere doesn't make sense don't you? I guess apparently not. You need to pass in "Solid angle" which goes from 0 to 4*pi steradians.
Proportion = SolidAngle/(4*pi);
Also I don't see any involvement of Barack Obama in your program so you might pick a more descriptive name for your function.
  5 件のコメント
Image Analyst
Image Analyst 2013 年 3 月 25 日
Ask your professor what a steradian is and see if he knows. Ask him why he is not using steradians, and what degrees means in a 3D situation. If he means the angle of the solid cone, like theta in this page http://en.wikipedia.org/wiki/Steradians then you'll need to convert that cone angle into steradians.
Jan
Jan 2013 年 3 月 25 日
編集済み: Image Analyst 2013 年 3 月 25 日
Why not use those values?

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

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by