函数 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