Posted: Sun Jul 19, 2009 6:34 pm Post subject: Help w/VBA function 2calculate sine of an angle using series
Can someone help me do this? I have no clue where to even start.
Thank you!
Write and Test a VBA function to calculate the sine of an angle using the series:
sin(x)=+(x^1/1!)-(X^3/3!)+(x^5/5!)-(x^7/7!)+...
The strategy in using a power series is to calculate and add terms until the absolute value of the last term is less than a specified tolerance.
There are a number of ways to handle the required loop and logic. The flowchart on the next page shows one approach. You may use this approach or develop your own. Be sure to include the following:
The function itself should have the datatype Double.
The function arguments will be the angle (x As Double) and an Optional, Boolean argument for degrees or radians.
The maximum iterations (100) and the tolerance (0.00001) should be assigned inside the function code
The loop should continue either until the absolute value of the last term is less than the tolerance, or maximum iterations are reached.
There should be code inside the loop to calculate each term based on the loop counter and add with the appropriate sign (+ or -).
There should be a message box to tell the user that maximum iterations were reached this implies that the last term was not small enough to pass the tolerance test.
Write a subroutine to use the function which asks the user to enter a value of x. The results should be output to both the spreadsheet and via a message box. The user should be allowed to continue or stop after each x is entered. The results on the spreadsheet should form two columns .. one headed x and the other sin (x).
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum