#!/usr/local/bin/bc -l ### IntDiff.BC - numeric differentiation and integration of ### a single variable function define f(x) { return x^2 } # example - redefine in later code/bc session # Numerically differentiate the global function f(x) define dfxdx(x) { auto eps; eps = A^-scale scale *= 2 x = (f(x+eps)-f(x-eps))/(2*eps) scale /= 2 return x/1 } # New global variable like 'scale' - determines accuracy of numerical # integration at the expense of time. Don't set above 15 unless this # is running on a really fast machine! depth = 10 # Numerically integrate the global function f(x) between x = a and x = b # . uses the trapezoidal rule define ifxdx_old(a,b) { auto os,h,s,t,i if(a==b)return f(a) os = scale;if(scale