VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



How to solve sin(x)

by hazem khalfallah (1 Submission)
Category: Math/Dates
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Sun 28th April 2002
Date Added: Mon 8th February 2021
Rating: (1 Votes)

How to solve sin(x)

Rate How to solve sin(x)



Dim x As Double
Dim n As Long
Dim xs As Double
Dim sign As Integer
sign = 1
x = Val(txtx.Text)
If x < 0 Then sign = -1
xs = x
n = Val(txtn.Text)
If n <= 0 Then
  lbldisplay.Caption = "******No solution for zero terms."
Else
        x = Abs(x)
        Do While x > twopi
        x = x - twopi
        Loop
        lbldisplay.Caption = "sin(" & x & ") = " & _
                                                       sign * xsine(x, n) _
                                & vbNewLine & "sin(" & xs & ")=" & Sin(xs)
                                
End If
End Sub
Private Function xsine(x As Double, n As Long) As Double
Dim ans As Double
Dim e As Long
Dim sign As Integer
sign = 1
ans = x
For e = 3 To (2 * n) Step 2
sign = sign * (-1)
newterm = x ^ e / factorial(e) * sign
ans = ans + newterm
Next e
xsine = ans
End Function
Private Function factorial(e As Long) As Double
Dim p As Double
Dim k As Long
p = 1
For k = e To 1 Step -1
p = p * k
Next k
factorial = p
End Function


Private Sub cmdclear_Click()
txtx.Text = ""
txtn.Text = ""
lbldisplay.Caption = ""

End Sub

Private Sub cmdexit_Click()
End

End Sub


Download this snippet    Add to My Saved Code

How to solve sin(x) Comments

No comments have been posted about How to solve sin(x). Why not be the first to post a comment about How to solve sin(x).

Post your comment

Subject:
Message:
0/1000 characters