(.env) boris@UbuntuLTS:~/CURVE$ cat solveSci3.py
import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import fsolve
func = lambda x : (x*np.cos(x)-(1-x)**(0.5))
# Plot it
x = np.linspace(-5,1,100 )
plt.plot(x, func(x))
plt.xlabel("x")
plt.ylabel("expression value")
plt.grid()
plt.draw()
# Use the numerical solver to find the roots
x_initial_guess = -5
x_solution = fsolve(func, x_initial_guess)
print("The solution is x = %f" % x_solution)
print("at which the value of the expression is %f" % func(x_solution))
x_initial_guess = -3
x_solution = fsolve(func, x_initial_guess)
print("The solution is x = %f" % x_solution)
print("at which the value of the expression is %f" % func(x_solution))
x_initial_guess = 0
x_solution = fsolve(func, x_initial_guess)
print("The solution is x = %f" % x_solution)
print("at which the value of the expression is %f" % func(x_solution))
plt.show()
(.env) boris@UbuntuLTS:~/CURVE$ python3 solveSci3.py
The solution is x = -4.132124
at which the value of the expression is -0.000000
The solution is x = -2.435660
at which the value of the expression is -0.000000
The solution is x = 0.710065
at which the value of the expression is 0.000000
Смотри окончательную версию кода https://informatics-ege.blogspot.com/2022/10/solving-one-transcendental-equation-via.html
Как чистая математика решает трансцендентные уравнения без библиотек типа Scipy (Python for instance) ? От курса Вычислительной математики университета лично у меня остались смутные и нудные воспоминания.