vb求cos(x)的近似值,cos(x)=1-x^2/2!+x^4/4!-.+(-1)^(n=1)*x(2*n-2)/(2*n-2)!精确到10^-6Private Sub Command1_Click()Dim i As Integer,b As Integer,c As Integerx = Text1.Textb = 0For i = 1 To nb = b + a(i)c = Abs(b \ 1 - b)If c < 10 ^ (-6) ThenText2

来源:学生作业帮助网 编辑:作业帮 时间:2024/11/26 13:37:24
vb求cos(x)的近似值,cos(x)=1-x^2/2!+x^4/4!-.+(-1)^(n=1)*x(2*n-2)/(2*n-2)!精确到10^-6Private Sub Command1_Click()Dim i As Integer,b As Integer,c As Integerx = Text1.Textb = 0For i = 1 To nb = b + a(i)c = Abs(b \ 1 - b)If c < 10 ^ (-6) ThenText2
xSkPWNrۦiSZTMiґ9:A6 P')RZn^|%9;|~_NVqG/T۝e# NUTƩ+)>xU9\Q4%$z?/|_}6vjf5zPqd45 ַvVYLԅāTts,apD)@jT)cRAA: *p*SS&IV¿k} 1KXKRau|M¼bQ*ݧ»Xr= HvG!aU01=*4VCG4,Ew'TvZ4AJ4l_]; F?&lHfShX Þ7w

vb求cos(x)的近似值,cos(x)=1-x^2/2!+x^4/4!-.+(-1)^(n=1)*x(2*n-2)/(2*n-2)!精确到10^-6Private Sub Command1_Click()Dim i As Integer,b As Integer,c As Integerx = Text1.Textb = 0For i = 1 To nb = b + a(i)c = Abs(b \ 1 - b)If c < 10 ^ (-6) ThenText2
vb求cos(x)的近似值,cos(x)=1-x^2/2!+x^4/4!-.+(-1)^(n=1)*x(2*n-2)/(2*n-2)!精确到10^-6
Private Sub Command1_Click()
Dim i As Integer,b As Integer,c As Integer
x = Text1.Text
b = 0
For i = 1 To n
b = b + a(i)
c = Abs(b \ 1 - b)
If c < 10 ^ (-6) Then
Text2.Text = b
Next i
End If
End Sub
Public Function a(i As Single) As Double
Dim i As Integer,d As Integer
d = 1
x = Text1.Text
For j = 1 To 2 * i - 2
d = d * j
Next j
a(i) = (-1) ^ (i + 1) * x ^ (2 * n - 2) / d
End Function
我建了两个text文本,一个输入x,一个输出结果,然后点击一个命令框计算输出结果,

vb求cos(x)的近似值,cos(x)=1-x^2/2!+x^4/4!-.+(-1)^(n=1)*x(2*n-2)/(2*n-2)!精确到10^-6Private Sub Command1_Click()Dim i As Integer,b As Integer,c As Integerx = Text1.Textb = 0For i = 1 To nb = b + a(i)c = Abs(b \ 1 - b)If c < 10 ^ (-6) ThenText2
太麻烦了我觉得.只要do loop就行了.
Private Sub Command1_Click()
x = Val(Text1.Text)
t = 2
n = 2
s = 1
Do
f = (-1) ^ (n + 1) * x ^ (2 * (n - 1)) / t
s = s + f
n = n + 1
t = t * (2 * n - 3) * (2 * (n - 1))
Loop Until Abs(f)