dwp82
11-15-2012, 03:26 AM
I am trying to devolop a vba syntax I can use within excel.
So far I have managed to come up with a maclaurin expansion for e^x
Function MacExp(x)
MacExp = 0
term = 1
k = 1
Do While term > 0
MacExp = MacExp + term
term = term * x / k
k = k + 1
If k > 100 Then
Exit Do
End If
Loop
End Function
However I am now trying to come up with a taylor series for cos x , with the function starting as "function fcos (x,n)" I have this so far, but its not getting the correct numbers out.
Function fcos(x, n)
fcos = 0
Term = 1
k = 1
Do While Term > 0
fcos = x * n
Term = Term * x / k
k = k + 1
If k < 5 Then
Exit Do
End If
Loop
End Function
thank you for any help.
So far I have managed to come up with a maclaurin expansion for e^x
Function MacExp(x)
MacExp = 0
term = 1
k = 1
Do While term > 0
MacExp = MacExp + term
term = term * x / k
k = k + 1
If k > 100 Then
Exit Do
End If
Loop
End Function
However I am now trying to come up with a taylor series for cos x , with the function starting as "function fcos (x,n)" I have this so far, but its not getting the correct numbers out.
Function fcos(x, n)
fcos = 0
Term = 1
k = 1
Do While Term > 0
fcos = x * n
Term = Term * x / k
k = k + 1
If k < 5 Then
Exit Do
End If
Loop
End Function
thank you for any help.