I wrote a code and I need some help about implementing an optmization method, maybe with scipy. If you can note below I have a variable "pD" that I need to vary in order to find a result for "abs(mFmin[i][j] - mReg[i][j]) > 1". mFmin, mReg and all the other calculations inside this while depends on "pD"
I wrote a poor code, just for testing, in order to vary "pD" comparing mFmin and mReg, but it's too slow and doesn't matter if I raise the error or not, that little code sucks.
I'm searching some optmization code in scipy library, but I can't see where I can implement this with my code. I think it's simples solving, but I have nobody to exchange ideas...
Note: pD is a matrix
Below, I attached the main part of the code:
for i in range(0,int(x)):
for j in range(0,n):
curso[i] = i*passo
curso[0] = 0
pD[i][j] = pZref
mFmin[i][j] = 0
mReg[i][j] = gref
# my doubt starts here
while abs(mFmin[i][j] - mReg[i][j]) > 1:
if mFmin[i][j] < mReg[i][j]:
pD[i][j] = pD[i][j] + 0.0001
else:
pD[i][j] = pD[i][j] - 0.0001
pZaux[i][j] = pE_*sqrt((pow(pZref/pE_,2)-pow(pA/pE_,2))*pow(mFmin[i][j]/gref,2)+pow(pA/pE_,2))
vD[i][j] = pE_*vE_/pD[i][j]
if pD[i][j]/pE_ > RPcr:
psiR[i][j] = sqrt(pow(pD[i][j]/pE_,2/kappa)-pow(pD[i][j]/pE_,(kappa+1)/kappa))
else:
psiR[i][j] = psicrR
if pZaux[i][j]/pD[i][j] > RPcr:
psiF[i][j] = sqrt((2*kappa/(kappa-1))*(pow(pZaux[i][j]/pD[i][j],2/kappa)-pow(pZaux[i][j]/pD[i][j],(kappa+1)/kappa)))
else:
psiF[i][j] = psicrF
mFmin[i][j] = 3600*psiF[i][j]*kmin*(fmin[j]/1000000)*sqrt(pD[i][j]*100000/vD[i][j])
mReg[i][j] = 3600*psiR[i][j]*alpha*(fV[i][j]/1000000)*sqrt(2*kappa/(kappa-1)*(pE_*100000/vE_))
Thanks for reading!
MRM