SUNY Geneseo Department of Mathematics
Friday, February 20
Math 384
Spring 2015
Prof. Doug Baldwin
square
function…function [ y ] = square( x )
y = x^2;
end
>> square( 3 )
ans =
9
>> f = @square
f =
@square
>> f(3)
ans =
9
function [ y ] = apply( f, x )
y = f(x);
end
>> apply( @square, 4 )
ans =
16
>> apply( @sin, pi )
ans =
1.2246e-16
>> c1 = struct( 'calculate', @square );
>> c2 = struct( 'calculate', @sin );
>> c1.calculate( 3 )
ans =
9
>> c2.calculate( 3 )
ans =
0.1411