In [53]:
import sympy

import adaptive_trapzint as p1
import sinesum1 as p2
import centered_diff as p3
import find_primes as p4

Homework 1

Taylor Patti

2/8/2016

Exercises Completed:

  1. Exercise 3.8 (adaptive_trapzint.py)
  2. Exercise 3.15 (sinesum1.py)
  3. Exercise 3.18 (centered_diff.py)
  4. Exercise 3.20 (find_primes.py)

adaptive_trapzint.py

Uses algorithm to calculate the number of series terms required to obtain integral value within a given error, then computes this quantity. A select sampling of functions, intervals, and function performance is output below.


In [54]:
p1.performance_table()


Preformance Table of Various Functions

  Function        Interval           Error         N-value

   cos(x)       0.00 to 3.14      3.122502E-17       509

   sin(x)       0.00 to 3.14     -6.349115E-06       509

   sin(x)       0.00 to 1.57     -6.346204E-06       180

sinesum1.py

Constructs a trigonometric series with a known point of conversion and ultimately produces a table which details the effectiveness of truncating at various indexes for a sampling of arguments.


In [11]:
p2.table(1)


Difference Between the Limit and the Sum of Sines

         n     a=0.01     a=0.25     a=0.49

         1       0.99       0.68       0.40
         3       0.96       0.15      -0.18
         5       0.94      -0.14       0.00
        10       0.87       0.01      -0.06
        30       0.63      -0.03      -0.01
       100      -0.02       0.01      -0.01

centered_diff.py

Estimates the first derivative of a function by a truncated Taylor Series approximation. Ultimately, a table was produced in which the estimations were compared to the analytic derivatives, calculated using sympy, and the error was deduced.


In [20]:
p3.application()


            Function                Error

              exp(x)              1.67E-05

        exp(-2*x**2)              0.00E+00

              cos(x)             -2.45E-16

              log(x)              3.33E-05

Out[20]:
[1.6666749992122476e-05, 0.0, -2.4492935982947064e-16, 3.3335333477158e-05]

find_primes.py

This program identifies prime factors by iterating through a list from 2 to the number given as the function argument and eliminating numbers which are multiples of smaller numbers from the iteration list. The iteration list is then returned and consists of only prime numbers lesser or equal to the function argument. Here, the prime numbers of 100 and less are shown.


In [16]:
print p4.find_primes(100)


[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]