-
[[URGENT]] VBA help with the Taylor Series on Trigonometry
Hello, I am new to this forum and I have an urgent problem to be solved. I hope someone here can help me out in writing a VBA While Loop on the Sine x function of the Taylor Series.
the function that i need to write is something like this:
h ttp://upload.wikimedia.org/math/5/d/3/5d32785481dec2be0c115f510f164dd1.png
So far I have written a few lines. And my program is like the following:
Function sum()
Dim x() As Double
Dim sine As Double
Dim I As Integer
Dim cell As Range
Dim ValRange As Range
x() = Cells(1, 1).Value
Cells(1, 1).Value = x(1)
Cells(2, 1).Value = x(2)
Cells(3, 1).Value = x(3)
Cells(4, 1).Value = x(4)
Cells(5, 1).Value = x(5)
Cells(6, 1).Value = x(6)
sine = x(I)
AddIt = x(I)
Fact = Fact + 2
While AddIt < 0.00000001
sine = AddIt * x(I) * x(I) / Fact / Fact - 1
AddIt = Abs(AddIt) - 1
x(I + 1) = x(I)
Wend
End Function
my function is not working
i need URGENT HELP... Please help me><
thanks
-
Without testing fully - try...
[vba]
Option Explicit
Sub SinXSeriesExpansion()
Dim M As Long, N As Long, X As Double, SineX As Double
X = InputBox("What is X?")
M = InputBox("How many terms?")
If IsNumeric(M) And M > 0 Then
SineX = 0
On Error GoTo OverFlow
For N = 0 To M \ 1
SineX = SineX + ((-1) ^ (N) * X ^ (2 * N + 1)) / Evaluate("Fact(" & 2 * N + 1 & ")")
Range("A" & N + 1) = SineX
Next
MsgBox SineX
Else
MsgBox "Need the number of terms to be greater than zero!"
End If
Exit Sub
OverFlow:
MsgBox "Too many terms - try fewer terms", , "OverFlow Error!!"
End Sub
[/vba]
You know you're really in trouble when the light at the end of the tunnel turns out to be the headlight of a train hurtling towards you
The major part of getting the right answer lies in asking the right question...
Made your code more readable, use VBA tags (this automatically inserts [vba] at the start of your code, and [/vba ] at the end of your code) | Help those helping you by marking your thread solved when it is.
-
sorry
but can i hav it as a While Loop program?
coz my lecturer is asking me for a while loop...><
Thank you alot for helping me out...><
-
Please read this from FAQ
MVP (Excel 2008-2010)
Post a workbook with sample data and layout if you want a quicker solution.
To help indent your macros try Smart Indent
Please remember to mark threads 'Solved'
-
So it's homework is it? We don't do homework.
You know you're really in trouble when the light at the end of the tunnel turns out to be the headlight of a train hurtling towards you
The major part of getting the right answer lies in asking the right question...
Made your code more readable, use VBA tags (this automatically inserts [vba] at the start of your code, and [/vba ] at the end of your code) | Help those helping you by marking your thread solved when it is.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules