Exemple #1
0
def get_nonlinear(dim):
    global nonlinear
    if dim == 2:
        nonlinear = equation(nleq_21_coeff, nleq_21_rhs, 2, nleq_21_bc, nleq_21_exact, nleq_21_lcoeff)
    if dim == 1:
        nonlinear = equation(nleq1_coeff, nleq1_rhs, 1, nleq1_bc, nleq1_exact, l_coeff=nleq1_l_coeff)
    return nonlinear
Exemple #2
0
def main() -> None:
    f_o = equation().left_hand_side({'z': 1}).right_hand_side({'A': 1, 'B': 2})
    constraints = [
        inequality().left_hand_side({
            'A': 1,
            'B': 4
        }).inequality_symbol("<=").right_hand_side({'const': 21}),
        inequality().left_hand_side({
            'A': 2,
            'B': 1
        }).inequality_symbol(">=").right_hand_side({'const': 7}),
        inequality().left_hand_side({
            'A': 3,
            'B': 1.5
        }).inequality_symbol("<=").right_hand_side({'const': 21}),
        inequality().left_hand_side({
            'A': -2,
            'B': 6
        }).inequality_symbol(">=").right_hand_side({'const': 0}),
    ]
    # usual constraints: y, x >= 0
    standard_form(f_o, constraints)
    simplex_table = SimplexTable(constraints, f_o)
    simplex_table.build_matrix()
    while (True):
        break
Exemple #3
0
def standard_form(f_o: equation, constraints: list):
    i = 0
    for _ in constraints:
        constraints[i] = equation().turn_inequality_to_equality(
            constraints[i], len(constraints), i)
        i += 1

    f_o.everything_to_lhs()
Exemple #4
0
def solver(function, varList, angleMode):

    check_function = preprocess(function)

    if detect_eq_inqe(check_function):
        res_data = equation(check_function, varList, angleMode)
        # print(res_data)
    else:
        res_data = inequation(function)
        # data_trim = res_data.replace("\\","").replace('"[','[').replace(']"',']').replace('"{','{').replace('}"','}')
        # print('Json String: ', data_trim)
        # a2 = json.loads(res_data)
        # print('Test', a2['function'])
        # print('Test', a2['step'])
        # print('Test', a2['child'])
        # print('     ', a2['child'][0]['function'])
        # print('     ', a2['child'][0]['step'])
        # print('     ', a2['child'][0]['child'])
        # print('          ', a2['child'][0]['child'][0])
        # print('               ', a2['child'][0]['child'][0]['function'])
        # print('     ', a2['child'][0]['result'])
        # print('Test', a2['result'])
    return res_data


# solver("x**4-3*x**3-7*x**2+7*x+2")

#Read data from stdin
# def read_in():
#     lines = sys.stdin.readlines()
#     # Since our input would only be having one line, parse our JSON data from that
#     return json.loads(lines[0])
#     #return lines[0]

# def main():
#     data = read_in()
#     start = timeit.default_timer()
#     result = solver(data['sympy'])
#     stop = timeit.default_timer()
#     time = stop - start 

#     temp = str(result)
#     temp2 = json.loads(temp)

#     datareturn = {}
#     datareturn["time"] = time
#     datareturn["accurate"] = temp2
#     datareturn["approximate"] = ""
#     json_data = json.dumps(datareturn)
    
#     # result = {"sympy": sympyTrim, "numpy": normalTrim}
#     # json_data = json.dumps(result)
#     # print json_data
#     #print lines['node'][0]['node']
#     # Start process

# if __name__ == '__main__':
#     main()
Exemple #5
0
def get_quasilinear(dim, number, a=1):
    """
    This function provide two 1d quasilinear equations and to 2d quasilinear
    equations.


    -------------------
    dim = 1, number = 1

    [(1 + exp(x*y))d2y + (2 + cos(pi*x))d2x + exp(-x*y)dxdy + exp(x)dx +
    exp(y)dy + sin(pi*x*y)]u = rhs

    u_exact = exp(x*y), bc and rhs are taken from the operator and exact solution.
    -------------------
    dim = 1, number = 2

    [(4 + cos(2*pi*x*y))d2y + (2 + sin(pi*x*y))d2x + exp(-x*y)dxdy + exp(x)dx +
    exp(y)dy + sin(pi*x*y) + 2]u = rhs

    u_exact = exp(x+y), bc and rhs are taken from the operator and exact solution.
    -------------------
    dim = 2, number = 1

    Add description later!

    Parameters
    ----------
    dim: int
    Dimensionality: 2 for two equations, 1 for the one equation.

    number: int
    The number of the equation: 1 or 2 in case of any dimensionality.
    """
    if dim == 1:
        if number == 0:
            quasilinear = equation(eq_00_coeff, eq_00_rhs, 1, eq_00_bc, eq_00_exact)
        if number == 1:
            quasilinear = equation(eq_11_coeff, eq_11_rhs, 1, eq_11_bc, eq_11_exact)
        if number == 2:
            quasilinear = equation(eq_12_coeff, eq_12_rhs, 1, eq_12_bc, eq_12_exact)
        if number == 3:
            quasilinear = equation(eq_13_coeff, eq_13_rhs, 1, eq_13_bc, eq_13_exact)
        if number == 4:
            quasilinear = equation(eq_14_coeff, eq_14_rhs, 1, eq_14_bc, eq_14_exact)
        if number == 'red fox':
            rhs = lambda x: eq_red_fox_rhs(x, a)
            coeff = lambda x: eq_red_fox_coeff(x, a)
            quasilinear = equation(coeff, rhs, 1, eq_red_fox_bc, eq_red_fox_exact)
    if dim == 2:
        if number == 1:
            quasilinear = equation(eq_21_coeff, eq_21_rhs, 2, eq_21_bc, eq_21_exact)
        if number == 2:
            quasilinear = equation(eq_22_coeff, eq_22_rhs, 2, eq_22_bc, eq_22_exact)
    return quasilinear
