0

I have approximations for a series of correlation functions that are described by two variables, theta and Dw. The correlation functions are incorporated into a larger equation, where there are 4 additional variables. These variables are: gyroI, gyroS, r, and dec. These 4 variables are all measurable quantities that I have. I wrote this to a function and plotted the dependence of the single output value as a dependence of thetaand Dw.

import numpy as np
import matplotlib.pyplot as plt

N = 100
theta = np.linspace(np.pi/180, np.pi/30, N)
Dw = np.linspace(10, 200, N*2)
theta, Dw = np.meshgrid(theta, Dw)

def relax(theta, Dw, gyroI, gyroS, dist, decI):
    c = np.cos(theta)
    X0 = (1/20)*(c*(1+c)*(9*(c**2)-1)+4)-((1/4)*(c**2)*((1+c)**2))
    X1 = (1/10)*(1-c)*((2+c)*(1+(3*c**2))+(3*c))
    X2 = (1/40)*((1-c)**2)*((3*c**2)+(9*c)+8)
    t0 = (1/(Dw*X0))*((((c**2)*((1+c)**2))/(2*(c-1)))*(np.log(((1+c)/2)-((1-c)/2)))+(((1-c)*(2-c-(9*c**2)-(7*c**3)))/60))
    t1 = (((1-c)**2)*(9+(32*c)+(44*c**2)+(20*c**3)))/(120*Dw*X1)
    t2 = (((1-c)**3)*(8+(12*c)+(5*c**2)))/(240*Dw*X2)
    mu = (2*np.pi*122000)
    R2 = ((mu)*((gyroS/gyroI)/(dist**3))**2)*(((2*X2*t2)/(5*(1+(decI**2)*(t2**2))))+((2*X1*t1)/(5*(1+(decI**2)*(t1**2))))+((X0*t0)/(5*(1+(decI**2)*(t0**2)))))
    return R2

Z = 1/relax(theta, Dw, 599.7690768e6, 60.825978e6, 1.04, 92000.0)/1e3
cmap = plt.get_cmap('jet_r')
CT =plt.contourf(np.degrees(theta), Dw, np.log10(Z), levels= 15 ,cmap=cmap)
plt.colorbar(CT)
plt.xlabel('theta')
plt.ylabel('Dw')
plt.show()

Which produces the plot:

Plot1

What I would like to find is a way to have a function that takes in a single scalar value (in this case a single value of R2) and returns all values of theta and Dw that describe that value. Such that I am able effectively find all values that describe the dashed lines in the second figure within a range and resolution that I can define.

example plot 2 - dashed values of interest: example plot 2 - dashed values of interest

How can I leverage python to use the defined equations in the function for a single value of R2 and return the corresponding theta and Dw values that describe it?

rfkortekaas
  • 6,049
  • 2
  • 27
  • 34
  • It appears that you want to solve the 'inverse problem': given R2, find Theta & Dw that satisfy a (nonlinear) function of the form `R2 = f(Theta, Dw)`. If my understanding of the problem is correct, you will need root finding algorithms such as here: https://docs.scipy.org/doc/scipy/reference/optimize.html#root-finding. There could be multiple (Theta, Dw) solutions for a single value of R2 and finding all of them would be quite difficult. See if arc length continuation methods can be useful. – Ankur Jan 21 '21 at 05:26
  • @Ankur If I want to find e.g. R2 = 6, would finding the roots of where `R2 = f(theta, Dw)+6 ` be an approximate way to go? – cborcik Jan 22 '21 at 16:45
  • I think you will need to solve `6 = f(theta, dw)` to get values of `theta` and `dw` that satisfy the equation. – Ankur Jan 22 '21 at 18:58

0 Answers0