[Edu-sig] calculus and not-calculus using Python
kirby urner
kirby.urner at gmail.com
Tue Apr 20 02:49:41 CEST 2010
I've mostly been writing about a new kind of math class at the high school
level that distinguishes itself from the precalculus - calculus track.
This has partly to do with politics, as I think it's easier to develop something
new and set that alongside already existing options (traditional courses)
than it is to introduce reforms in already "programmed" offerings.
However, Python has some capabilities when it comes to calculus, in
scipy and Sage for example. Plus it's of course easy to take anything
one might do with a calculator in support of learning calculus concepts,
and do that same thing in Python instead.
This was somewhat my approach in writings I did on the catenary some
years ago (the catenary is a curve similar to a parabola but different).
http://www.4dsolutions.net/ocn/catenary.html
At this point though, it's maybe a moot point whether we try to embrace
more calculus with Python or not. The premise was doing something
more exciting with technology than scientific calculators, introducing
a real programming language, and yet having this considered a math
class as much as a computer class. This was against the backdrop
of the "math pipeline" being broken according to many criteria, i.e.
in need of some upgrades.
Some progress has been made in small niches, but in many respects
the current mood is to freeze features i.e. the response to rapid
change is to codify and pickle that which once was.
So I'm back to thinking only brand new courses will have a chance.
They have to be seen as new, and the expectation must be that
new material will be covered. Perhaps for this reason I find myself
venturing into Wolfram territory as he's always talking about his
"new kind of science". Those little cellular automata studies are
actually pretty easy to implement in Python (we've done it here
on edu-sig, with John Zelle's graphics.py, PIL and native Tkinter).
http://www.4dsolutions.net/presentations/holdenweb/mini_nks.py
I'm going to say more about these calculus exercises at some
point, not sure how soon. This relates to the thread about
generating tables.
That was pretty fruitful thread, glad so many jumped in. We need
to see that in some ways having computers put out to text files
is a way to get back to the good old days, when we could explore
reams of data.
What's better nowadays is we don't really need all that paper (lets
not waste it). We have hard drives and LCDs instead.
Kirby
PS: found this old exhange with Matthias of DrScheme fame. He just
got some prestigious award, per an announcement on math-thinking-l.
=============
from scipy.integrate import quad, dblquad, Inf
from numpy import arange
from math import exp, log, pi, sin, cos
def test0():
"""
Integration example
http://www.scipy.org/doc/api_docs/SciPy.integrate.quadpack.html
"""
def thefunc(x):
return cos(x)
for a in arange(0, 2*pi, 0.1):
output = quad(thefunc, 0, a)[0]
fmtstring = "Integral of cos(x) from 1 to {0} = {1}: sin({0}) = {2}"
print fmtstring.format(a, output, sin(a))
def test1():
"""
Integration example
http://www.scipy.org/doc/api_docs/SciPy.integrate.quadpack.html
"""
def thefunc(x):
return 1./x
for a in range(1,21,2):
output = quad(thefunc, 1, a)[0]
fmtstring = "Integral of 1/x from 1 to {0} = {1}: ln({0}) = {2}"
print fmtstring.format(a, output, log(a))
def test2():
"""
Double integration example
http://www.scipy.org/doc/api_docs/SciPy.integrate.quadpack.html
"""
def I(n):
return dblquad(lambda t, x: exp(-x*t)/t**n,
0, Inf,
lambda x: 1, lambda x: Inf)
print I(4)
print I(3)
print I(2)
def test3():
"""
Double integration example
same as above but without using lambda
http://www.scipy.org/doc/api_docs/SciPy.integrate.quadpack.html
"""
def mkfunc(n):
def thefunc(t, x):
return exp(-x*t)/t**n
return thefunc
def xfrom(x):
return 1
def xto(x):
return Inf
def I(n):
thefunc = mkfunc(n)
return dblquad(thefunc, 0, Inf, xfrom, xto)
print I(4)
print I(3)
print I(2)
def doall():
test0()
#test1()
#test2()
#test3()
if __name__ == '__main__':
doall()
More information about the Edu-sig
mailing list