Exemple #6
0
    def __init__(self, path):
        QWidgetSavePos.__init__(self, "spectra_main")
        self.path = path
        self.setFixedSize(900, 600)
        self.setWindowIcon(icon_get("spectra_file"))

        self.setWindowTitle(
            _("Optical spectrum editor") + " (https://www.gpvdm.com)" + " " +
            os.path.basename(self.path))

        self.main_vbox = QVBoxLayout()

        toolbar = QToolBar()
        toolbar.setIconSize(QSize(48, 48))

        spacer = QWidget()
        spacer.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        toolbar.addWidget(spacer)

        self.help = QAction(icon_get("help"), 'Hide', self)
        self.help.setStatusTip(_("Help"))
        self.help.triggered.connect(self.callback_help)
        toolbar.addAction(self.help)

        self.main_vbox.addWidget(toolbar)

        self.notebook = QTabWidget()

        self.notebook.setMovable(True)

        self.main_vbox.addWidget(self.notebook)

        files = ["mat.inp"]
        description = [_("Parameters")]

        eq = equation(self.path, "spectra_eq.inp", "spectra_gen.inp",
                      "spectra.inp", "#spectra_equation_or_data")
        eq.show_solar_spectra = True
        eq.set_default_value("3")
        eq.set_ylabel(_("Intensity") + " (au)")
        eq.init()
        self.notebook.addTab(eq, _("Intensity"))

        for i in range(0, len(files)):
            tab = tab_class()
            tab.init(os.path.join(self.path, files[i]), description[i])
            self.notebook.addTab(tab, description[i])

        self.setLayout(self.main_vbox)

        self.notebook.currentChanged.connect(self.changed_click)
Exemple #7
0
def solve_poly_inequation(function):
    data = preprocess_inquetion(function)
    temp = str(data)
    abc = json.loads(temp)

    expression = abc["expression"]
    # print('Solve:')

    temp2 = equation(preprocess(expression))
    temp2 = str(temp2)
    temp3 = json.loads(temp2)

    datareturn = {}
    datareturn["step"] = abc["step"]
    datareturn["child"] = (temp3)
    json_data = json.dumps(datareturn)
    return json_data
Exemple #8
0
def reduce_lines(lines):
    max_tolorence = 1
    max_distance = 55
    lines_equs = []
    for line in lines:
        lines_equs.append(
            equation(line[0][0], line[0][1], line[0][2], line[0][3]))
    lines_equs = sorted(lines_equs, key=lambda x: x.length(), reverse=True)
    for line1 in lines_equs:
        for line2 in lines_equs:
            if line1 != line2 and abs(line1.slope -
                                      line2.slope) < max_tolorence:
                if (line1.distance_from(line2) < max_distance):
                    lines_equs.remove(line2)
    for line1 in lines_equs:
        for line2 in lines_equs:
            if line1 != line2 and abs(line1.rho - line2.rho) < 30 and abs(
                    line1.theta - line2.theta) < 1:
                lines_equs.remove(line2)
    return lines_equs
Exemple #9
0
	index = 0

	while 1:
		if (roots[index] < right_border and roots[index] > left_border):
			out_file.write('{} \n'.format(roots[index]))
		index = index + 1

		if (index > right_border):
			break

	out_file.close()

if __name__ == '__main__':

	Start_time = time.time()
	lft_bord = 2
	rgt_bord = 150

	my_object = eq.equation(1e-12)

	my_object.calculate(lft_bord, rgt_bord)

	my_object.simle_check()

	#print_report(0,10,my_object.get_roots())

	draw_plots(lft_bord, rgt_bord, my_object.get_roots())

	print("the program worked for", str((int(time.time()-Start_time)) % 60).zfill(2), "seconds")
