In: Computer Science
What is the python code to solve this type of nonlinear equation in jupyter notebook
16cos2x+16sin2x-40.1cosx+2.3sinx+16.223=0
Please show the code clearly.
The equation contains only one symbol 'x' . The values of x can be obtained for this equation using SymPy's solve() method. SymPy is a module that works with symbolic expression. And the solve() method will solve the expression you give into it.
First, we must import the SymPy module. We are going to be using only 4 of the functions in SymPy : solve(), symbols(), cos(), sin(). So, import only those function:
from sympy import symbols, solve, cos, sin
Then , mention that 'x' is going to be a symbol in our expression. use the symbol() method
x = symbols('x')
Then, define the expression itself.
expr = 16*(cos(x))**2 + 16*(sin(x))**2 - 40.1*cos(x) + 2.3*sin(x) + 16.223
Then, solve the expressions using solve() method. It will return all the values for x for which the equation will be satisfied.
solution = solve(expr)