高分。VB高手请进。一道VB作业题
函数e^x能用下面的方式表达e^x.=1+x/(1!)+x^2/(2!)+x^3/(3!)+x^4/(4!)+………因为这是一个无限增长的数列,我们需要确定我们要加多少个...
函数 e^x 能用下面的方式表达
e^x.= 1+ x/(1!)+ x^2/(2!) + x^3/(3!)+ x^4/(4!) +………
因为这是一个无限增长的数列,我们需要确定我们要加多少个项。这个数列中的项会变得越来越少,当达到一定的精确度,e^x就能被确定
编程要求
使用一个main program 和两个 user-defined Function Subprogram
在main program中, 让读者输入x 的值 来计算ex.
在main program 中, 让读者输入这个数列中的末项最大值
在main program中, 输出ex 的值
使用一个user-define Funtion 来计算 ex
使用一个user-defined Function来计算阶乘,N!
我真的想不到该用什么逻辑去求出ex vb 该用的语法我都懂,可是我就是想不到那个逻辑
谢谢各位大侠
以上是中文翻译
可能不太准确
以下是英文原文
Program requirements:
- Use a main program and two user-defined Function subprograms.
- In the main program, prompt user in enter a value, x, to use in calculating ex.
- In the main program, prompt the user to enter a maximum value of the last term in the series (suggested value = 1 x 10-7).
- In the main program, output the answer (the calculated ex value) and calculate the e(x) using VBA built-in function and output that answer also (for comparison purposes).
- Use a user-defined Function to calculate the exponential (ex) function.
- Use a user-define Function to calculate a Factorial, N!.
这是我编的,可是我怎么编都有很多问题
Dim x As Single, Lasttermlimit As Single, factorial As Single, expx As Single, expbuildinfunction As Single, answer As Single, count1 As Single, count2 As Single
x = InputBox("Please enter a value for x")
expbuildinfunction = exp(x)
Do
factorial = fact()
expx = singleterm(x, factorial)
If expx < Lasttermlimit Then Exit Do
expx = expx + 1
Loop
MsgBox (" The calculated e^x value is " & expx & " The value of e^x in the VBA buildin function is " & expbuildinfunction)
End Sub
Function fact() As Single
Dim count1 As Single
count1 = count1 + 1
fact = fact * count1
End Function
Function singleterm(ByVal x As Single, fact As Single) As Single
Dim count2 As Single
count2 = count2 + 1
singleterm = x ^ count2 / fact
End Function 展开
e^x.= 1+ x/(1!)+ x^2/(2!) + x^3/(3!)+ x^4/(4!) +………
因为这是一个无限增长的数列,我们需要确定我们要加多少个项。这个数列中的项会变得越来越少,当达到一定的精确度,e^x就能被确定
编程要求
使用一个main program 和两个 user-defined Function Subprogram
在main program中, 让读者输入x 的值 来计算ex.
在main program 中, 让读者输入这个数列中的末项最大值
在main program中, 输出ex 的值
使用一个user-define Funtion 来计算 ex
使用一个user-defined Function来计算阶乘,N!
我真的想不到该用什么逻辑去求出ex vb 该用的语法我都懂,可是我就是想不到那个逻辑
谢谢各位大侠
以上是中文翻译
可能不太准确
以下是英文原文
Program requirements:
- Use a main program and two user-defined Function subprograms.
- In the main program, prompt user in enter a value, x, to use in calculating ex.
- In the main program, prompt the user to enter a maximum value of the last term in the series (suggested value = 1 x 10-7).
- In the main program, output the answer (the calculated ex value) and calculate the e(x) using VBA built-in function and output that answer also (for comparison purposes).
- Use a user-defined Function to calculate the exponential (ex) function.
- Use a user-define Function to calculate a Factorial, N!.
这是我编的,可是我怎么编都有很多问题
Dim x As Single, Lasttermlimit As Single, factorial As Single, expx As Single, expbuildinfunction As Single, answer As Single, count1 As Single, count2 As Single
x = InputBox("Please enter a value for x")
expbuildinfunction = exp(x)
Do
factorial = fact()
expx = singleterm(x, factorial)
If expx < Lasttermlimit Then Exit Do
expx = expx + 1
Loop
MsgBox (" The calculated e^x value is " & expx & " The value of e^x in the VBA buildin function is " & expbuildinfunction)
End Sub
Function fact() As Single
Dim count1 As Single
count1 = count1 + 1
fact = fact * count1
End Function
Function singleterm(ByVal x As Single, fact As Single) As Single
Dim count2 As Single
count2 = count2 + 1
singleterm = x ^ count2 / fact
End Function 展开
展开全部
你那都编的什么乱七八糟的,我看了半天才理解,以下我帮你改的。。。还不如从新编一个来得快~~~
Private Sub Command1_Click() 'Main Program是一个按钮
Dim x As Integer, Lasttermlimit As Single, expx As Single
Dim expbuildinfunction As Single, answer As Single, count As Integer
x = InputBox("Please enter a value for x") '输入x
expbuildinfunction = Exp(x) '计算真实值e^x
Lasttermlimit = InputBox("Please enter a value for the last limit value") '用一个inputbox获取末项极限值,当末项小于此值时停止运算
count = 1
Do
expx = singleterm(x, count)
If expx < Lasttermlimit Then Exit Do '当单项小于末项极限值时退出循环
count = count + 1
answer = answer + expx
Loop
answer = answer + 1
MsgBox (" The calculated e^x value is " & answer & " The value of e^x in the VBA buildin function is " & expbuildinfunction)
End Sub
Function fact(ByVal count1 As Integer) As Single '计算阶乘
If count1 = 1 Then
fact = 1
Else
fact = count1 * fact(count1 - 1) '递归调用,不能加1的,不然要循环溢出了
End If
End Function
Function singleterm(ByVal x As Single, ByVal count2 As Integer) As Single '求单项值
singleterm = x ^ count2 / fact(count2)
End Function
Private Sub Command1_Click() 'Main Program是一个按钮
Dim x As Integer, Lasttermlimit As Single, expx As Single
Dim expbuildinfunction As Single, answer As Single, count As Integer
x = InputBox("Please enter a value for x") '输入x
expbuildinfunction = Exp(x) '计算真实值e^x
Lasttermlimit = InputBox("Please enter a value for the last limit value") '用一个inputbox获取末项极限值,当末项小于此值时停止运算
count = 1
Do
expx = singleterm(x, count)
If expx < Lasttermlimit Then Exit Do '当单项小于末项极限值时退出循环
count = count + 1
answer = answer + expx
Loop
answer = answer + 1
MsgBox (" The calculated e^x value is " & answer & " The value of e^x in the VBA buildin function is " & expbuildinfunction)
End Sub
Function fact(ByVal count1 As Integer) As Single '计算阶乘
If count1 = 1 Then
fact = 1
Else
fact = count1 * fact(count1 - 1) '递归调用,不能加1的,不然要循环溢出了
End If
End Function
Function singleterm(ByVal x As Single, ByVal count2 As Integer) As Single '求单项值
singleterm = x ^ count2 / fact(count2)
End Function
展开全部
貌似翻译得有问题。
“因为这是一个无限增长的数列,我们需要确定我们要加多少个项。这个数列中的项会变得越来越少,当达到一定的精确度,e^x就能被确定
”这句话的意思让人搞不懂,不过通过后面的来理解貌似需要用户输入两个数据,一个是x值,另一个应该是精度(也就是计算到小数点后多少位)?貌似是这样的。
先确定题目再来写程序吧。
“因为这是一个无限增长的数列,我们需要确定我们要加多少个项。这个数列中的项会变得越来越少,当达到一定的精确度,e^x就能被确定
”这句话的意思让人搞不懂,不过通过后面的来理解貌似需要用户输入两个数据,一个是x值,另一个应该是精度(也就是计算到小数点后多少位)?貌似是这样的。
先确定题目再来写程序吧。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
级数展开。这个你需要指定展开多少项,VB是无法展开无穷项的。难度不大。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询