def find_super_start_points(a,k, x_left, x_right, y_down, y_up):
    x = x_left
    while (x <= x_right):
        y = y_down
        while (y <= y_up):
            #print (x,y)
            if (abs(f(k,x,y)) <= sigma and abs(g(a,x,y)) <= sigma):
                print "--- Start point found! : ", x , ",", y , "; f = ", f(k,x,y), " ; g = ", g(a, x, y)
                return [x, y]    
            y += epsilon
        x += epsilon
    return []
def solve_system(a, k, squares):
    print "--- Solving system for a=", a, "| k=", k
    print "f(x,y) = ", "exp(", k ," * x + y) - x*y - 1.4"
    print "g(x,y) = ", "(x^2)/", "(", a, "^2) + 2*(y^2) - 4"
    print "--- Finding start points..."
    solutions = []
    for square in squares:
        print "--- Solving on ", square
        super_start = find_super_start_points(a, k, *square)
        print "--- Search has been ended"
        if (super_start != []):
            i = 1
            current = super_start
            previous = [current[0] - 1, current[1] - 1]
            table_head = ["i", "x", "y", "f(x, y)", "g(x, y)"]
            rows = []
            while not((abs(current[0] - previous[0]) < gamma) and (abs(current[1] - previous[1]) < gamma) ):
                previous = current
                x_k = current[0]
                y_k = current[1]
                current = [x_k + det_x(a, k, x_k, y_k) / det(a, k, x_k, y_k)  ,  y_k + det_y(a, k, x_k, y_k) / det(a, k, x_k, y_k)  ]
                row = [i, current[0],  current[1], f(k, x_k, y_k), g(a, x_k, y_k)]
                rows.append(row)
                i += 1
            print tabulate.tabulate(rows, table_head, "rst")
            print "--- Solved : ", current
            solutions += current
        else:
            print "--- No points found!"
    print "---SOLUTIONS: ", solutions
Ejemplo n.º 3
0
Archivo: lab07.py Proyecto: haanaks/aip
import entering as en
import my_functions as func
from collections import defaultdict

values = defaultdict(list)
en.x, en.x2, en.h, en.a = float(en.x), float(en.x2), float(en.h), float(en.a)
while True:
    try:
        while en.x <= en.x2:
            try:
                values[1].append(func.g(en.x, en.a))
                values[2].append(func.f(en.x, en.a))
                values[3].append(func.y(en.x, en.a))
                en.x += en.h
            except ValueError:
                print('Error')
        with open('function_values.txt', 'w+') as f:
            for key in range(1, 4):
                f.write(';'.join(str(values[key])))
                values[1].append(f.read())
        print(values[1])
    except KeyboardInterrupt:
        print('bye')
    ex = input('Do you wanna repeat?(y or n)')
    if ex == 'y':
        pass
    else:
        raise SystemExit()
Ejemplo n.º 4
0
        s = int(input('Also please select a function'))

        mas_y, mas_x = [], []
        while x <= x2:
            if s == 1:
                try:
                    mas_x.append(x)
                    mas_y.append(func.g(x, a))
                    print(x, func.g(x, a))
                    x += h
                except ValueError:
                    print('Error')
            elif s == 2:
                try:
                    mas_x.append(x)
                    mas_y.append(func.f(x, a))
                    print(x, func.f(x, a))
                    x += h
                except ValueError:
                    print('Error')
            elif s == 3:
                try:
                    mas_x.append(x)
                    mas_y.append(func.y(x, a))
                    print(x, func.y(x, a))
                    x += h
                except ValueError:
                    print('Error')

        plt.plot(mas_x, mas_y)
        plt.title('График функции')
Ejemplo n.º 5
0
    return val


path = 'C:/Users/User/Documents/bn_all/'
files = [f for f in glob.glob(path + '*.mrk8', recursive=True)]

encoding = 'utf-8'
marc_df = pd.DataFrame()
for i, file_path in enumerate(files):
    print(str(i) + '/' + str(len(files)))
    marc_list = io.open(file_path, 'rt', encoding=encoding).read().splitlines()
    marc_list = list(filter(None, marc_list))
    df = pd.DataFrame(marc_list, columns=['test'])
    df['field'] = df['test'].replace(r'(^.)(...)(.+?$)', r'\2', regex=True)
    df['content'] = df['test'].replace(r'(^.)(.....)(.+?$)', r'\3', regex=True)
    df['help'] = df.apply(lambda x: f(x, 'LDR'), axis=1)
    df['help'] = df['help'].ffill()
    df['year'] = df.apply(lambda x: year(x, '008'), axis=1)
    df['year'] = df.groupby('help')['year'].ffill().bfill()
    df = df[df['year'].isin([str(i) for i in range(2013, 2020)])]
    if len(df) > 0:
        df['id'] = df.apply(lambda x: f(x, '009'), axis=1)
        df['id'] = df.groupby('help')['id'].ffill().bfill()
        df = df[['id', 'field', 'content']]
        df['content'] = df.groupby(['id', 'field'])['content'].transform(
            lambda x: '❦'.join(x.drop_duplicates().astype(str)))
        df = df.drop_duplicates().reset_index(drop=True)
        df_wide = df.pivot(index='id', columns='field', values='content')
        marc_df = marc_df.append(df_wide)

fields = marc_df.columns.tolist()
Ejemplo n.º 6
0
Archivo: lab02.py Proyecto: haanaks/aip
import my_functions

a = float(input('Please enter a'))
x = float(input('Please enter x'))
s = int(input('Also please select a function: [G-1];[F-2];[Y-3]'))

if s == 1:
    try:
        print(my_functions.g(x, a))
    except ValueError:
        print('error')
elif s == 2:
    try:
        print(my_functions.f(x, a))
    except ValueError:
        print('error')
elif s == 3:
    try:
        print(my_functions.y(x, a))
    except ValueError:
        print('error')
else:
    print('Sorry,you have wrote invalid number')
Ejemplo n.º 7
0
for path_in in paths_in:
    reader = io.open(path_in, 'rt', encoding='utf-8').read().splitlines()
    mrk_list = []
    for row in reader:
        if '=LDR' not in row:
            mrk_list[-1] += '\n' + row
        else:
            mrk_list.append(row)
    mrk_list = [r for r in mrk_list if re.findall('\=650.+czeska', r.lower())]
    for record in mrk_list:
        record = record.split('=')
        record = list(filter(None, record))
        for i, row in enumerate(record):
            record[i] = record[i].rstrip().split('  ', 1)
        df = pd.DataFrame(record, columns=['field', 'content'])
        df['id'] = df.apply(lambda x: f(x, '001'), axis=1)
        df['id'] = df['id'].ffill().bfill()
        df['content'] = df.groupby(['id', 'field'])['content'].transform(
            lambda x: '❦'.join(x.drop_duplicates().astype(str)))
        df = df.drop_duplicates().reset_index(drop=True)
        df_wide = df.pivot(index='id', columns='field', values='content')
        full_data = full_data.append(df_wide)

fields_order = full_data.columns.tolist()
fields_order.sort(key=lambda x: ([str, int].index(
    type("a" if re.findall(r'\w+', x)[0].isalpha() else 1)), x))
full_data = full_data.reindex(columns=fields_order)

df_to_mrc(full_data, '❦',
          'F:/Cezary/Documents/IBL/Libri/Iteracja 10.2020/cz_from_pbl.mrc')
Ejemplo n.º 8
0
k = 0
shablon = input('Enter shablon')
func_values = []
en.x, en.x2, en.h, en.a, en.s = float(en.x), float(en.x2), float(en.h), float(en.a), float(en.s)
while True:
    try:
        while en.x <= en.x2:
            if en.s == 1:
                try:
                    func_values.append(func.g(en.x, en.a))
                    en.x += en.h
                except ValueError:
                    print('Error')
            elif en.s == 2:
                try:
                    func_values.append(func.f(en.x, en.a))
                    en.x += en.h
                except ValueError:
                    print('Error')
            elif en.s == 3:
                try:
                    func_values.append(func.y(en.x, en.a))
                    en.x += en.h
                except ValueError:
                    print('Error')
        print('; '.join(str(i) for i in func_values))
        for i in func_values:
            if str(i) == shablon:
                k += 1
        print(k)
    except KeyboardInterrupt: