SUNY Geneseo Department of Mathematics
Monday, April 3
Math 230 02
Spring 2017
Prof. Doug Baldwin
“Structure and Symmetry: An Introduction to Lie Algebras and Representation Theory”
By Chad Magnum, Niagara University
Friday, April 7, 2:30 PM, Newton 203
Extra credit as usual for writing a paragraph or so about connections you make to the talk
I’ll be out of town Friday (April 7)
Class will be led by Prof. Farian
Most likely a lab day for the numeric integration lab
Example 1. Write a loop that prints “I will not misuse loops” 100 times
Relevant ideas or questions from the reading
for
loops are good for doing a fixed number of iterationsSolution
%% Print "I will not misuse loops" 100 times.
for count = 1 : 100
fprintf( 'I will not misuse loops\n' )
end
Comments
for
loop:
the keyword for
, a variable that will step through a sequence of values, statements
to execute for each one of those values, and the keyword end
.Example 2. Given a natural number n, write a loop that calculates the sum of the first n odd numbers (e.g., if n = 1, the result is 1; if n = 2 the result is 1 + 3; if n = 3 the result is 1 + 3 + 5; etc.)
What is the kth odd number?
Solutions
function total = oddSum( n )
%ODDSUM Find the sum of the first n odd numbers.
% e.g., if n = 2, result = 1 + 3
% e.g., if n = 3, result = 1 + 3 + 5
%
% Progamming idiom for keeping an accumulating result:
% total = initial value
% loop
% update total
% end
total = 0;
for i = 1 : 2 : 2*n - 1
total = total + i;
end
end
function total = oddSum( n )
%ODDSUM Find the sum of the first n odd numbers.
% e.g., if n = 2, result = 1 + 3
% e.g., if n = 3, result = 1 + 3 + 5
%
% Progamming idiom for keeping an accumulating result:
% total = initial value
% loop
% update total
% end
total = 0;
for i = 1 : n
total = total + (2*i - 1);
end
end
Comments
Example 3. write a loop that calculates the sum of the numbers in a vector v.
Solution
function y = vecSum( v )
%VECSUM Find the sum of the numbers in vector v
y = 0;
for i = v
y = y + i;
end
end
Comments
for
loop steps through a vector, and how that fact might be used.Lab day to start the numeric integration lab.