I am trying to solve an equation similar to the simplified example
x / x.sum - b = 0
where x is an n-dimensional vector. Since one can multiply x with any constant without changing the equation, the solution is up to a normalization. Because of this, I try to add an n+1-th equation, such that
x.sum() - 1 = 0
My attempts to put this in code have all produced errors. This is the most recent minimal example:
import numpy as np
from scipy.optimize import fsolve
n = 1000
a = np.ones(n)
b = np.random.rand(n)
def f(x):
return (x / (x.sum() + 1) - b, x.sum() - 1)
x = fsolve(f, a)
print(x)
Is this possible with fsolve? What is the correct code?
Further context: The function is a simplified example. The actual function that I attempt to solve is non-linear and complicated. I can proof that a solution for x exists and that it is unique up to scaling.