Jan-08-2021, 02:56 PM
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 (
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
(I used the solver
I would really appreciate any help because I am a bit lost.
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
nonlinsolve
as 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