正在阅读:VB数学实例:巧用递归法解不定方程VB数学实例:巧用递归法解不定方程

2004-02-14 09:34 出处:CSDN 作者:northwolves 责任编辑:linjixiong

  多元一次方程往往采用循环求解。笔者在与网友们讨论一个问题(http://expert.csdn.net/Expert/topic/2607/2607772.xml?temp=.7494928)过程中,琢磨出一种算法,采  用递归进行多元一次方程的求解。并将解分为整数解和 非负整数解两种情况,请大家指教。

  Private Sub Command1_Click() '演示求X1+X2+X3+X4+X5=10整数解
  Text1.Text = ""
  Dim answer As String
  answer = GETRESULT(5, 10, True) '赋值
  Dim temp
  temp = Split(answer, vbCrLf)
  For i = 0 To UBound(temp)
  temp(i) = "解" & i + 1 & ":" & vbTab & temp(i) ' add index
  Next
  answer = Join(temp, vbCrLf)
  Text1.Text = "方程 X1+X2+X3+X4+X5=10 共有 " & UBound(temp) + 1 & " 个整数解:" & vbCrLf & answer 'show all answer in textbox

  End Sub
  Private Sub Command2_Click() '演示求X1+X2+X3+X4+X5=10非负整数解
  Text1.Text = ""
  Dim answer As String

  answer = GETRESULT(5, 10, False) '赋值
  Dim temp
  temp = Split(answer, vbCrLf)
  For i = 0 To UBound(temp)
  temp(i) = "解" & i + 1 & ":" & vbTab & temp(i) 'add index
  Next
  answer = Join(temp, vbCrLf)

察看评论详细内容 我要发表评论
作者笔名简短内容 发表时间
:
键盘也能翻页,试试“← →”键

相关文章

关注我们

最新资讯离线随时看 聊天吐槽赢奖品