Calculate Sin(x), e^(x) , and Pi
This code allows you to calculate Sin(x), e^(x), and Pi without using any of the built-in VB functions
AI
Riepilogo AI: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.
Codice sorgente
'Sin(x) function 'Note: this is in radians, not degrees Public Function Sine(x as Double) as Double Dim i As Integer, sum As Double: sum = 0 'Calculate the taylor expansion of sin For i = 1 To 10 sum = sum + (((-1) ^ (i + 1)) * ((x) ^ (2 * i - 1)) / fact(2 * i - 1)) Next i Sine=sum End Function 'e^(x) function Public Function e(x as Integer) as Double Dim i As Integer, sum As Double: sum = 0 'Calculate the Taylor expansion of e For i = 0 To 150 sum = sum + (x ^ i) / fact(i) Next i e=sum End Function 'Pi function Public Function pi() as Double Dim i As Integer, sum As Double: sum = 0 For i = 1 To 15000 sum = sum + ((-1) ^ (i + 1)) * (1 ^ (2 * i - 1)) / (2 * i - 1) Next i pi = sum * 4 End Function 'Function that calculates factorials Public Function fact(n As Integer) As Double Dim i As Long, r As Double: r = 1 If n = 0 Then fact = 1 For i = 1 To n r = i * r Next i fact = r End Function
Commenti originali (3)
Recuperato da Wayback Machine