python - Rearrange equations for solver -
I'm looking to find a normal python method, to manipulate the way to solve questions in the equations . For example:
There may be some constants to get started
e1, e2 = 0.58,0.62 ma1, ma2 = 0.85, 1.15 mw = 0.8 CPA, CPW = 1.023,4.193 DBA, DBR = 0.0,25.0
and a group of equations (read here for readability instead of solver)
Q = e1 * ma1 * CPA * (tw1-dba) Q = MA1 * CPA * (DBS-DBA) Q = MW * CPW * (BB-2-B2) QE = E2 * M2 * CPA * (DBR-B2) Q = MA2 * CPA * (DBR-DBO) This leaves 5 unknown, so the system can probably be sorted out.
Q, dbo, dBR, tw1, tw2
The actual systems are non-linear and more complex.
I have already solved this simple example, delphi, sage ... so I am not looking for a solution.
The equations are typed directly into the text editor and I want a dragon program that gives me an array of unknown and protection functions.
y = Mysolver.fsolve (f, x)
So, for example above
x = [Q, dbo, dbr, tw1, tw2] f = [q-e1 * m1 * cpa * (b1-dba), q-m1 * cpa * (dbs-dba), q-mw * cpw * (B1-B2), Q-A2 * Ma 2 * CPA * (DBR -TV2), Q-M2 * CPA * (DBR-DBO)]
I do not know how to remove unknown and create error functions.
I have tried the compile.parse () function and it seems to give a structured breakdown.
Can someone give some ideas on the best idea.
Actually, I have implemented the same thing in Python I am from Eureka and other programs mentioned by you I'm also familiar. You can see my implementation at xyzsolve.appspot.com (sorry for the shameless plug) Implementation is in all python I iterations will be run via code:
Change # 0: Each variable in the equation To replace a simple search with and replace the variable with its value. For example, x * y 1.1 * 2.2 will be formed if the values of x and y are 1.1 and 2.2. After getting the transformed string, you can simply use eval and put your value in residual (or your white vector). Scipy's fsolve / fmin function lets you pass extra logic in your remaining function, so that means use In the index of each of the named variables, a dictionary should have something like '{x': 0, 'y': 1} in your dictionary and then you can do only one search and replace it for each equation. It works, but at a very slow rate when you have to search the residual function every time.
Change # 1: Do the same as repetition # 0, except the variable with the X array element, then 'Y' will become 'x [1]' in fact you generate all this one string function To do; Something looks like "Df F (X): Returns X [0] + X [1], X [0] - X [1]". Then you can use the exec function in Fthin to create a function to pass fsolve / fmin. There is no motion hit and you can stop at this point if your equation is in the form of valid python syntax, if you want to support the more comprehensive equation input format, then you can not do much with this approach.
Change # 2: Apply a custom laser and parser It seems not as hard to do as I used for lexer. I used a recursive original parser to parse each equation Not too difficult, 100 or so lines of code) This gives you complete flexibility with the equation format. I just keep the stability of the variable, constants that are in each side of the equation in different lists like parser parse equation, it creates an equation string which looks like 'var_000 + var_001 * var_002' and so on. . Finally I just change 'var_000' from the x vector with the appropriate indicator then 'var_000' 'x [0]' and so on. If you want you can make an AST and make more sophisticated changes but I have stopped here.
Finally, you can also consider the types of input equations. There are quite a few non-linear non-linear equations that will not solve with FSOLV (this uses the Minpack Hybrids). You probably also need to input initial estimates
I would be interested in hearing if there are other alternative ways of doing this.
Comments
Post a Comment