求解一道关于函数的vb题目用自定义函数过程,输入x,n,系数An,计算并输出函数的值。 y=

2025-04-29 19:54:03
推荐回答(2个)
回答1:

Private Function h(a() As Double, x As Double, n As Integer) As Double
Dim i As Integer, s As Double, t As Double
s = 0
t = 1
For i = 1 To n
t = t * x
s = s + a(i) * Log(t)
Next i
h = s
End Function

Private Function g(x As Double) As Double
g = Sin(37 * 3.1416 / 180) * Exp(3 * x)
End Function

Private Sub Command1_Click()
Dim a() As Double
Dim n As Integer, x As Double, y As Double
n = InputBox("n=?")
ReDim a(1 To n)
x = InputBox("x=?")
For i = 1 To n
a(i) = InputBox("a(" & i & ")=?")
Next i
y = g(x * x) + h(a, x + 3, n) + g(2 * x)
Print "y="; y
End Sub

回答2:

private function y(x as single,n as integer,a() as single) as double
y=g(x)+h(x+3,n,a())+g(2*x)
print y
end function

private function g(xg as single) as double
g=sin(37*3.1416/180)*e^(3*xg)
end function

private function h(xh as single,nh as integer,ah() as single) as double
dim i as integer
h=0
for i=1 to nh
h=h+ah(i)*(ln(xh))^i
next
end function