Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
499 views
in Technique[技术] by (71.8m points)

python - Sympy nonlinsolve does not return an explicit solution

This is my first attempt at symbolic solving in Python and I would need some help. My aim is to get explicit solutions for my variables in terms of the parameters (tetaL, tetaH, Re, Rl, E).

So far, I only got solutions for the variables in function of the other unknow variables, instead of solutions depending on parameters only. For instance, i get the solution for Sb (SbSol) in terms of c2b, c1 which are unknown variables I am trying to solve for.

(I used the solver nonlinsolveas my equations are non-linear.)

I would really appreciate any help because I am a bit lost.

import sympy
import numpy as np
from sympy import *

#symbol declaration (variables to solve for + parameters)
teta, tetaL, tetaH, Re, Rl, E,  Sb, D, c, K, Lb, Lf, Sf, c1, c2, c1b, c2b, exoPstar = ( 
    symbols('teta tetaL tetaH Re, Rl E  Sb D, c K Lb Lf Sf c1 c2 c1b c2b exoPstar') )

exoPstar = Re/Rl
tetaTreshDec = (Re*(Lb + Sb * exoPstar) - c * exoPstar * D) / c*D*(Re- exoPstar)
prNoDefDec = (tetaTreshDec + 1)/2
UDec = prNoDefDec * ( teta * log(c1) + (1-teta) * log(c2)) + (1-prNoDefDec) * ( teta * log(c1b) + (1-teta) * log(c2b))

#the system of equations
focBkSdec = diff(UDec, Sb)
focBkCdec = diff(UDec, c)
focHHdec = diff(UDec, D)
Eq0 = teta - ( 1/2 * (tetaL + tetaH))
Eq1 = E - (D + K)
Eq2 = D - (Lb + Sb)
Eq3 = Lf - (Rl/(Re- Rl) * D * c)
Eq4 = Sf - (E - D - Lf)
Eq5 = c1 - c*D
Eq6 = c2 - (((Sb + Sf)* Re + (Lb- teta*c*D)*Rl + Lf*Rl) / (1- teta))
Eq7 = c1b - (Lb + Lf)
Eq8 = c2b - (c1b + (Sb+Sf)*Re /(1- teta))

#solving in function of the parameters (tetaL, tetaH, Re, Rl, E)
(SbSol, cSol, DSol, KSol, LbSol, LfSol, SfSol, c1Sol, c2Sol, c1bSol, c2bSol), = list(nonlinsolve([focBkSdec,focHHdec, focBkCdec, Eq0, Eq1, Eq2, Eq3, Eq4, Eq5, Eq6, Eq7, Eq8],[Sb, c, D, K, Lb, Lf, Sf, c1, c2, c1b, c2b]))
SbSol

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...