Inline Functions
We can also use the inline command to perform the circle calculations.
This can be done directly at the command prompt (or in our current file).
We type
circumference = inline('2*pi*r')
circumference = Inline function: circumference(r) = 2*pi*r
and
area = inline('pi*r.^2')
area = Inline function: area(r) = pi*r.^2
Inline functions are evaluated using the feval command.
To get the circumference of a circle with radius 5 we use
feval(circumference,5)
ans = 31.4159
To get both values we use, e.g.,
circledata = [feval(circumference,5); feval(area,5)]
circledata = 31.4159 78.5398
Vectorized usage:
circledata = [feval(circumference,[2 4 6]); feval(area,[2 4 6])]
circledata = 12.5664 25.1327 37.6991 12.5664 50.2655 113.0973