SUNY Geneseo Department of Mathematics
Math 230 02
Spring 2015
Prof. Doug Baldwin
The following are sketches of how I would answer each of the questions in hour exam 2. Most of these are Matlab code fragments I wrote to test my solutions, with relatively little discussion. But please feel free to ask questions if you want!
%% Question 1, triangle classification.
a = input( 'Length of first side: ' );
b = input( 'Length of second side: ' );
c = input( 'Length of third side: ' );
if a == b && b == c
fprintf( 'Equilateral\n' );
elseif a == b || b == c || a == c
fprintf( 'Isosceles\n' );
else
fprintf( 'Neither\n' );
end
%% Question 2A, loop-based series
function [ s ] = math230SeriesLoop( k )
s = 0;
for n = 1 : k
s = s + sin( n * pi / 2 ) / n^2;
end
end
%% Question 2B, vectorized series
function [ s ] = mathe230SeriesVectorize( k )
ns = 1 : k;
s = sum( sin( ns * pi ./ 2 ) ./ ns .^ 2 );
end
%% Question 3, trapezoid rule
The trapezoid rule does respect that property that the
integral from a to b of f(x) is the negative of the integral
from b to a of f(x), because exchanging the bounds negates
the deltaX variable in the algorithm, consequently negating
all the areas that are calculated but not changing anything
else.
%% Question 4, logical complement of "x < 23 && y == -3"
x >= 23 || y ~= -3;