+ Reply to Thread
Results 1 to 1 of 1

Taylor Series Expansion of Sin(x) -- VBA -- Type Mismatch error

Hybrid View

  1. #1
    Registered User
    Join Date
    08-26-2013
    Location
    Dallas, TX
    MS-Off Ver
    Excel 2010
    Posts
    1

    Taylor Series Expansion of Sin(x) -- VBA -- Type Mismatch error

    I'm new to VBA and am trying to make a program to solve the Taylor Series Expansion of Sin(x).

    There is a '<Type Mismatch>' error on the line:
    "deriv = ((h ^ i) * PLUSorMINUS * EVENorODD) / (Fact(i))"

    It says "Fact(i)" is the problem. Any help would be appreciated.
    Sub fsolver()
    
    xLOW = 0.01
    xHIGH = 1
    imax = 100
    Es = 0.0005
    
    x = 0
    h = x
    i = 1
    Ea = 0.01
    
    EVENorODD = Cos(x)
    deriv = 0
    fSIN = 0
    PLUSorMINUS = 1
    
    
    Fact = Application.WorksheetFunction.Fact(i)
    
    isEven = Application.WorksheetFunction.isEven(i)
    
    
    Do
    xOLD = x
    x = (xLOW + xHIGH) / 2
    h = x
    If Ea <> 0 Then
        Ea = Abs((x - xOLD) / (x)) * 100
    End If
    
    deriv = ((h ^ i) * PLUSorMINUS * EVENorODD) / (Fact(i))
    fSIN = Sin(x) + deriv
    
    
    fLOW = fSIN(xLOW)
    fHIGH = fSIN(xHIGH)
    
    ABOVEorBELOW = fLOW * fHIGH
    
    If ABOVEorBELOW < 0 Then
        xHIGH = x
        Else
        If ABOVEorBELOW > 0 Then
        xLOW = x
        End If
    End If
    
    Cells(1, 5) = "x"
    Cells(i + 1, 5) = x
    Cells(1, 6) = "Ea"
    Cells(i + 1, 6) = Ea
    Cells(1, 3) = "Result"      'fSIN value
    Cells(i + 1, 3) = fSIN
    Cells(1, 4) = "fLOW*fHIGH above or below 0"
    Cells(i + 1, 4) = ABOVEorBELOW
    Cells(1, 2) = "Truncated value"     'deriv value
    Cells(i + 1, 2) = deriv
    Cells(1, 1) = "i"
    Cells(1 + i, 1) = i
    
    i = i + 1
    
    If isEven(i) = True Then
        EVENorODD = Sin(x)
        Else: EVENorODD = Cos(x)
    End If
    
    
    If i = [1,4,5,8,9] = True Then
        PLUSorMINUS = (1)
        Else: PLUSorMINUS = (-1)
    End If
    
    
    If Es > Ea Or i > imax Then Exit Do
    
    Loop
    
    
    End Sub
    Last edited by vlady; 09-09-2013 at 07:25 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Run Type error 13 Type Mismatch
    By Affan Khan in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 11-13-2012, 12:58 PM
  2. Complile Error: Type Mismatch ??? After adding error trap
    By clemsoncooz in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-22-2012, 03:50 PM
  3. Conditional Formatting - Run Time Error '13' Type Mismatch Error
    By ksp in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-17-2011, 07:37 PM
  4. Taylor series estimation program
    By bockisch in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-23-2010, 11:19 AM
  5. Help: Compile error: type mismatch: array or user defined type expected
    By lvcha.gouqizi in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-31-2005, 05:05 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1