+ Reply to Thread
Results 1 to 9 of 9

Taylor series estimation program

  1. #1
    Registered User
    Join Date
    09-16-2010
    Location
    AZ, USA
    MS-Off Ver
    Excel 2007
    Posts
    9

    Taylor series estimation program

    I am trying to write a program that estimates sin(x) for a school assignment. Here is what I have so far:
    Please Login or Register  to view this content.
    There is a compiler error around fact=((2*k)+1). It says there is an "expected end of function" and the 2 is highlighted. I don't know what this means or how to fix it.

  2. #2
    Registered User
    Join Date
    09-16-2010
    Location
    AZ, USA
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Taylor series estimation program

    I have realized part of the problem. The function Factorial needs to be outside the main function. However, moving it only causes my program to return #VALUE. How can I fix this?

  3. #3
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: Taylor series estimation program

    If you use the debugger to step through the code line by line you would see the error is due to overflowing values.

    The reason for the overflow is the variable being passed into the FACT function is being altered within the function.

    Please Login or Register  to view this content.
    If you use the ByVal keyword a copy of the value is passed in to the function.
    Also from what I can see you only need to calculate the bottom variable once.
    Cheers
    Andy
    www.andypope.info

  4. #4
    Registered User
    Join Date
    09-16-2010
    Location
    AZ, USA
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Taylor series estimation program

    Thanks, it compiles now. But the returned value for SinE(3,10) is 3 and that isn't right.

  5. #5
    Registered User
    Join Date
    09-16-2010
    Location
    AZ, USA
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Taylor series estimation program

    In fact, it seems to be simply returning the number for x.

  6. #6
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: Taylor series estimation program

    If you change your singles to doubles the function should return 3.0000000020474

    If you use the function on the worksheet you may need to increase the number of decimal points shown.

    If not what answer did you expect from in the inputs 3 and 10?

  7. #7
    Registered User
    Join Date
    09-16-2010
    Location
    AZ, USA
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Taylor series estimation program

    It should be an estimate of sin(3) in radians.

  8. #8
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Taylor series estimation program

    You can calculate the factorial in-line as needed:
    Please Login or Register  to view this content.
    Entia non sunt multiplicanda sine necessitate

  9. #9
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,363

    Re: Taylor series estimation program

    Your "bottom" variable needs to be moved into the For.. Next loop so it gives increasing numbers of factorials.

    You will also need to change the "k" in your loop to "I" . You are incrementing I not k.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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