Exemple #10
0
def diagram_sum_3body(x, d):
    point = equation.equation(3. * x, '2D', 20., 0.1, d)
    point.solve()
    g3 = point.g3
    del point
    return 4. * pi / log(d**2 * 2. * x) + g3
Exemple #11
0
import sys
import equation as eq

print("Enter the second degree equation(ax² + bx + c = 0)")

a = int(input("Enter the a: "))
b = int(input("Enter the b: "))
c = int(input("Enter the c: "))

equation = eq.equation(a, b, c)

delta_status = equation.calculate_delta()

if delta_status == 0:
    equation.calculate_results()

elif delta_status == 1:
    equation.calculate_complex_results()

elif delta_status == 2:
    print("Result is not real number")
    sys.exit()

equation.print_results()
	def __init__(self,path):
		QWidget.__init__(self)
		self.path=path
		self.setFixedSize(900, 600)
		self.setWindowIcon(QIcon(os.path.join(get_image_file_path(),"organic_material.png")))

		self.setWindowTitle(_("Material editor (www.gpvdm.com)")) 
		

		self.main_vbox = QVBoxLayout()

		toolbar=QToolBar()
		toolbar.setIconSize(QSize(48, 48))

		self.cost = QAction(QIcon(os.path.join(get_image_file_path(),"cost.png")), 'Hide', self)
		self.cost.setStatusTip(_("Cost of material"))
		self.cost.triggered.connect(self.callback_cost)
		toolbar.addAction(self.cost)
		
		spacer = QWidget()
		spacer.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
		toolbar.addWidget(spacer)


		self.help = QAction(QIcon(os.path.join(get_image_file_path(),"help.png")), 'Hide', self)
		self.help.setStatusTip(_("Help"))
		self.help.triggered.connect(self.callback_help)
		toolbar.addAction(self.help)

		self.main_vbox.addWidget(toolbar)


		self.notebook = QTabWidget()

		self.notebook.setMovable(True)

		self.main_vbox.addWidget(self.notebook)


		files=["dos.inp","pl.inp"]
		description=[_("Electrical parameters"),_("Luminescence")]


		for i in range(0,len(files)):
			tab=tab_class()
			tab.init(os.path.join(self.path,files[i]),description[i])
			self.notebook.addTab(tab,description[i])

		alpha=equation(self.path,"alpha_eq.inp","alpha_gen.omat","alpha.omat")
		alpha.set_default_value("1e7")
		alpha.set_ylabel("Absorption (m^{-1})")
		alpha.init()
		self.notebook.addTab(alpha,"Absorption")

		n=equation(self.path,"n_eq.inp","n_gen.omat","n.omat")
		n.set_default_value("3")
		n.set_ylabel("Refractive index (au)")
		n.init()
		self.notebook.addTab(n,"Refractive index")


		self.setLayout(self.main_vbox)
		self.win_list=windows()
		self.win_list.load()
		self.win_list.set_window(self,"materials_window")
		
		self.notebook.currentChanged.connect(self.changed_click)
 def test_solves_equation(self):
     """Solve y=1*(x**2) + 0*x - 4"""
     solution = {2, -2}  # {-2, 2} = {2, -2}
     result = equation(1, 0, -4)
     self.assertEqual(solution, result)
Exemple #14
0
# coding: utf-8
import numpy as np
import matplotlib.pylab as plt
import fixed_value as fv
import equation as eq
from mpl_toolkits.mplot3d import Axes3D

def teach_data(samplenumber, cont, randmax, randmin)

    teachx0 = (randmax - randmin) * np.random.rand(samplenumber) + randmin
    teachx1 = (randmax - randmin) * np.random.rand(samplenumber) + randmin
    teachf = eq.equation(teachx0, teachx1, cont)

    return teachf

# fixed_value = fv.fixed_value()
# samplenumber = fixed_value.test_samplenumber
# cont = fixed_value.cont
# randmax = fixed_value.randmax
# randmin = fixed_value.randmin
#
# teachx0 = (randmax - randmin) * np.random.rand(samplenumber) + randmin
# teachx1 = (randmax - randmin) * np.random.rand(samplenumber) + randmin
# # teachx0 = np.arange(-3,3,0.1)
# # teachx1 = np.arange(-3,3,0.1)
#
# teachf = eq.equation(teachx0, teachx1, cont)
#
# fig = plt.figure()
# ax = Axes3D(fig)
# ax.plot(teachx0, teachx1, teachf, marker="o", linestyle="none")
Exemple #15
0
def diagram_sum_3body(x, d):
    point=equation.equation(3.*x,'2D',20.,0.1,d)
    point.solve()
    g3=point.g3
    del point
    return 4.*pi/log(d**2 *2.*x) + g3