Reputation: 1947
I want to write a function which has 5 inputs :
which outputs
Problem seems very simple for me, however I'm dealing with error :
Function Sequence(x_0 As Double, x_1 As Double, a As Double, b As Double, n As Double) As Double
If n = 0 Then
x_0
ElseIf n = 1 Then
x_1
Else
a * Sequence(x_0, x_1, a, b, n-1) + b * Sequence(x_0, x_1, a, b, n-2)
End If
End Function
And If I want to use my function :
Sequence(1;1;1;1;1)
I see error :
Do you hany idea what I'm doing wrong ?
Upvotes: 0
Views: 94
Reputation: 42236
In VBA, the function to call parameters must be separated by comma. Like a UDF function you can call it from sheet using the list separator according to regional settings ["=Sequence(1, 1, 1, 1, 1) or Sequence(1; 1; 1; 1; 1)];
If a called function returns something, the way you call it should be in a way to deal with the returned value:
Debug.Print Sequence(1, 1, 1, 1, 1)
Then, try playing with the function parameters.
Function Sequence(x_0 As Double, x_1 As Double, a As Double, b As Double, n As Double) As Double
If n = 0 Then
Sequence = x_0
ElseIf n = 1 Then
Sequence = x_1
Else
Sequence = a * Sequence(x_0, x_1, a, b, n - 1) + b * Sequence(x_0, x_1, a, b, n - 2)
End If
End Function
Upvotes: 1