Too many input arguments?

3 Ansichten (letzte 30 Tage)
David
David am 25 Mär. 2013
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 Kommentar
Carlos
Carlos am 25 Mär. 2013
I have called the function in this way
>> ObamaBarackSphereF(2,20)
Giving this result
ans =
0.2327

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Image Analyst
Image Analyst am 25 Mär. 2013
Bearbeitet: Image Analyst am 25 Mär. 2013
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 Kommentare
Image Analyst
Image Analyst am 25 Mär. 2013
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 am 25 Mär. 2013
Bearbeitet: Image Analyst am 25 Mär. 2013
Why not use those values?

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by