Note: I originally had chi = 1 but I've changed it to chi = 0 (This is the simpler case).
My equations f(x,y) and g(x,y) come from the following code:
import numpy as np
from pylab import *
def stress(X,Y):
chi = 0
F = 1
a = 1
c = (1.0*a)/(np.sqrt(np.power(X,2)+np.power(Y,2))*1.0)
A = 0.5*(1 - c**2. + (1 - 4*c**2 + 3*c**4.)*np.cos(2*np.arctan(Y/X)))
B = 0.5*(1 - c**2. - (1 - 4*c**2 + 3*c**4.)*np.cos(2*np.arctan(Y/X)))
C = 0.5*(1 + c**2. - (1 + 3*c**4.)*np.cos(2*np.arctan(Y/X)))
D = 0.5*(1 + c**2. + (1 + 3*c**4.)*np.cos(2*np.arctan(Y/X)))
E = 0.5*((1 + 2*c**2. - 3*c**4.)*np.sin(2*np.arctan(Y/X)))
f = 1.0*F*c**2 + (A-1.0*chi*B) # Radial stress
g = -1.*F*c**2 + (C - 1.0*chi*D) # Tangential stress
return f,g
def f(X,Y):
return stress(X,Y)[0]
def g(X,Y):
return stress(X,Y)[1]
def find_points(X_max,Y_max,X_steps,Y_steps):
Xs = np.linspace(-X_max,X_max,X_steps)
Ys = np.linspace(-Y_max,Y_max,Y_steps)
radials = f(Xs,Ys)
tangentials = g(Xs,Ys)
return radials, tangentials
find_points(10,10,100,100)
This returns arrays of values for f and g.
I would like to find all of the (X,Y) ordered pairs where both f(X,Y) = 0 and g(X,Y) = 0. I was looking at different scipy packages and I couldn't find anything that seem to work for a multi-variable function like this. Also, my answers right now are being returned in arrays, so could I use something like np.where()? The problem with this is that because I'm storing exact values, I don't necessarily ever see f(x,y) or g(x,y) explicitly equal zero. My end goal is to plot these points. Also, does what I did so far make sense with the Xs and Ys as linspaces over these ranges?
Thank you
Update: I went back and wrote up a little script using a guideline I found on a somewhat similar question see This link. I used scipy.optimize.
from scipy import optimize
def equations(p):
X, Y = p
a = 1
F = 1
chi = 0
c = (1.0*a)/(np.sqrt(np.power(X,2)+np.power(Y,2))*1.0)
A = 0.5*(1 - c**2. + (1 - 4*c**2 + 3*c**4.)*np.cos(2*np.arctan(Y/X)))
B = 0.5*(1 - c**2. - (1 - 4*c**2 + 3*c**4.)*np.cos(2*np.arctan(Y/X)))
C = 0.5*(1 + c**2. - (1 + 3*c**4.)*np.cos(2*np.arctan(Y/X)))
D = 0.5*(1 + c**2. + (1 + 3*c**4.)*np.cos(2*np.arctan(Y/X)))
f = 1.0*F*c**2 + (A-1.0*chi*B) # Radial stress
g = -1.*F*c**2 + (C - 1.0*chi*D) # Tangential stress
return (f,g)
X, Y = optimize.fsolve(equations, (1, 1))
print equations((X, Y))
This requires me to put in different initial guesses to get different (X,Y) roots. It would be awesome if somehow I could solve all of the solutions. Also, the answers I'm getting seem kind of off. Thanks again.
Note: The original equations, before I converted them to Cartesian coordinates, were as follows:
def stress(R,theta):
chi = 0
F = 1
a = 1
c = (1.0*a)/(R*1.0)
A = 0.5*(1 - c**2. + (1 - 4*c**2 + 3*c**4.)*np.cos(2*theta))
B = 0.5*(1 - c**2. - (1 - 4*c**2 + 3*c**4.)*np.cos(2*theta))
C = 0.5*(1 + c**2. - (1 + 3*c**4.)*np.cos(2*theta))
D = 0.5*(1 + c**2. + (1 + 3*c**4.)*np.cos(2*theta))
E = 0.5*((1 + 2*c**2. - 3*c**4.)*np.sin(2*theta))
f = 1.0*F*c**2. + (A-1.0*chi*B) # Radial stress
g = -1.0*F*c**2. + (C-1.0*chi*D) # Tangential stress
return f,g
Maybe this will help sort out some of the confusion with the arctan(Y/X) aspect of the equation.