SUNY Geneseo Department of Mathematics
Monday, March 7
Math 230 02
Spring 2016
Prof. Doug Baldwin
stickPerson
function?if ( logical_expression )
statements1 % done if expression is true
else
statements2 % done if expression is false
end
elseif
for nesting inside ifage
first:>> if ( age < 25 )
price = 4800;
else
price = 2200;
end
Undefined function or variable 'age'.
age
is defined, you can type branches into the command window,
Matlab will wait until the whole thing is entered and then execute it>> age = 30;
>> if ( age < 25 )
price = 4800;
else
price = 2200;
end
>> price
price =
2200
function [price] = insure( age )
if ( age < 25 )
price = 4800;
else
price = 2200;
end
end
>> insure( 17 )
ans =
4800
>> insure( 30 )
ans =
2200
function [y] = absvalue( x )
if ( x < 0 )
y = -x;
else
y = x;
end
end
>> absvalue( -7 )
ans =
7
>> absvalue( 3.7 )
ans =
3.7000