'Optimization of Non-linear Equation using Scipy Solver

import numpy as np
import sys
import pandas as pd
from scipy.optimize import *
import matplotlib.pylab as plot

SigG = 162.4
M2 = 30
SigS = 111.7
Rmv = 26
kN2E6 = 6.13

func = lambda SigA : 1-(((SigA/SigG)**M2) + (((SigA/(kN2E6+(10.0**-23))) + SigS) / (Rmv + SigS))**2)
SigAinitial_guess = [0,162.4]
Solution = fsolve(func,SigAinitial_guess)
Solution[0]
print(repr(Solution[0]))

I have an issue with optimizing the above equation mentioned in the code. I need to find out SigA from the equation and the total equation must be equal to one.

I have already implemented the same using Excel solver and those are the exact output values of SigA and it satisfied with our experiment. Now, I'm trying to implement the same using Python.

The problem here is I have different kN2E6 values. From those values, if I take 4.608 I'm getting the exact output in Excel. If I take the values from 6.136 to the rest values I'm getting an error and I have mentioned it below for both kN2E6 values.

For kN2E6 = 6.136

runfile('C:/Users/e1110066/.spyder-py3/unbenannt0.py', wdir='C:/Users/e1110066/.spyder-py3')
-233.46921625832516
C:/Users/e1110066/.spyder-py3/unbenannt0.py:14: RuntimeWarning: overflow encountered in power
  func = lambda SigA : 1-(((SigA/SigG)**M2) + (((SigA/(kN2E6+(10.0**-23))) + SigS) / (Rmv + SigS))**2)

For kN2E6 = 4.608

runfile('C:/Users/e1110066/.spyder-py3/unbenannt0.py', wdir='C:/Users/e1110066/.spyder-py3')
119.77114094526229

I have taken my SigAinitial_guess = [0,162.4], because my output of SigA should be in between (0,162.4).



Solution 1:[1]

That's a very bad location for your data file in the first place. You are referring to the file in the project folder and that's bad. The way this should work is that you place the source data file in the project folder and then, when you build, that file is copied to the output folder. It is that copy that your application uses when it runs. That means that you can make as much of a mess of the copy as you want while testing as you will always have the original source file to go back to. When you want to reset your test data file, you simply create a new copy and overwrite the existing one. When you're ready to deploy your app, a copy of the clean source file will be created in the Release output folder and you're good to go. If you do it that way then you can simply use "|DataDirectory|" for the folder path in your connection string and it will just work:

con.ConnectionString = "Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\keyboardpartpickerDB.mdf;Integrated Security=True"

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1