主题:求解一次函数
liwanming_2004
[专家分:0] 发布于 2007-07-08 10:47:00
我想解这个方程:10.625*(x^0.41)=exp(5.78-21.78*x)
求x的值
回复列表 (共3个回复)
沙发
老大徒伤悲 [专家分:29120] 发布于 2007-07-08 12:00:00
别到处发了!
Dim jie As Boolean, epsl As Single
Private Sub Form_Click()
Dim x1 As Single, x2 As Single, y1 As Single, y2 As Single, x As Single, y As Single
epsl = Val(InputBox("请输入求解的允许误差", 0.00001))
jie = False
Do
x1 = Val(InputBox("请输入求解的下限"))
x2 = Val(InputBox("请输入求解的上限"))
y1 = hanshu(x1)
If jie Then Exit Sub
y2 = hanshu(x2)
If jie Then Exit Sub
If y1 * y2 < 0 Then
MsgBox "上下限确定成功", vbInformation + vbOKOnly
Exit Do
Else
MsgBox "上下限确定错误,重新确定!", vbExclamation + vbOKOnly
End If
Loop
Do Until jie
x = x1 - y1 * (x2 - x1) / (y2 - y1)
y = hanshu(x)
If jie Then Exit Sub
If y * y1 > 0 Then
x1 = x
y1 = y
Else
x2 = x
y2 = y
End If
Loop
End Sub
Private Function hanshu(x As Single) As Single
hanshu = 10.625 * (x ^ 0.41) - Exp(5.78 - 21.78 * x)
If Abs(hanshu) < epsl Then
MsgBox "求解成功!" & vbCrLf & "近似数值解为:" & x & vbCrLf & "函数误差为:" & hanshu
jie = True
End If
End Function
试试看。解大约为0.1883085,方程两边的结果大约为 5.35828250912293 5.35826843651022
如果你想用来解别的方程,请更换 hanshu = 10.625 * (x ^ 0.41) - Exp(5.78 - 21.78 * x)这一行。
板凳
abcwuhang [专家分:1840] 发布于 2007-07-10 14:28:00
???怎么把VB程序贴到这里来了??
3 楼
qqym710 [专家分:140] 发布于 2007-07-10 23:59:00
牛哥
我来回复