excel 批量“规划求解”(其它方法也行)解四元一次方程组
发布网友
发布时间:2022-05-06 10:05
我来回答
共2个回答
热心网友
时间:2023-10-09 02:32
Sub test()
Dim MaxRow As Integer, i As Integer
Dim StrFormula1 As String, StrFormula2 As String
MaxRow = Range("A65536").End(xlUp).Row
For i = 2 To MaxRow
Range("I2") = "=SUMPRODUCT(E2:G2,OFFSET(J1:L1," & i - 1 & ",))"
Range("I3") = "=SUMPRODUCT(E3:G3,OFFSET(J1:L1," & i - 1 & ",))"
Range("I4") = "=SUM(OFFSET(J1:L1," & i - 1 & ",))"
SolverReset
SolverOk SetCell:="$I$4", MaxMinVal:=3, ValueOf:="1", byChange:=Replace("$J$2:$L$2", "2", i)
SolverAdd CellRef:="$I$2", Relation:=2, formulaText:="$A$" & i
SolverAdd CellRef:="$I$3", Relation:=2, formulaText:="$B$" & i
SolverSolve
Next
End Sub
先在模块中引用 规划求解 工具 引用 点选 SOLVER
热心网友
时间:2023-10-09 02:32
用VB的循环嵌套函数可以解决。
for next语句
if then语句
如果可以改变,把AB列的数据都放在一列会更容易实现,会有很多解。