Aqua Phoenix
     >>  Lectures >>  Matlab 4  
 

Navigator
   
 
       
   

4.5 Assignment Solutions - Lecture 4

4.5.1 Part A

  hw4partA.m  

4.5.2 Part B

  hw4partB.m  

4.5.3 Part C

  area_ellipse.m  

function A=area_ellipse(a, b)
% area_ellipse computes the area of an ellipse.
% Arguments a and b correspond to half the
% short and long axes.
% If only one argument is passed, then a and b
% are assumed to be equal to that argument,
% and effectively the area of a circle is
% computed.

error(nargchk(1, 2, nargin))

if (nargin == 1)
  b=a;
end

if ((a < 0) || (b < 0))
  A=0;
else
  A=pi*a*b;
end

Figure 4.19
Click image to enlarge, or click here to open
We test the function with a few function calls:

area_ellipse(3,4)

area_ellipse(5)

area_ellipse(-4,3)

area_ellipse()

Figure 4.20
Click image to enlarge, or click here to open

4.5.4 Part D

  numberUnits.m