A given equation depends on an unknown variable (y
) and a set of parameters. I would like to numerically solve for y
, given each element of a grid with values of the parameters.
A simplified example of my attempted solution is as follows (y
is the unknown variable and x
is the parameter):
import numpy as np
import sympy as sp
x,y=sp.symbols('x y')
xgrid=np.arange(1,6)
f = sp.lambdify(x,sp.nsolve(x**2+y,y,2),"numpy")
print(f(xgrid))
However, I am getting the following error:
expected a one-dimensional and numerical function.
I was expecting to receive a vector with y=-x**2
for every value x
in xgrid
.
Please notice that the actual function of interest is not y=-x**2
as in the example, but a non-linear function that is implicit in both x
in y
.
Am I forced to do a loop over each value in the grid
, or can I still use lambdify
somehow? Thanks in advance!