Last active
December 18, 2015 22:38
-
-
Save TomDeBeauchamp/5855418 to your computer and use it in GitHub Desktop.
6.189 Homework 2.3 Math Module
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### The following are my attempts at homework 2.3 for MIT 6.189 | |
###http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-189-a-gentle-introduction-to-programming-using-python-january-iap-2011/assignments/MIT6_189IAP11_hw2.pdf | |
### Everything here works, and evaluates correctly, but I'd love some feedback. | |
### Particularly with understanding the intention behind the multadd method. | |
### In a few of my examples I use it essentially just to generate a sum (multiplying said sum by one). | |
### Is there a saavier way to use this, more in keeping with the spirit of the exercise? | |
## 1 - multadd function | |
##### YOUR CODE HERE ##### | |
import math | |
def multadd(a,b,c): | |
return a*b+c | |
##tests.... | |
print multadd(6,3,3), 6*3+3 | |
print multadd(1,0,9), 1*0+9 | |
print multadd(-1,0,-9), -1*0-9 | |
print multadd(-1,30,-9), -1*30-9 | |
## 2 - Equations | |
##### YOUR CODE HERE ##### | |
angle_test = multadd(1,math.sin(math.pi/4),math.cos(math.pi/4)/2) | |
print angle_test | |
ceiling_test = multadd(1,math.ceil(276/19.0),2*math.log(12,7)) | |
print ceiling_test | |
## 3 - yikes function | |
##### YOUR CODE HERE ##### | |
def yikes(x): | |
return multadd(x,math.exp(-x),math.sqrt((1-math.exp(-x)))) | |
# Test Cases | |
x = 5 | |
print "yikes(5) =", yikes(x) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment