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
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 []
Example #3
0
File: lab07.py Project: 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()
Example #4
0
import matplotlib.pyplot as plt

while True:
    try:
        x = float(input('Enter lowest x'))
        x2 = float(input('Enter highest x'))
        h = float(input('Enter step'))
        a = float(input('Enter a'))
        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)
Example #5
0
	def f(x, y):
		return g(x + y)
Example #6
0
File: lab02.py Project: 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')
Example #7
0
def f(x, y):
    return g(x + y)
Example #8
0
def main():
    x = 6
    y = 7.5
    result = x + y
    print(g(result))
    print(result)
Example #9
0
import entering as en
import my_functions as func

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: