I am very new to coding and must solve this particular equation with python for a project. (It's not for credit. It's just for my understanding.) please note: I know how to solve the equation by hand and I don't need to learn the solution. I need to learn how to make my code work.
I cannot find the error in my code. I assume there is one because I keep getting the same error. Does anyone know how to fix this or to do it better?
Thank you very much for your help.
Below is the error and the code that I am using.
Error:
NotImplementedError: multiple generators [x, sin(x3)] No algorithms are implemented to solve equation x3 4x - 6sin(x**3) - 1 0
import numpy as np
import sympy as sy
x = sy.symbols("x", real=True)
u = sy.symbols("u", real=True)
u = x**3
eq1 = sy.Eq(u - 6*sy.sin(u) 10*x - 6*x -1, 0)
eq1
sol1 = sy.solve(eq1, x)
print(sol1)
CodePudding user response:
The solve
function is for finding closed form symbolic solutions of equations. This is your equation:
In [30]: eq1
Out[30]:
⎛ 3⎞ 3
-1 - 6⋅sin⎝x ⎠ 4⋅x x = 0
This is a transcendental equation and so it is very unlikely that any analytic expression exists for the solution.
If you want an approximate numeric solution then you can use nsolve e.g. the three solutions for this equation can be found like this:
In [33]: nsolve(eq1, x, 0.25)
Out[33]: 0.276389904495405
In [34]: nsolve(eq1, x, 0.75)
Out[34]: 0.739963760252268
In [35]: nsolve(eq1, x, 1.25)
Out[35]: 1.22805318567194
https://en.wikipedia.org/wiki/Transcendental_equation https://docs.sympy.org/latest/modules/solvers/solvers.html#sympy.solvers.solvers.nsolve