【发布时间】:2021-06-17 12:28:21
【问题描述】:
我正在尝试求解方程组。下面示例中的方程是拉格朗日函数(LDash 1 到 7)的一阶导数,我是用纸笔获得的。系统的解决方案应该给出最大值和最小值的候选者。
选择变量是X1, X2, LC, LA, s, u,而所有其他符号都是正实数的占位符。
脚本运行,但在我的控制台中没有显示任何内容。在整个SymPy documentationsolve 的示例中输出解决方案。您能帮我找出为什么它在下面的示例中不这样做吗?
我对 Python 完全陌生,所以请告诉我如何改进。谢谢!
# import stuff
from sympy.interactive import printing
printing.init_printing(use_latex=True)
from sympy import Function
from sympy.solvers import solve
import sympy as sp
X1, X2, LC, LA, s, u = sp.var('X_1, X_2, L_C, L_A, s, u', positive=True);
# import exogenous variables
a1, a2, a3, a4, S1, S2, S3, S4, p1, p2, p3, p4, fdash, vdash,f, v = sp.symbols('alpha_1, alpha_2, alpha_3, alpha_4, S_1, S_2, S_3, S_4, p_1, p_2, p_3, p_4, \hat{F}, \hat{V}, f, v', positive=True)
v0 = sp.symbols('v_0') # raw skill level
i = sp.symbols('\hat{\imath}') # children in the household - time endowment
I = sp.symbols('I') # household size and total time endowment
climate = sp.symbols('theta') # climate variable
capital = sp.symbols('K') # quasi fixed land and (non-human) capital
lam = sp.symbols('\lambda') # shadow prices (lagrange multiplier)
# pen-and-paper: derivatives of the Lagrange function w.r.t choice variables
LDash1 = a1/(X1-S1)-lam*p1 # L' w.r.t X1
LDash2 = a2/(X2-S2)-lam*p2 # L' w.r.t X2
LDash3 = -a3/(I-i-LA-S3) + 2*lam*p3 + lam*p1*fdash # L' w.r.t LA
LDash4 = -1/(i-LC) - a4/(i-LC-S4) + 2*lam*p4 + lam*p1*fdash*(-s*u + s*v +(1-s)*v0) # L' w.r.t LC
LDash5 = lam*p1*fdash *(-u*LC + v*LC - v0*LC) # L' w.r.t. s
LDash6 = lam*p1*fdash *(-s*LC + s*vdash*LC) # L' w.r.t u
LDash7 = p1*X1 + p2*X2 -2*p3*I + 2*p3*i + 2*p3*LA -2*p4*i + 2*p4*LC + p1*f # L' w.r.t lambda
solve((LDash1,LDash2, LDash3, LDash4, LDash5, LDash6, LDash7), (X1,X2,LA,LC,u,s))
【问题讨论】:
-
为什么会显示什么?你没有
print任何东西,sympy.solvers.solve大概也没有输出任何东西,所以你最终没有输出
标签: python sympy mathematical-optimization