Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math as m
- # x^2 - e^(y/x) - y - 2x = 0
- precision = 0.0001
- def formula(x, y):
- return m.pow(x, 2) - m.pow(m.e, y / x) - y - 2 * x
- def derivative(x, y):
- return (2 * m.pow(x, 3) + m.pow(m.e, y / x) * y - 2 * m.pow(x, 2)) / (x * m.pow(m.e, y / x) + m.pow(x, 2))
- def secder(x, y):
- h = 0.0001
- return (derivative(x + h, y) - derivative(x, y)) / h
- def solution():
- miny, minx = 10000, 10000
- znak = "+"
- for x in range(115000, 120000): # вам нужно будет найти нормальные отрезки для циклов по х и у, прост на сайтике нарисуйте
- for y in range(-135000, -127000): # но он может не правильно нарисовать, гл крч
- if x != 0:
- try:
- if abs(formula(x / 100000, y / 100000)) < 0.0001 and abs(derivative(x / 100000, y / 100000)) < 0.001 and secder(x / 100000, y / 100000) >= 0:
- if miny > abs(y / 100000):
- if y < 0:
- znak = "-"
- else:
- znak = "+"
- miny = abs(y / 100000)
- minx = x / 100000
- except OverflowError:
- continue
- print("перебор")
- print("x equals to ", minx)
- print("y equals to ", -miny)
- print("formula: ", (formula(minx, -miny)))
- print("first derivative ", derivative(minx, -miny))
- print("second derivative", secder(minx, -miny))
- solution()
- def solution2():
- finx = 100000
- delta = precision / 3
- for x in range(0, 15000):
- x = x / 10000
- y, n = 1, 1000
- a, b = -2, 1.1
- for k in range(1, n + 1):
- if x != 0:
- try:
- alpha = (a + b) / 2 - delta
- beta = (a + b) / 2 + delta
- if abs(formula(x, alpha)) <= abs(formula(x, beta)):
- b = beta
- y = alpha
- else:
- a = alpha
- y = beta
- if (b - a) < precision:
- finx = x
- break
- except OverflowError:
- continue
- # print(finx, y)
- try:
- if abs(derivative(finx, y)) < 0.0001 and secder(finx, y) > 0 and abs(formula(finx, y))< 0.0001:
- ax = finx
- yx = y
- except OverflowError:
- continue
- print("\n\nполовинное деление")
- print("x equals to ", ax)
- print("y equals to ", yx)
- print("formula: ", (formula(ax, yx)))
- print("first derivative ", derivative(ax, yx))
- print("second derivative", secder(ax, yx))
- solution2()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement