4 ms·
I think it would be much more valuable to learn how the algorithms inside the graphing calculator work, instead of learning how to use a calculator. Integration
by jules 17y ago
I think it would be much more valuable to learn how the algorithms inside the graphing calculator work, instead of learning how to use a calculator. Integration, differential equation solving and root finding can be programmed in just a couple lines of code. It is amazing how well these numerical methods work.
E.g. solving the differential equation y' = y from t=0,y=1 to t=1 computes exp(1):
import math
def simple(f,t,t1,y=0.0,dt=0.001):
while t<t1:
y += f(t,y)*dt
t += dt
return y
def rk4(f,t,t1,y=0.0,dt=0.001):
while t<t1:
k1 = f(t,y)
k2 = f(t+dt/2, y+dt*k1/2)
k3 = f(t+dt/2, y+dt*k2/2)
k4 = f(t+dt, y+dt*k3)
y += (k1+2*k2+2*k3+k4)*dt/6
t += dt
return y
def f(t,y): return y
print "Simple:", simple(f, 0.0, 1.0, 1.0)
print " RK4:", rk4(f, 0.0, 1.0, 1.0)
print "math.e:", math.e
This prints:
Simple: 2.71692393224
RK4: 2.71828182846
math.e: 2.71828182846
Or perhaps Newton's method to solve x^2 = 2, solution x=sqrt(2):
def newton(f, fprime, x=0.1, n=10):
for i in xrange(0,n):
x -= f(x)/fprime(x)
return x
def g(x): return x**2 - 2
def gprime(x): return 2*x # derivative of g
print newton(g, gprime)
print math.sqrt(2)
Result:
1.41421356237
1.41421356237
Note that 10 iterations are enough to get all the digits that Python prints correct.
In just 13 lines of code we have tools for effectively solving any ordinary differential y' = f(t,y) equation and for solving f(x) = 0 for many functions f. Solving y' = f(t,y) where f(t,y) is a function of t alone gives us integration. E.g. integrating 1/t from t=1 to t=2:
rk4(lambda t,y: 1/t, 1.0, 2.0)
(but there are better methods for integration than general purpose differential equation solvers)
- alextp 17y agoI agree. Numeric methods have taught me far more than learning simple programmable analytic tricks. Specially solving reccurrences and summations, which mathematica can do very well, and I will almost always make a silly mistake when trying to do it by hand.
- arghnoname 17y agoAnalytic tricks can help reduce a problem that is either numerically unstable or simply too big to estimate quickly into something that can be estimated in a stable or way or at all.
- jules 17y agoI agree that numerical methods are not a substitute for analytic tricks, you need analytic tricks to come up with the algorithms and to understand why they work! But learning how to use a particular calculator is not important (that is what I'd like to see replaced by learning the algorithms). And even for analytic tricks it's often much more enlightening to code the algorithm. For example I learned much more by coding an algorithm for factoring an arbitrary polynomial over Q than doing any number of factorizations by hand. I don't think that many people are even aware that there is an algorithm for factoring an arbitrary polynomial. They either don't even consider it a potential algorithmic problem or they think that it might be impossible to write an algorithm to solve it.