diff options
author | hardythe1 | 2013-11-08 12:25:43 +0530 |
---|---|---|
committer | hardythe1 | 2013-11-08 12:25:43 +0530 |
commit | 5c96aba148286bb3989592701dc47d3c46563891 (patch) | |
tree | 10b8b174bce6331bfb92e4c583e3ca1267ce4eb3 /tbc/static/uploads/Hardik/C/nr.py | |
parent | 76e013fd4efe5a5262243d4ac10445a1a5d4b1ad (diff) | |
download | Python-TBC-Interface-5c96aba148286bb3989592701dc47d3c46563891.tar.gz Python-TBC-Interface-5c96aba148286bb3989592701dc47d3c46563891.tar.bz2 Python-TBC-Interface-5c96aba148286bb3989592701dc47d3c46563891.zip |
adding reviewer interface
Diffstat (limited to 'tbc/static/uploads/Hardik/C/nr.py')
-rw-r--r-- | tbc/static/uploads/Hardik/C/nr.py | 51 |
1 files changed, 0 insertions, 51 deletions
diff --git a/tbc/static/uploads/Hardik/C/nr.py b/tbc/static/uploads/Hardik/C/nr.py deleted file mode 100644 index 47ac557..0000000 --- a/tbc/static/uploads/Hardik/C/nr.py +++ /dev/null @@ -1,51 +0,0 @@ -import sys, math, argparse, time -from sympy import * - -start_time = time.time() - -# using argparse to get command line arguments -parser = argparse.ArgumentParser() -parser.add_argument("-f", "--function", help = "Define a function") -parser.add_argument("-s", "--starting", help = "Starting point value", type = float, default = 0.0) -parser.add_argument("-p", "--precision", help = "Convergence precision", type = float, default = 5*10**(-6)) -args = parser.parse_args() - -sym_x = Symbol('x') -# convert the given function to a symbolic expression -try: - fx = S(args.function) -except: - sys.exit('Unable to convert function to symbolic expression.') - -# calculate the differential of the function -try: - dfdx = diff(fx, Symbol('x')) -except: - sys.exit('Unable to differentiate function.') - -# e is the relative error between 2 consecutive estimations of the root -e = 1 -x0 = args.starting -iterations = 0 - -while ( e > args.precision ): - # new root estimation - try: - r = x0 - fx.subs({sym_x : x0})/dfdx.subs({sym_x : x0}) - except ZeroDivisionError: - print "Function derivative is zero. Division by zero, program will terminate." - sys.exit() - # relative error - e = abs((r - x0)/r) - iterations += 1 - x0 = r - -total_time = time.time() - start_time - -print 'Function:' -pprint(fx) -print 'Derivative:' -pprint(dfdx) -print 'Root %10.6f calculated after %d iterations'%(r, iterations) -print 'Function value at root %10.6f'%(fx.subs({sym_x : r}),) -print 'Finished in %10.6f seconds'%(total_time,) |