python - 如何优化一组方程的变量?
问题描述
我有 6 个变量,我想根据 20 个方程估计它们的值(这些方程作为列表存储在 f0 中)。有人知道我可以使用 python 中的哪个库来估计这些变量吗?优化完成后,这就是我对 6 个变量的期望:
# expected value for x[0] = 2,
# expected value for x[1] = 0.002,
# expected value for x[2] = 4000,
# expected value for x[3] = 2,
# expected value for x[4] = 0.002,
# expected value for x[5] = 0.002
def func(x):
rl = [1, 5, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 150, 200, 250, 300, 350, 400]
vin = 20*[480]
ian = [22.381, 6.209, 3.4182, 2.0862, 1.7003, 1.5329, 1.4446, 1.3918, 1.3574, 1.3337, 1.3165,
1.3036, 1.2857, 1.2793, 1.2695, 1.2552, 1.2475, 1.2429, 1.2398, 1.2373]
f0 = []
for i in range(len(rl)):
f0.append((x[3]*x[2]*(376.99*1j*x[5] + x[4] + rl[i])/((x[3] + x[2])*(x[3]*x[2]/(x[3] + x[2]) + 376.99*1j*x[5] + x[4] + rl[i])) + 376.99*1j*x[1] + x[0])* ian[i] - vin[i])
return f0
我尝试使用 minimum_squares 如下所示,但结果有点偏离。谢谢!
res = least_squares(func, (0.1, 0.01, 350, 1, 1, 0.01), bounds = ((0,0,0,0,0,0), (2,0.5,5000,5,2,0.5)))
解决方案
推荐阅读
- json - 在最低级别将 JSON“解包”到 SQL Server 表中的最佳方法是什么?
- javascript - 如何为窗口轮播菜单设置动画?
- vim - Vim-Airline + 屏幕错误
- php - 如何从两个mysql表中打印出值
- awk - 将列匹配到一个单独的文件并将匹配项附加到文件
- stata - 如何在 Stata 中为双向图例添加超过 15 个系列?
- java - 我面临一个问题,即在回收站视图中设置数据我已经测试过数据来自 API
- r - 在 ggplot 中重新排序图例标签的困难
- python - 如果在某些时间/值之间,熊猫累积总和
- python - 在Python中找到所有n个正数加起来等于k的组合?