python-3.x - 用 pyomo 计算数值导数
问题描述
我需要在非线性 pyomo 约束的给定点重复计算导数。根据这篇文章,基本上有两种选择:一种符号方法(使用 sympy)和一种通过 Pyomo 生成的 NL 文件的数字方法。
我尝试了如下所示的符号方法:
def gradient(constr, variables):
grad_num = np.array([value(partial) for partial in
differentiate(constr.body, wrt_list=variables)])
if (not (is_leq_constr(constr))):
grad_num = -grad_num
return grad_num
原则上,这种方法是有效的。但是,在处理更大的问题时,函数调用需要很长时间,我希望数值方法更快。
这是真的?如果是这样,任何人都可以帮助我,将上述函数“翻译”为gjh_asl_json方法吗?我很感激任何提示。
解决方案
推荐阅读
- prometheus - 如何解决 Prometheus 配置错误:文件服务发现配置必须包含至少一个路径名
- swift - 以 JSON 格式获取 socket.io 数据
- excel - 将数据行复制到新位置时,数据被正确复制,但在数据行之间插入了空白行
- excel - RefreshAll 后 VBA 未按正确顺序计算
- haskell - Haskell:Desugaring State do notation
- ios - 将 UITbale 视图连接到 firebase 实时数据库的解包错误
- ionic-framework - 在屏幕外标签中初始化传单地图(当前不可见的离子幻灯片)
- javascript - 如何在实时搜索中使整行可点击
- c - 调用函数时元素消失 - LZW 压缩
- javascript - 如何正确显示我的 Knockout 应用程序的模板元素?