SUNY Geneseo Department of Mathematics
Friday, September 18
Math 230 01
Fall 2015
Prof. Doug Baldwin
function [ out1, out2, … ] = functionName( in1, in2, … )
% help comment(s)
… body …
end
=
in function definitionfunction [ volume ] = volumeCylinder( radius, height )
%VOLUMECYLINDER Compute volume of cylinder from radius and height
volume = pi * radius^2 * height;
end
volumeCylinder( 1, 2 )
ans =
6.2832
help volumeCylinder
volumeCylinder Compute volume of cylinder from radius and height
function [ n, d ] = add( a, b, c, d )
%ADD Add fractions a/b plus c/d
% Result is fraction n/d in reduced form
common = b * d;
scaledA = a * d;
scaledC = c * b;
numerator = scaledA + scaledC;
n = numerator / gcd(numerator,b*d);
d = b * d / gcd(numerator,b*d);
end
add( 1, 3, 22, 7 )
ans =
73
[n,d] = add( 1, 3, 22, 7 )
n =
73
d =
21