Esempio n. 1
0

def evalcmlarg(text):
    return eval(text)

parser.add_argument(
    '--n', '--n_list', type=evalcmlarg, default='[1, 3, 5, 10, 30, 100]',
    help='List of n values')
parser.add_argument(
    '--alpha', '--alpha_list', type=evalcmlarg, default='[0.01, 0.25, 0.49]',
    help='List of alpa values')
parser.add_argument('--T', type=evalcmlarg, default='2*pi',
                    help='Domain of function')
args = parser.parse_args()

table(args.n, args.alpha, args.T)

"""
Sample run:
python sinesum4.py --n '[1, 3, 5, 10, 30, 100]' --alpha '[0.01, 0.25, 0.49]' --T 2*pi
n = 1
  Function t=0.01*pi t=0.25*pi t=0.49*pi
   f(t, T) 1.0000000 0.0000000 -1.0000000
S(t, n, T) 0.1595792 0.0000000 -0.1595792
     Error 0.8404208 0.8404208 0.8404208

n = 3
  Function t=0.01*pi t=0.25*pi t=0.49*pi
   f(t, T) 1.0000000 0.0000000 -1.0000000
S(t, n, T) 0.4654944 0.0000000 -0.4654944
     Error 0.5345056 0.5345056 0.5345056
Esempio n. 2
0
import sys, argparse
from sinesum2 import table
from math import pi

parser = argparse.ArgumentParser()
parser.add_argument('--n', '--number of iterations', type=str, default='[99]', help='number of iterations', metavar='n')
parser.add_argument('--alpha', '--phase', type=str, default='[0.1]', help='phase', metavar='alpha')
parser.add_argument('--T', '--period', type=float, default=2*pi, help='period', metavar='T')
args = parser.parse_args()

n_values = eval(args.n)
print '\nn     =', n_values
alpha_values = eval(args.alpha)
print 'alpha =', alpha_values
T = args.T
print 'T     =', T, '\n'
table(n_values, alpha_values, T)
Esempio n. 3
0

parser.add_argument("--T",
                    "--function domain max. value",
                    type=evalcmlarg,
                    default=1.0,
                    help="function domain max. value",
                    metavar="T")

parser.add_argument("--alpha",
                    "--points to evaluate: alpha*T",
                    type=evalcmlarg,
                    default=[0.1, 0.2],
                    help="--points to evaluate: alpha*T, 0<alpha<1",
                    metavar="alpha")

parser.add_argument("--n",
                    "--nums. of iterations",
                    type=evalcmlarg,
                    default=[50, 100],
                    help="--nums. of iteration",
                    metavar="n")

args = parser.parse_args()

T = args.T
n = args.n
alpha = args.alpha
#print T, alpha, n
table(n, alpha, T)
Esempio n. 4
0

def evalcmlarg(text):
    return eval(text)

parser.add_argument(
    '--n', '--n_list', type=evalcmlarg, default='[1, 3, 5, 10, 30, 100]',
    help='List of n values')
parser.add_argument(
    '--alpha', '--alpha_list', type=evalcmlarg, default='[0.01, 0.25, 0.49]',
    help='List of alpa values')
parser.add_argument('--T', type=evalcmlarg, default='2*pi',
                    help='Domain of function')
args = parser.parse_args()

table(args.n, args.alpha, args.T)

"""
Sample run:
python sinesum4.py --n '[1, 3, 5, 10, 30, 100]' --alpha '[0.01, 0.25, 0.49]' --T 2*pi
n = 1
  Function t=0.01*pi t=0.25*pi t=0.49*pi
   f(t, T) 1.0000000 0.0000000 -1.0000000
S(t, n, T) 0.1595792 0.0000000 -0.1595792
     Error 0.8404208 0.8404208 0.8404208

n = 3
  Function t=0.01*pi t=0.25*pi t=0.49*pi
   f(t, T) 1.0000000 0.0000000 -1.0000000
S(t, n, T) 0.4654944 0.0000000 -0.4654944
     Error 0.5345056 0.5345056 0.5345056
Esempio n. 5
0
from sinesum2 import S, f, table
_filname = sys.argv[0]
_usage = """ % _filname
Usage: %s '[1, 3, 75, 10, 30, 100]' '[0.01, 0.25, 0.49]' 2*pi
Computes the sine sum approximation of a piecewise constant 
function. Takes n list, alpha list and function domain.
"""

if len(sys.argv) < 4:
    print _usage
    raise IndexError(
        'Domain, n list and alpha list must be given on command-line')
n_list = eval(sys.argv[1])
alpha_list = eval(sys.argv[2])
T = eval(sys.argv[3])
table(n_list, alpha_list, T)

"""
Sample run:
python sinesum1.py '[1, 3, 75, 10, 30, 100]' '[0.01, 0.25, 0.49]' 2*pi
n = 1
  Function t=0.01*pi t=0.25*pi t=0.49*pi
   f(t, T) 1.0000000 0.0000000 -1.0000000
S(t, n, T) 0.1595792 0.0000000 -0.1595792
     Error 0.8404208 0.8404208 0.8404208

n = 3
  Function t=0.01*pi t=0.25*pi t=0.49*pi
   f(t, T) 1.0000000 0.0000000 -1.0000000
S(t, n, T) 0.4654944 0.0000000 -0.4654944
     Error 0.5345056 0.5345056 0.5345056