pax_global_header 0000666 0000000 0000000 00000000064 13751255212 0014515 g ustar 00root root 0000000 0000000 52 comment=4325b7e0f780b23df3d07700ac32add01473f0c0 pycode-browser-1.03/ 0000775 0000000 0000000 00000000000 13751255212 0014404 5 ustar 00root root 0000000 0000000 pycode-browser-1.03/Code/ 0000775 0000000 0000000 00000000000 13751255212 0015256 5 ustar 00root root 0000000 0000000 pycode-browser-1.03/Code/Maths/ 0000775 0000000 0000000 00000000000 13751255212 0016332 5 ustar 00root root 0000000 0000000 pycode-browser-1.03/Code/Maths/Arrays/ 0000775 0000000 0000000 00000000000 13751255212 0017573 5 ustar 00root root 0000000 0000000 pycode-browser-1.03/Code/Maths/Arrays/cross.py 0000775 0000000 0000000 00000000143 13751255212 0021277 0 ustar 00root root 0000000 0000000 #Numpy : Cross from numpy import * a = array([1,2,3]) b = array([4,5,6]) c = cross(a,b) print (c) pycode-browser-1.03/Code/Maths/Arrays/fileio.py 0000775 0000000 0000000 00000000162 13751255212 0021416 0 ustar 00root root 0000000 0000000 #File R/W example from numpy import * a = arange(10) a.tofile('myfile.dat') b = fromfile('myfile.dat') print (b) pycode-browser-1.03/Code/Maths/Arrays/inv.py 0000775 0000000 0000000 00000000254 13751255212 0020745 0 ustar 00root root 0000000 0000000 #Calculating the inverse of a matrix from numpy import * a = array([ [4,1,-2], [2,-3,3], [-6,-2,1] ], dtype='float') ainv = linalg.inv(a) print (ainv) print (dot(a,ainv)) pycode-browser-1.03/Code/Maths/Arrays/numpy1.py 0000775 0000000 0000000 00000000201 13751255212 0021372 0 ustar 00root root 0000000 0000000 #Numpy : basic array with just two elements from numpy import * x = array( [1,2] ) # Make array from list print (x , type(x)) pycode-browser-1.03/Code/Maths/Arrays/numpy2.py 0000775 0000000 0000000 00000000357 13751255212 0021407 0 ustar 00root root 0000000 0000000 #Numpy: range, linspace, ones, zeros, random from numpy import * a = arange(1.0, 2.0, 0.1) # start, stop & step print (a) b = linspace(1,2,11) print (b) c = ones(5) print (c) d = zeros(5) print (d) e = random.rand(5) print (e) pycode-browser-1.03/Code/Maths/Arrays/numpy3.py 0000775 0000000 0000000 00000000207 13751255212 0021402 0 ustar 00root root 0000000 0000000 #Numpy: matrices from numpy import * a = [ [1,2] , [3,4] ] # make a list of lists x = array(a) # and convert to an array print (a) pycode-browser-1.03/Code/Maths/Arrays/numpy4.py 0000775 0000000 0000000 00000000164 13751255212 0021405 0 ustar 00root root 0000000 0000000 #Numpy: Reshaping from numpy import * a = arange(10) print (a) a = a.reshape(5,2) # 5 rows and 2 columns print (a) pycode-browser-1.03/Code/Maths/Arrays/numpy5.py 0000775 0000000 0000000 00000000274 13751255212 0021410 0 ustar 00root root 0000000 0000000 #Numpy: array manipulations, scalar multiplication etc from numpy import * a = array([ [1.0, 2.0] , [3.0, 4.0] ]) # make a numpy array print (a) print (a * 5) print (a * a) print (a / a) pycode-browser-1.03/Code/Maths/Arrays/oper.py 0000775 0000000 0000000 00000000207 13751255212 0021114 0 ustar 00root root 0000000 0000000 #Numpy: Ading, multiplying arrays from numpy import * a = array([[2,3], [4,5]]) b = array([[1,2], [3,0]]) print (a + b) print (a * b) pycode-browser-1.03/Code/Maths/Arrays/reshape.py 0000775 0000000 0000000 00000000135 13751255212 0021576 0 ustar 00root root 0000000 0000000 #Numpy: Reshaping arrays from numpy import * a = arange(20) b = reshape(a, [4,5]) print (b) pycode-browser-1.03/Code/Maths/Calculus/ 0000775 0000000 0000000 00000000000 13751255212 0020105 5 ustar 00root root 0000000 0000000 pycode-browser-1.03/Code/Maths/Calculus/compareEuRK4.py 0000775 0000000 0000000 00000001312 13751255212 0022720 0 ustar 00root root 0000000 0000000 #Euler and Runge-Kutta methods are used to calculate sine from its derivative, cosine. ''' Sine function is calculated using its derivative, cosine. Using Euler and RK4 method, with ''' import math def rk4(x, y, yprime, dx = 0.01): # x, y , derivative, stepsize k1 = dx * yprime(x) k2 = dx * yprime(x + dx/2.0) k3 = dx * yprime(x + dx/2.0) k4 = dx * yprime(x + dx) return y + ( k1/6 + k2/3 + k3/3 + k4/6 ) h = 0.01 # stepsize x = 0.0 # initail values y = 0.0 # for Euler z = 0.0 # for RK4 while x < math.pi: print( x, y - math.sin(x), z - math.sin(x) ) # errors y = y + h * math.cos(x) # Euler method z = rk4(x,z,math.cos,h) # Runge-Kutta method x = x + h pycode-browser-1.03/Code/Maths/Calculus/diff.py 0000775 0000000 0000000 00000000313 13751255212 0021367 0 ustar 00root root 0000000 0000000 #Calculating derivates def f(x): return x**3 def deriv(x,dx=0.005): df = f(x+dx/2)-f(x-dx/2) return df/dx print( deriv(2.0)) print( deriv(2.0, 0.1)) print( deriv(2.0, 0.0001)) pycode-browser-1.03/Code/Maths/Calculus/diff1.py 0000775 0000000 0000000 00000001010 13751255212 0021443 0 ustar 00root root 0000000 0000000 #Calculating and plotting derivatives from pylab import * dx = 0.1 # value of x increment x = arange(0,10, dx) y = sin(x) yprime = [] # empty list for k in range(99): # from 100 points we get 99 diference values dy = y[k+1]-y[k] yprime.append(dy/dx) x1 = x[:-1] # A new array without the last element x1 = x1 + dx/2 # The derivative corresponds to the middle point plot(x1, yprime, '+') plot(x1, cos(x1)) # Cross check with the analitic value show() pycode-browser-1.03/Code/Maths/Calculus/euler.py 0000775 0000000 0000000 00000000320 13751255212 0021571 0 ustar 00root root 0000000 0000000 #Euler integration import math h = 0.01 # stepsize x = 0.0 # initail values y = 0.0 while x < math.pi: print( x, y, math.sin(x) ) y = y + h * math.cos(x) # Euler method x = x + h pycode-browser-1.03/Code/Maths/Calculus/fit1.py 0000775 0000000 0000000 00000001033 13751255212 0021322 0 ustar 00root root 0000000 0000000 #Least square method for Curve Fitting; plotting results. from pylab import * from scipy import * from scipy.optimize import leastsq def err_func(p,y,x): A,k,theta = p return y - A*sin(2*pi*k*x+theta) def evaluate(x,p): return p[0] * sin(2*pi*p[1]*x+p[2]) ax = arange(0, 0.2, 0.001) A,k,theta = 5, 50.0, pi/3 y_true = A*sin(2*pi*k*ax+theta) y_meas = y_true + 0.2*randn(len(ax)) p0 = [6, 50.0, pi/3] plsq = leastsq(err_func,p0,args=(y_meas,ax)) print( plsq) plot(ax,y_true) plot(ax,y_meas,'o') plot(ax,evaluate(ax,plsq[0])) show() pycode-browser-1.03/Code/Maths/Calculus/fit2.py 0000775 0000000 0000000 00000000741 13751255212 0021330 0 ustar 00root root 0000000 0000000 from pylab import * from scipy import * from scipy.optimize import leastsq def err_func(p,y,x): A,k,theta = p return y - A*sin(2*pi*k*x+theta) def evaluate(x,p): return p[0] * sin(2*pi*p[1]*x+p[2]) ax = arange(0, 0.2, 0.001) A,k,theta = 5, 50.0, pi/3 y_true = A*sin(2*pi*k*ax+theta) y_meas = y_true + 0.2*randn(len(ax)) p0 = [6, 50.0, pi/3] plsq = leastsq(err_func,p0,args=(y_meas,ax)) print( plsq) plot(ax,y_true) plot(ax,y_meas,'o') plot(ax,evaluate(ax,plsq[0])) show() pycode-browser-1.03/Code/Maths/Calculus/rk4.py 0000775 0000000 0000000 00000001145 13751255212 0021163 0 ustar 00root root 0000000 0000000 #Solving initial value problem using 4th order Runge-Kutta method. ''' Solving initial value problem using 4th order Runge-Kutta method. Sine function is calculated using its derivative, cosine. ''' import math def rk4(x, y, yprime, dx = 0.01): # x, y , derivative, stepsize k1 = dx * yprime(x) k2 = dx * yprime(x + dx/2.0) k3 = dx * yprime(x + dx/2.0) k4 = dx * yprime(x + dx) return y + ( k1/6 + k2/3 + k3/3 + k4/6 ) h = 0.01 # stepsize x = 0.0 # initail values y = 0.0 while x < math.pi: print( x, y, math.sin(x) ) y = rk4(x,y,math.cos) # Runge-Kutta method x = x + h pycode-browser-1.03/Code/Maths/Calculus/rk_sin.py 0000775 0000000 0000000 00000001131 13751255212 0021743 0 ustar 00root root 0000000 0000000 from pylab import * def func(t): return cos(t) def rk4(s,t): k1 = dt * func(t) k2 = dt * func(t + dt/2.0) k3 = dt * func(t + dt/2.0) k4 = dt * func(t + dt) return s + ( k1/6 + k2/3 + k3/3 + k4/6 ) t = 0.0 # Stating angle dt = 0.01 # value of angle increment val = 0.0 # value of the 'sine' function at t = 0 tm = [0.0] # List to store theta values res = [0.0] # RK4 results while t < 2*pi: val = rk4(val,t) # get the new value t = t + dt tm.append(t) res.append(val) plot(tm, res,'+') plot(tm, sin(tm)) # compare with actual curve show() pycode-browser-1.03/Code/Maths/Calculus/trapez.py 0000775 0000000 0000000 00000000455 13751255212 0021773 0 ustar 00root root 0000000 0000000 from math import * def sqr(a): return a**2 def trapez(f, a, b, n): h = (b-a) / n sum = f(a) for i in range (1,n): sum = sum + 2 * f(a + h * i) sum = sum + f(b) return 0.5 * h * sum print( trapez(sin,0.,pi,100)) print( trapez(sqr,0.,2.,100)) print( trapez(sqr,0,2,100)) # Why the error ? pycode-browser-1.03/Code/Maths/Calculus/vdiff.py 0000775 0000000 0000000 00000000407 13751255212 0021561 0 ustar 00root root 0000000 0000000 #Example vdiff.py from pylab import * def f(x): return sin(x) def deriv(x,dx=0.005): df = f(x+dx/2)-f(x-dx/2) return df/dx vecderiv = vectorize(deriv) x = linspace(-2*pi, 2*pi, 200) y = vecderiv(x) plot(x,y,'+') plot(x,cos(x)) show() pycode-browser-1.03/Code/Maths/FamousCurves/ 0000775 0000000 0000000 00000000000 13751255212 0020754 5 ustar 00root root 0000000 0000000 pycode-browser-1.03/Code/Maths/FamousCurves/archi.py 0000775 0000000 0000000 00000000173 13751255212 0022420 0 ustar 00root root 0000000 0000000 #Example archi.py from pylab import * a = 2 th= linspace(0, 10*pi,200) r = a*th polar(th,r) axis([0, 2*pi, 0, 70]) show() pycode-browser-1.03/Code/Maths/FamousCurves/archi.txt 0000775 0000000 0000000 00000001612 13751255212 0022606 0 ustar 00root root 0000000 0000000 This is the description of archi.py file. You can add description to any python file by adding a .txt file with the description. The file name should be the same as the python file.This is the description of archi.py file. You can add description to any python file by adding a .txt file with the description. The file name should be the same as the python file.This is the description of archi.py file. You can add description to any python file by adding a .txt file with the description. The file name should be the same as the python file.This is the description of archi.py file. You can add description to any python file by adding a .txt file with the description. The file name should be the same as the python file.This is the description of archi.py file. You can add description to any python file by adding a .txt file with the description. The file name should be the same as the python file. pycode-browser-1.03/Code/Maths/FamousCurves/astro.py 0000775 0000000 0000000 00000000175 13751255212 0022464 0 ustar 00root root 0000000 0000000 #Example astro.py from pylab import * a = 2 x = linspace(0,a,100) y = ( a**(2.0/3) - x**(2.0/3) )**(3.0/2) plot(x,y) show() pycode-browser-1.03/Code/Maths/FamousCurves/astropar.py 0000775 0000000 0000000 00000000200 13751255212 0023154 0 ustar 00root root 0000000 0000000 #Example astropar.py from pylab import * a = 2 t = linspace(-2*a,2*a,101) x = a * cos(t)**3 y = a * sin(t)**3 plot(x,y) show() pycode-browser-1.03/Code/Maths/FamousCurves/cover.py 0000775 0000000 0000000 00000000176 13751255212 0022453 0 ustar 00root root 0000000 0000000 from pylab import * th = linspace(0, 10*pi,1000) r = 4* sin(8*th) polar(th,r) r = sqrt(th) polar(th,r) polar(th, -r) show() pycode-browser-1.03/Code/Maths/FamousCurves/ellipse.py 0000775 0000000 0000000 00000000210 13751255212 0022757 0 ustar 00root root 0000000 0000000 #Example ellipse.py from pylab import * a = 2 b = 3 t = linspace(0, 2 * pi, 100) x = a * sin(t) y = b * cos(t) plot(x,y) show() pycode-browser-1.03/Code/Maths/FamousCurves/fermat.py 0000775 0000000 0000000 00000000176 13751255212 0022613 0 ustar 00root root 0000000 0000000 #Example fermat.py from pylab import * a = 2 th= linspace(0, 10*pi,200) r = sqrt(a**2 * th) polar(th,r) polar(th, -r) show() pycode-browser-1.03/Code/Maths/FamousCurves/lissa.py 0000775 0000000 0000000 00000000261 13751255212 0022443 0 ustar 00root root 0000000 0000000 #Example lissa.py from pylab import * a = 2 b = 3 t= linspace(0, 2*pi,100) x = a * sin(2*t) y = b * cos(t) plot(x,y) x = a * sin(3*t) y = b * cos(2*t) plot(x,y) show() pycode-browser-1.03/Code/Maths/Functions/ 0000775 0000000 0000000 00000000000 13751255212 0020302 5 ustar 00root root 0000000 0000000 pycode-browser-1.03/Code/Maths/Functions/bes1.py 0000775 0000000 0000000 00000000323 13751255212 0021507 0 ustar 00root root 0000000 0000000 from pylab import * from scipy import special def vj0(xarray): y = [] for x in xarray: val = special.j0(x) # Compute Jo y.append(val) return y a = linspace(0,10,100) b = vj0(a) plot(a,b) show() pycode-browser-1.03/Code/Maths/Functions/bes2.py 0000775 0000000 0000000 00000000353 13751255212 0021513 0 ustar 00root root 0000000 0000000 from pylab import * from scipy import * def vjn(n,xarray): y = [] for x in xarray: val = special.jn(n,x) # Compute Jn(x) y.append(val) return y a = linspace(0,10,100) for n in range(5): b = vjn(n,a) plot(a,b) show() pycode-browser-1.03/Code/Maths/Functions/bes3.py 0000775 0000000 0000000 00000001130 13751255212 0021506 0 ustar 00root root 0000000 0000000 from scipy import * from scipy import special import pylab def jn(n,x): jn = 0.0 for k in range(30): num = (-1)**k * (x/2)**(2*k) den = factorial(k)*factorial(n+k) jn = jn + num/den return jn * (x/2)**n def vjn_local(n,xarray): y = [] for x in xarray: val = jn(n,x) # Jn(x) using our function y.append(val) return y def vjn(n,xarray): y = [] for x in xarray: val = special.jn(n,x) # Compute Jn(x) y.append(val) return y a = linspace(0,10,100) for n in range(2): b = vjn(n,a) c = vjn_local(n,a) pylab.plot(a,b) pylab.plot(a,c,marker = '+') pylab.show() pycode-browser-1.03/Code/Maths/Functions/legen1.py 0000775 0000000 0000000 00000000244 13751255212 0022032 0 ustar 00root root 0000000 0000000 from scipy import linspace, special import pylab x = linspace(-1,1,100) for n in range(1,6): leg = special.legendre(n) y = leg(x) pylab.plot(x,y) pylab.show() pycode-browser-1.03/Code/Maths/Graphs/ 0000775 0000000 0000000 00000000000 13751255212 0017556 5 ustar 00root root 0000000 0000000 pycode-browser-1.03/Code/Maths/Graphs/arcs.py 0000775 0000000 0000000 00000000251 13751255212 0021061 0 ustar 00root root 0000000 0000000 #Example arcs.py from pylab import * a = 10.0 for a in range(5,21,5): th = linspace(0, pi * a/10, 200) x = a * cos(th) y = a * sin(th) plot(x,y) show() pycode-browser-1.03/Code/Maths/Graphs/circ.py 0000775 0000000 0000000 00000000245 13751255212 0021054 0 ustar 00root root 0000000 0000000 #Example circ.py from pylab import * a = 10.0 x = linspace(-a, a , 200) yupper = sqrt(a**2 - x**2) ylower = -sqrt(a**2 - x**2) plot(x,yupper) plot(x,ylower) show() pycode-browser-1.03/Code/Maths/Graphs/circpar.py 0000775 0000000 0000000 00000000177 13751255212 0021563 0 ustar 00root root 0000000 0000000 #Example circpar.py from pylab import * a = 10.0 th = linspace(0, 2*pi, 200) x = a * cos(th) y = a * sin(th) plot(x,y) show() pycode-browser-1.03/Code/Maths/Graphs/julia.py 0000775 0000000 0000000 00000002157 13751255212 0021244 0 ustar 00root root 0000000 0000000 ''' Region of a complex plane ranging from -1 to +1 in both real and imaginary axes is rpresented using a 2 dimensional matrix having X x Y elements.For X and Y equal to 200, the stepsize in the complex plane is 2.0/200 = 0.01. The nature of the pattern depends very much on the value of c. ''' from pylab import * X = 200 Y = 200 rlim = 1.0 ilim = 1.0 rscale = 2*rlim / X iscale = 2*ilim / Y MAXIT = 100 MAXABS = 2.0 c = 0.02 - 0.8j # The constant in equation z**2 + c m = zeros([X,Y],dtype=uint8) # A two dimensional array def numit(x,y): # number of iterations to diverge z = complex(x,y) for k in range(MAXIT): if abs(z) <= MAXABS: z = z**2 + c else: return k # diverged after k trials return MAXIT # did not diverge, for x in range(X): for y in range(Y): re = rscale * x - rlim # complex number represented im = iscale * y - ilim # by the (x,y) coordinate m[x][y] = numit(re,im) # get the color for (x,y) imshow(m) # Colored plot using the two dimensional matrix show() pycode-browser-1.03/Code/Maths/Graphs/npsin.py 0000775 0000000 0000000 00000000200 13751255212 0021252 0 ustar 00root root 0000000 0000000 #Example npsin.py from pylab import * x = linspace(-pi, pi , 200) y = sin(x) y1 = sin(x*x) plot(x,y) plot(x,y1,'r') show() pycode-browser-1.03/Code/Maths/Graphs/plot1.py 0000775 0000000 0000000 00000000065 13751255212 0021173 0 ustar 00root root 0000000 0000000 from pylab import * x = range(10) plot(x) show() pycode-browser-1.03/Code/Maths/Graphs/plot2.py 0000775 0000000 0000000 00000000172 13751255212 0021173 0 ustar 00root root 0000000 0000000 from pylab import * x = range(10,20) y = range(40,50) plot(x,y, marker = '+', color = 'red', markersize = 10) show() pycode-browser-1.03/Code/Maths/Graphs/plot3.py 0000775 0000000 0000000 00000000302 13751255212 0021167 0 ustar 00root root 0000000 0000000 from pylab import * x = [] # empty lists y = [] for k in range(100): ang = 0.1 * k sang = sin(ang) x.append(ang) y.append(sang) plot(x,y) show() pycode-browser-1.03/Code/Maths/Graphs/plot4.py 0000775 0000000 0000000 00000000206 13751255212 0021173 0 ustar 00root root 0000000 0000000 #Example plot4.py from pylab import * t = arange(0.0, 5.0, 0.2) plot(t, t**2,'x') # t^{2} plot(t, t**3,'ro') # t^{3} show() pycode-browser-1.03/Code/Maths/Graphs/polar.py 0000775 0000000 0000000 00000000213 13751255212 0021244 0 ustar 00root root 0000000 0000000 #Example polar.py from pylab import * th = linspace(0,2*pi,100) r = 5 * ones(100) # radius = 5 axis([0, 2*pi, 0, 10]) polar(th,r) show() pycode-browser-1.03/Code/Maths/Graphs/sine.py 0000775 0000000 0000000 00000000150 13751255212 0021065 0 ustar 00root root 0000000 0000000 #Example sine.py import math x = 0.0 while x < math.pi * 4: print( x , math.sin(x)) x = x + 0.1 pycode-browser-1.03/Code/Maths/Polynomials/ 0000775 0000000 0000000 00000000000 13751255212 0020640 5 ustar 00root root 0000000 0000000 pycode-browser-1.03/Code/Maths/Polynomials/poly.py 0000775 0000000 0000000 00000000274 13751255212 0022203 0 ustar 00root root 0000000 0000000 #Example poly.py from pylab import * a = poly1d([3,4,5]) b = poly1d([6,7]) c = a * b + 5 d = c/a print( a) print( b) print( a * b) print( d[0], d[1]) print( a.deriv()) print( a.integ()) pycode-browser-1.03/Code/Maths/Polynomials/poly1.py 0000775 0000000 0000000 00000000455 13751255212 0022265 0 ustar 00root root 0000000 0000000 import scipy import pylab a = scipy.poly1d([3,4,5]) print( a, ' is the polynomial') print( a*a, 'is its square') print( a.deriv(), ' is its derivative') print( a.integ(), ' is its integral') print( a(0.5), 'is its value at x = 0.5') x = scipy.linspace(0,5,100) b = a(x) pylab.plot(x,b) pylab.show() pycode-browser-1.03/Code/Maths/Polynomials/polyplot.py 0000775 0000000 0000000 00000000220 13751255212 0023071 0 ustar 00root root 0000000 0000000 #Example polyplot.py from pylab import * x = linspace(-pi, pi, 100) a = poly1d([-1.0/5040,0,1.0/120,0,-1.0/6,0,1,0]) y = a(x) plot(x,y) show() pycode-browser-1.03/Code/Maths/Series/ 0000775 0000000 0000000 00000000000 13751255212 0017564 5 ustar 00root root 0000000 0000000 pycode-browser-1.03/Code/Maths/Series/fourier_sawtooth.py 0000775 0000000 0000000 00000000327 13751255212 0023546 0 ustar 00root root 0000000 0000000 #Example fourier_sawtooth.py from pylab import * N = 100 # number of points x = linspace(-pi, pi, N) y = zeros(N) for n in range(1,10): term = (-1)**(n+1) * sin(n*x) / n y = y + term plot(x,y) show() pycode-browser-1.03/Code/Maths/Series/fourier_square.py 0000775 0000000 0000000 00000000327 13751255212 0023176 0 ustar 00root root 0000000 0000000 #Example fourier_square.py from pylab import * N = 100 # number of points x = linspace(0.0, 2 * pi, N) y = zeros(N) for n in range(5): term = sin((2*n+1)*x) / (2*n+1) y = y + term plot(x,y) show() pycode-browser-1.03/Code/Maths/Series/series_cos.py 0000775 0000000 0000000 00000000504 13751255212 0022276 0 ustar 00root root 0000000 0000000 import scipy, pylab def mycos(x): res = 0.0 for n in range(18): res = res + (-1)**n * (x ** (2*n)) / scipy.factorial(2*n) return res def vmycos(ax): y = [] for x in ax: y.append(mycos(x)) return y x = scipy.linspace(0,4*scipy.pi,100) y = vmycos(x) pylab.plot(x,y) pylab.plot(x,scipy.cos(x),'+') pylab.show() pycode-browser-1.03/Code/Maths/Series/series_sin.py 0000775 0000000 0000000 00000000463 13751255212 0022307 0 ustar 00root root 0000000 0000000 #Example series_sin.py from pylab import * from scipy import factorial x = linspace(-pi, pi, 50) y = zeros(50) for n in range(5): term = (-1)**(n) * (x**(2*n+1)) / factorial(2*n+1) y = y + term plot(x,term) plot(x, y, '+b') plot(x, sin(x),'xr') # compare with the real one show() pycode-browser-1.03/Code/Maths/archi.py 0000775 0000000 0000000 00000000173 13751255212 0017776 0 ustar 00root root 0000000 0000000 #Example archi.py from pylab import * a = 2 th= linspace(0, 10*pi,200) r = a*th polar(th,r) axis([0, 2*pi, 0, 70]) show() pycode-browser-1.03/Code/Maths/archi.txt 0000775 0000000 0000000 00000001612 13751255212 0020164 0 ustar 00root root 0000000 0000000 This is the description of archi.py file. You can add description to any python file by adding a .txt file with the description. The file name should be the same as the python file.This is the description of archi.py file. You can add description to any python file by adding a .txt file with the description. The file name should be the same as the python file.This is the description of archi.py file. You can add description to any python file by adding a .txt file with the description. The file name should be the same as the python file.This is the description of archi.py file. You can add description to any python file by adding a .txt file with the description. The file name should be the same as the python file.This is the description of archi.py file. You can add description to any python file by adding a .txt file with the description. The file name should be the same as the python file. pycode-browser-1.03/Code/Maths/arcs.py 0000775 0000000 0000000 00000000251 13751255212 0017635 0 ustar 00root root 0000000 0000000 #Example arcs.py from pylab import * a = 10.0 for a in range(5,21,5): th = linspace(0, pi * a/10, 200) x = a * cos(th) y = a * sin(th) plot(x,y) show() pycode-browser-1.03/Code/Maths/area.py 0000775 0000000 0000000 00000000162 13751255212 0017616 0 ustar 00root root 0000000 0000000 #Example: area.py pi = 3.1416 r = input('Enter Radius ') a = pi * r ** 2 #A=\pi r^{2} print( 'Area = ', a) pycode-browser-1.03/Code/Maths/astro.py 0000775 0000000 0000000 00000000175 13751255212 0020042 0 ustar 00root root 0000000 0000000 #Example astro.py from pylab import * a = 2 x = linspace(0,a,100) y = ( a**(2.0/3) - x**(2.0/3) )**(3.0/2) plot(x,y) show() pycode-browser-1.03/Code/Maths/astropar.py 0000775 0000000 0000000 00000000200 13751255212 0020532 0 ustar 00root root 0000000 0000000 #Example astropar.py from pylab import * a = 2 t = linspace(-2*a,2*a,101) x = a * cos(t)**3 y = a * sin(t)**3 plot(x,y) show() pycode-browser-1.03/Code/Maths/badtable.py 0000775 0000000 0000000 00000000135 13751255212 0020444 0 ustar 00root root 0000000 0000000 #Example: badtable.py print( 1 * 8) print( 2 * 8) print( 3 * 8) print( 4 * 8) print( 5 * 8) pycode-browser-1.03/Code/Maths/big.py 0000775 0000000 0000000 00000000241 13751255212 0017445 0 ustar 00root root 0000000 0000000 #Example: big.py x = input('Enter a number ') if x > 10: print( 'Bigger Number') elif x < 10: print( 'Smaller Number') else: print( 'Same Number') pycode-browser-1.03/Code/Maths/big2.py 0000775 0000000 0000000 00000000204 13751255212 0017526 0 ustar 00root root 0000000 0000000 #Example: big2.py x = 1 while x < 11: if x < 5: print( 'Samll ', x) else: print( 'Big ', x) print( 'Done') pycode-browser-1.03/Code/Maths/big3.py 0000775 0000000 0000000 00000000214 13751255212 0017530 0 ustar 00root root 0000000 0000000 #Example: big3.py x = 1 while x < 100: print( x) if x > 10: print( 'Enough of this') break x = x + 1 print( 'Done') pycode-browser-1.03/Code/Maths/circ.py 0000775 0000000 0000000 00000000245 13751255212 0017630 0 ustar 00root root 0000000 0000000 #Example circ.py from pylab import * a = 10.0 x = linspace(-a, a , 200) yupper = sqrt(a**2 - x**2) ylower = -sqrt(a**2 - x**2) plot(x,yupper) plot(x,ylower) show() pycode-browser-1.03/Code/Maths/circpar.py 0000775 0000000 0000000 00000000177 13751255212 0020337 0 ustar 00root root 0000000 0000000 #Example circpar.py from pylab import * a = 10.0 th = linspace(0, 2*pi, 200) x = a * cos(th) y = a * sin(th) plot(x,y) show() pycode-browser-1.03/Code/Maths/cloth.py 0000775 0000000 0000000 00000000474 13751255212 0020025 0 ustar 00root root 0000000 0000000 class clothing: def __init__(self,colour, rate): self.colour = colour self.rate = rate def getcolour(self): return self.colour cheapblue = clothing('blue', 20.0) costlyred = clothing('red', 100.0) print( cheapblue.rate) print( costlyred) pycode-browser-1.03/Code/Maths/cloth2.py 0000775 0000000 0000000 00000000600 13751255212 0020076 0 ustar 00root root 0000000 0000000 class clothing: def __init__(self,colour, rate): self.colour = colour self.rate = rate def getcolour(self): return self.colour def __str__(self): return '%s Cloth at Rs. %6.2f per sqmtr'%(self.colour, self.rate) cheapblue = clothing('blue', 20.0) costlyred = clothing('red', 100.0) print( cheapblue.rate) print( costlyred) pycode-browser-1.03/Code/Maths/clothbill.py 0000775 0000000 0000000 00000002226 13751255212 0020665 0 ustar 00root root 0000000 0000000 class clothing: def __init__(self,colour, rate): self.colour = colour self.rate = rate def getcolour(self): return self.colour def __str__(self): return '%s Cloth at Rs. %6.2f per sqmtr'%(self.colour, self.rate) class pants(clothing): def __init__(self, cloth, size, labour): self.labour = labour self.size = size clothing.__init__(self,cloth.colour, cloth.rate) def __str__(self): return '%-10s Pants'%(self.colour) def getcost(self): return self.rate * self.size + self.labour class shirt(clothing): def __init__(self, cloth, size, labour): self.labour = labour self.size = size clothing.__init__(self,cloth.colour, cloth.rate) def __str__(self): return '%-10s Shirt'%(self.colour) def getcost(self): return self.rate * self.size + self.labour cheapblue = clothing('blue', 20.0) costlyred = clothing('red', 100.0) items = [] items.append(pants(cheapblue, 2.0, 150.0) ) items.append(shirt(costlyred, 1.5, 130.0) ) for k in items: print( k, k.getcost()) pycode-browser-1.03/Code/Maths/compareEuRK4.py 0000775 0000000 0000000 00000001162 13751255212 0021150 0 ustar 00root root 0000000 0000000 ''' Sine function is calculated using its derivative, cosine. Using Euler and RK4 method, with ''' import math def rk4(x, y, yprime, dx = 0.01): # x, y , derivative, stepsize k1 = dx * yprime(x) k2 = dx * yprime(x + dx/2.0) k3 = dx * yprime(x + dx/2.0) k4 = dx * yprime(x + dx) return y + ( k1/6 + k2/3 + k3/3 + k4/6 ) h = 0.01 # stepsize x = 0.0 # initail values y = 0.0 # for Euler z = 0.0 # for RK4 while x < math.pi: print( x, y - math.sin(x), z - math.sin(x)) # errors y = y + h * math.cos(x) # Euler method z = rk4(x,z,math.cos,h) # Runge-Kutta method x = x + h pycode-browser-1.03/Code/Maths/conflict.py 0000775 0000000 0000000 00000000365 13751255212 0020514 0 ustar 00root root 0000000 0000000 #Example conflict.py from numpy import * x = linspace(0, 5, 10) # make a 10 element array print( sin(x)) # sin of scipy can handle arrays from math import * # sin of math will be called now print( sin(x) ) # will give ERROR pycode-browser-1.03/Code/Maths/cover.py 0000775 0000000 0000000 00000000176 13751255212 0020031 0 ustar 00root root 0000000 0000000 from pylab import * th = linspace(0, 10*pi,1000) r = 4* sin(8*th) polar(th,r) r = sqrt(th) polar(th,r) polar(th, -r) show() pycode-browser-1.03/Code/Maths/cross.py 0000775 0000000 0000000 00000000146 13751255212 0020041 0 ustar 00root root 0000000 0000000 #Example cross.py from numpy import * a = array([1,2,3]) b = array([4,5,6]) c = cross(a,b) print( c) pycode-browser-1.03/Code/Maths/diff.py 0000775 0000000 0000000 00000000305 13751255212 0017615 0 ustar 00root root 0000000 0000000 #Example diff.py def f(x): return x**3 def deriv(x,dx=0.005): df = f(x+dx/2)-f(x-dx/2) return df/dx print( deriv(2.0)) print( deriv(2.0, 0.1)) print( deriv(2.0, 0.0001)) pycode-browser-1.03/Code/Maths/ellipse.py 0000775 0000000 0000000 00000000210 13751255212 0020335 0 ustar 00root root 0000000 0000000 #Example ellipse.py from pylab import * a = 2 b = 3 t = linspace(0, 2 * pi, 100) x = a * sin(t) y = b * cos(t) plot(x,y) show() pycode-browser-1.03/Code/Maths/euler.py 0000775 0000000 0000000 00000000275 13751255212 0020027 0 ustar 00root root 0000000 0000000 import math h = 0.01 # stepsize x = 0.0 # initail values y = 0.0 while x < math.pi: print( x, y, math.sin(x) ) y = y + h * math.cos(x) # Euler method x = x + h pycode-browser-1.03/Code/Maths/factor.py 0000775 0000000 0000000 00000000246 13751255212 0020167 0 ustar 00root root 0000000 0000000 #Example factor.py def factorial(n): # a recursive function if n == 0: return 1 else: return n * factorial(n-1) print( factorial(10) ) pycode-browser-1.03/Code/Maths/fermat.py 0000775 0000000 0000000 00000000176 13751255212 0020171 0 ustar 00root root 0000000 0000000 #Example fermat.py from pylab import * a = 2 th= linspace(0, 10*pi,200) r = sqrt(a**2 * th) polar(th,r) polar(th, -r) show() pycode-browser-1.03/Code/Maths/fileio.py 0000775 0000000 0000000 00000000163 13751255212 0020156 0 ustar 00root root 0000000 0000000 #Example fileio.py from numpy import * a = arange(10) a.tofile('myfile.dat') b = fromfile('myfile.dat') print( b) pycode-browser-1.03/Code/Maths/filelist.html 0000775 0000000 0000000 00000002711 13751255212 0021037 0 ustar 00root root 0000000 0000000