Reputation: 39
I have a system of 3 equations - 3 unknowns that I can solve if I know the values of the parameters (z,a). The issue is that I don't know them. Is it possible to write a code that given a guess for (z,a) finds (x,y,w) such that the system of equations is satisfied, while updating the guess for (z,a) - below I am fixing numbers for (z,a) but would like to confirm that. Also I need to make sure that x,y,w are between zero and one.
A sample of the code I am working on is below. Thanks for your help.
import scipy.optimize as so
import numpy as np
def test(variables,z,a): #Define function of variables and adjustable arg
x,y,w = variables #Declare variables
eq1 = x**a+y**2-1-z*10 #Equation to solve #1
eq2 = 2*x+1-w/a #Equation to solve #2
eq3 = x+y+w-1
return [eq1,eq2,eq3] #Return equation array
z,a = 1,1 #Ajustable parameter
initial = [0.1,0.2,0.5] #Initial condition list
sol = so.fsolve(test , initial, args = (z,a)) #Call fsolve
print(np.array(sol)) #Display sol
Upvotes: 0
Views: 145
Reputation: 736
You can create a list of guesses: guesses=[(1,1),(1,0),(0,1)]
for instance, and iterate through that list using a for loop.
initial = [0.1,0.2,0.5] #Initial condition list
guesses=[(1,1),(1,0),(0,1)]
for (z, a) in guesses:
sol = so.fsolve(test , initial, args = (z,a)) #Call fsolve
print(np.array(sol)) #Display sol
As for the bounds for x,y and w, I believe that it is not possible to add bounds with scipy.optimize.fsolve
. You can check scipy.optimize.minimize instead.
Upvotes: 1