Skip to content

Commit e26d4e5

Browse files
committed
Merge pull request #100 from ryanmorin/master
work review trapz.py
2 parents e9aae72 + 93c3244 commit e26d4e5

3 files changed

Lines changed: 97 additions & 0 deletions

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
__author__ = 'ryan.morin'
2+
3+
import math
4+
5+
def sine(x):
6+
return math.sin(x)
7+
8+
def line(x):
9+
return 5
10+
11+
def quadratic(x, c=0, d=0, e=0):
12+
return c * x**2 + d*x + e
13+
14+
def trapz(fun, a, b, *args, **kwargs):
15+
"""
16+
Compute the area under the curve from 'a' to 'b' for a function y = f(x)
17+
:param fun: the function used for the calculation
18+
:param a: the beginning point of the integration
19+
:param b: the ending point of the integration
20+
:return: the area of the function fun
21+
"""
22+
total = 0.0
23+
inc = float((b-a))/100
24+
total += fun(a)/2.0
25+
for i in range(1,100):
26+
total += fun(a + (i * inc))
27+
total += (fun(b)/2.0)
28+
return total * inc
29+
30+
print (trapz(lambda x: math.sin(x), 1,10))
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
y = 4
2+
def fun(x=y):
3+
print ("x is:", x)
4+
5+
fun()
6+
7+
def f(*args, **kwargs):
8+
print("the positional arguments are:", args)
9+
print("the keyword arguments are:", kwargs)
10+
11+
f(3,4,57,6, o=6, r=5)
12+
13+
print ("My name is {first} {last}".format(last="Barker", first="Chris"))
14+
15+
d = {"last":"Barker", "first":"Chris"}
16+
print("My name is {first} {last}".format(**d))
17+
18+
def f(fore_color='w',back_color='x',link_color='y',visited_color='z'):
19+
print (('{},{} -- {},{}').format(fore_color,back_color,link_color,visited_color))
20+
21+
other = ('white', 'orange')
22+
other2 = {'link_color':'pink', 'visited_color':'jump'}
23+
print (other2['visited_color'])
24+
25+
f(other2['visited_color'], *other,visited_color='yellow')
26+
27+
def fun(x, a=None):
28+
if a is None:
29+
a = []
30+
a.append(x)
31+
print(a)
32+
33+
fun(4)
34+
fun(10)
35+
36+
l = [lambda x, y: x+y]
37+
print (l[0](2,3))
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
__author__ = 'ryan.morin'
2+
3+
import math
4+
5+
def sine(x):
6+
return math.sin(x)
7+
8+
def line(x):
9+
return 5
10+
11+
def quadratic(x, c=0, d=0, e=0):
12+
return c * x**2 + d*x + e
13+
14+
def trapz(fun, a, b, *args, **kwargs):
15+
"""
16+
Compute the area under the curve from 'a' to 'b' for a function y = f(x)
17+
:param fun: the function used for the calculation
18+
:param a: the beginning point of the integration
19+
:param b: the ending point of the integration
20+
:return: the area of the function fun
21+
"""
22+
total = 0.0
23+
inc = float((b-a))/100
24+
total += fun(a)/2.0
25+
for i in range(1,100):
26+
total += fun(a + (i * inc))
27+
total += (fun(b)/2.0)
28+
return total * inc
29+
30+
print (trapz(lambda x: math.sin(x), 1,10))

0 commit comments

Comments
 (0)