Python Forum

Full Version: How to find a zero of this function?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have many input parameters and a function in the end of the following code. The unknown parameter is the "Fi". I tried to find a zero of the last function, but I could make only an iteration for this problem. Can you please help me to find a better function for determining "Fi"? Thank you :-)
n=7
di=[4,2,1,0.5,0.25,0.125,0.0625]
beta_i=np.array([0.606,0.606,0.575,0.568,0.563,0.541,0.506],np.float32)
fi_i=np.array([0.535,0.546,0.525,0.469,0.513,0.500,0.485],np.float32)
yi=np.array([0.022,0.201,0.096,0.063,0.315,0.249,0.054],np.float32)
K=4.10
aij=0.712
bij=0.651
p01=0
p02=(1-beta_i[1]+bij*beta_i[1]*(1-1/beta_i[0]))*yi[0]
p03=(1-beta_i[2]+bij*beta_i[2]*(1-1/beta_i[1]))*yi[1]
p04=(1-beta_i[3]+bij*beta_i[3]*(1-1/beta_i[2]))*yi[2]
p05=(1-beta_i[4]+bij*beta_i[4]*(1-1/beta_i[3]))*yi[3]
p06=(1-beta_i[5]+bij*beta_i[5]*(1-1/beta_i[4]))*yi[4]
p07=(1-beta_i[6]+bij*beta_i[6]*(1-1/beta_i[5]))*yi[5]
q01=(1-(aij*(beta_i[0]/beta_i[1])))*yi[1]
q02=(1-(aij*(beta_i[1]/beta_i[2])))*yi[2]
q03=(1-(aij*(beta_i[2]/beta_i[3])))*yi[3]
q04=(1-(aij*(beta_i[3]/beta_i[4])))*yi[4]
q05=(1-(aij*(beta_i[4]/beta_i[5])))*yi[5]
q06=(1-(aij*(beta_i[5]/beta_i[6])))*yi[6]
q07=0
P=[p01,p02,p03,p04,p05,p06,p07]
Q=[q01,q02,q03,q04,q05,q06,q07]
sump1=0
sump2=0
sump3=np.sum(P[0:1])
sump4=np.sum(P[0:2])
sump5=np.sum(P[0:3])
sump6=np.sum(P[0:4])
sump7=np.sum(P[0:5])
sumq1=np.sum(Q[1:6])
sumq2=np.sum(Q[2:6])
sumq3=np.sum(Q[3:6])
sumq4=np.sum(Q[4:6])
sumq5=np.sum(Q[5:6])
sumq6=0
sumq7=0
gamma_1=beta_i[0]/(1-sumq1)
gamma_2=beta_i[1]/(1-sumq2)
gamma_3=beta_i[2]/(1-sump3-sumq3)
gamma_4=beta_i[3]/(1-sump4-sumq4)
gamma_5=beta_i[4]/(1-sump5-sumq5)
gamma_6=beta_i[5]/(1-sump6-sumq6)
gamma_7=beta_i[6]/(1-sump7-sumq7)
gamma_i=np.array([gamma_1,gamma_2,gamma_3,gamma_4,gamma_5,gamma_6,gamma_7],np.float32)
def error(Fi):
    return (K-((yi/beta_i)/(1/Fi-1/gamma_i)).sum())
print(error(0.482))
(Jan-13-2020, 08:54 AM)kkitti93 Wrote: [ -> ]I have many input parameters and a function in the end of the following code. The unknown parameter is the "Fi". I tried to find a zero of the last function, but I could make only an iteration for this problem. Can you please help me to find a better function for determining "Fi"? Thank you :-)

Can you quantify better, please?
Do you want something faster or do you need it to be simpler code, or do you want more pythonic code?
It's hard to tell.
Also, please describe your math.
Sure, Im sorry, Im just a beginner, I know my description is not the best, I'll try it again:
I think it will be the best way if I show you the original mathematical problem. Please find the equations here:
https://www.cnczone.com/forums/attachmen...124.attach
The final equation is the 4th one, where the unknown parameter is the Fi (Ø). I can get all of the other parameters experimentally.
So, I would like to calculate this parameter (Ø), but I can only get it by an iterative way with this code. So I try some values for the Fi, and I get the difference between the real value and mine (error). So I am wondering if there is a way to find a function to calculate the precise value of the Fi.

Thank you for your help!
Much clearer, thank you. This looks like fun. I'll take a crack at it tonight or tomorrow.
Thank you very much, this is a great help for me!