
x = 1:10;
x = rand(10,1)    %  create random numbers 
x = 100*x .^6     %  take sixth power of those
n = length(x)
avg = mymean(x,n);      %     call my own function
med = mymedian(x,n);

avg
med



[a v] = arvo('sphere',1)
p=55
[a v] = arvo('ellipsoid',1,2,6)

fprintf('p is now --> %f \n',p);

function a = mymean(v,n)
% MYMEAN Example of a local function.

    a = 0;
    if n == 0; return; end
    for i = 1:n;
        a=a+v(i);
    end
    a=a/n;
end

function m = mymedian(v,n)
% MYMEDIAN Another example of a local function.

    w = sort(v);
    if rem(n,2) == 1
        m = w((n + 1)/2);
    else
        m = (w(n/2) + w(n/2 + 1))/2;
    end
end

function [area vol] = arvo(what,a,b,c)
    switch what
        case 'cube'   %.... note b not used
            area = 6*( a.^2 );  %.... note .^ operator so it can do vectors
            vol = a .^ 3;
        case 'sphere'
            area = 4*pi*a.^2;
            vol = (4/3)*pi*a.^3;
        case 'ellipsoid'
            vol=(4/3)*pi* (a .* b .* c);
            p=1.6075;       %  the exact area involves elliptical integrals.
            ap = a .^ p;
            bp = b .^ p;
            cp = c .^ p;
            area=4*pi*( ( ap + bp +cp )/ 3 ) .^ (1/p);  %.... Knud Thomsen's formula
        otherwise
            area=-1;
            vol=-1;
    end      
end

