Math 480 - Homework 4
Due Tuesday after spring break.
As usual, write in your diary as you do the following exercises.
TeX submission required. You can start with my solution to
homework 3 and edit it.
Pay
particular attention to the way I used \lstinline
and
\lstinputlisting
to display Python, and
verbatim
environments to display output.
Use what you learn when writing up your answers for this homework.
- Use what you've learned in this course (Python or TeX - both
if possible) to work on a mathematics question that interests you. You
can make one up, or use something that came up in another course
you're taking now.
Your diary/discussion should talk about how you've used something
new to you. If you knew TeX before this then just writing
something in TeX doesn't count.
- None of the integration functions we've studied (vanilla,
trapezoid, montecarlo) has been tested when the function takes on some
negative values or when the lower limit of integration is greater than
the upper limit. Those are all legitimate mathematically.
Some of those functions may work properly as is. Test to find
out. Then fix the ones that need fixing.
- Write and thoroughly test a Python function that returns a
tuple of all the prime factors of a positive integer n. For example,
when passed 24 it should return (2,2,2,3). (The order doesn't matter,
but the repetitions do.)
If you can't quite
figure out how to return a tuple, return a list.
Hint: just call one of our find smallest factor
functions in a loop.
- Write and thoroughly test a Python program that returns a
tuple of all the factors of a positive integer n. For example, when
passed 24 it should return (1,2,3,6,8,12,24). If you can't quite
figure out how to return a tuple, return a list.
One way not to do this is to loop on range(1,n+1) and test for
divisibility. That will work for small numbers, but is very
inefficient for big ones with very few factors. A better way is to use
a function from the itertools package to find all combinations of
prime factors.
- Maybe more ...