SUNY Geneseo Department of Mathematics
Friday, April 3
Math 230 02
Spring 2015
Prof. Doug Baldwin
syms
function [ f ] = makeAdder( x )
%MAKEADDER Create function that adds x to things
f = @(y) x + y;
end
>> a1 = makeAdder( 5 )
a1 =
@(y)x+y
>> a1( 2 )
ans =
7
>> a1(10)
ans =
15
>> a2 = makeAdder( 10 )
a2 =
@(y)x+y
>> a2( 1 )
ans =
11
>> a2(17)
ans =
27
>> a1( 1 )
ans =
6