0

I work with sympy and I have three symbolic variables (y , p_s , p_h). I want to solve the equation in terms of p_s and p_h, solving y in terms of p_s and p_h. My code is as follows when I run it, give me an empty list output. I don't know what is wrong! Could you help me?!

Note: My parameters come from a class HH.

def s_r():
        
    α ,  π , τ = hh.α ,  hh.π , hh.τ
    y , p_s = sympy.symbols('y p_s')
        
    return ((1-α)/p_s)*((y/(1+π))+τ)
    
def c_r():
        
    α , π , τ = hh.α , hh.π , hh.τ
    y = sympy.symbols('y')
        
    return α*((y/(1+π))+τ)
    
    
def c0_o():
        
    π , θ , h0 , τ  = hh.π , hh.θ , hh.h0 , hh.τ 
    y , p_h = sympy.symbols('y p_h')
        
    return  (y/(1+π))-((p_h*θ*h0**2)/(1+π))+τ


def func():
    
    α , h0  = hh.α , hh.h0 
    y , p_h , p_s = sympy.symbols('y p_h p_s')

    expression1 = (((c_r()**α)*(s_r()**(1-α))) - ((c0_o()**α)*(h0**(1-α))))
    lam1 = lambdify(y, expression1 , modules=['numpy'])

    y00 = solve(lam1(y), y,  dict = True)
    
    return y00

func()  

for more details, I want the "solve" to set equal to zero the "expression1" and give me an equation for y in terms of p_s and p_h.

dm2
  • 4,053
  • 3
  • 17
  • 28
NaTa
  • 1
  • 1
  • I really think it depends on your `α, π, ...`. For example, I've tried by setting `α = 2, π = 3, τ = 4, θ = 5, h0 = 6` and it computed two solutions. I've tried to set symbols instead of numbers and it raises a NotImplementedError. If you want more help, I believe you'll have to provide more details on the nature of these parameters. – Davide_sd Feb 27 '23 at 08:04
  • "My parameters come from a class HH." So your code is not reproducible. – Corralien Feb 27 '23 at 08:04
  • I've looked closely at your expression, I don't think there is an analytical solution. If I were you I'd solve it numerically... – Davide_sd Feb 27 '23 at 08:31
  • thank you very much. my parameters are as follows : θ = 0.02, β = 0.99, α = 0.7, τ = 0.02, π = 0.05, H_O = 200, h0 = 1, y_min = 0.01, y_max = 1, y_size = 50. I can not change them because other parts of my issue do not work. – NaTa Feb 27 '23 at 08:32
  • Hi, @NargesTahmasebi, we welcome you to SO. As we appreciate your question, please be advice to always provide a [https://stackoverflow.com/help/minimal-reproducible-example]( minimal reproducible example) . Also, you need to pin point the actual problem for the SO community has an easier time in helping you. – MBV Feb 27 '23 at 20:51

0 Answers0