Question

Write VBA functions to calculate sin (x) using the Maclaurin arcsine series, and compare the values for sin-1(x) from your program to those given by the Excel spreadsheet function ASIN(x). The Maclaurin arcsine expansion is given by x 3x 6 40 (2n)! sin1(x)-2((2n+1) Note: This function by definition is only defined for-1 SxS1. When you write the code for calculating it, you will need to include code that assigns a value to it that reflects it is undefined for values of x outside this range. One way to do this would be to assign to the function the value of a variable that is declared as a variant, so you can assign the variable a real number value for-1s x S 1, but assign it as a text string for other values of x 1. Write a VBA function, Th (n, x), to calculate the value of an individual terms in the arcsine series as a function of n and x. Watch out for n! when n> 84. Write a VBA function, MacASIN (x), that converges the Maclaurin arcsine series to 15 significant figures, where the error should be less than the tolerance, as defined by the expression: 2. tol-10-16 > error = T,(1.x) or where the terms become too large or too small to calculate. You can do this using a while.WEnd loop, just use a variable, such as Sum, which is set to Sum Tn (x,0) outside the While..WEnd loop, then set to Sum-Sum Tn (x, 1) inside the loop. Be sure to count the iterations of the loop, and to set the loop to exit if the iterations dont converge. Since you may want to set Sum to a text string, declare it as a Variant. Finally, since sin-1(0): O sin-1(-1) = π/2, and sin-1(1) = π/2, there is no need to converge the series expansio for the arcsine function for those values of x; just set MacASIN to the appropriate value. Make a table comparing the values of the Excel spreadsheet ASINCx) function to your user defined function MacASin(x). You do not need to write a Sub to do this. Be sure to set your table to display 15 significant figures so you can see the differences between the functions (Excel only displays 15 significant figures, but carries 16 in its calculations). Make your comparisons for x-±001.0.1.09 and ± 1. Include error trapping code in case the user enters text instead of a number. 3. 4.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Option Explicit

Dim sign As String
Dim val1 As Double
Dim val2 As Double


Private Sub cmd0_Click()
   txtbox.Value = txtbox.Value & cmd0.Caption
End Sub

Private Sub cmd1_Click()
   txtbox.Value = txtbox.Value & cmd1.Caption
End Sub

Private Sub cmd2_Click()
   txtbox.Value = txtbox.Value & cmd2.Caption
End Sub

Private Sub cmd3_Click()
   txtbox.Value = txtbox.Value & cmd3.Caption
End Sub

Private Sub cmd4_Click()
   txtbox.Value = txtbox.Value & cmd4.Caption
End Sub

Private Sub cmd5_Click()
   txtbox.Value = txtbox.Value & cmd5.Caption
End Sub

Private Sub cmd6_Click()
   txtbox.Value = txtbox.Value & cmd6.Caption
End Sub

Private Sub cmd7_Click()
   txtbox.Value = txtbox.Value & cmd7.Caption
End Sub

Private Sub cmd8_Click()
   txtbox.Value = txtbox.Value & cmd8.Caption
End Sub

Private Sub cmd9_Click()
   txtbox.Value = txtbox.Value & cmd9.Caption
End Sub

Private Sub cmdclear_Click()
   txtbox.Value = ""
   val1 = 0
   val2 = 0
   sign = ""
End Sub

Private Sub cmdcos_Click()
Dim v As Double
On Error GoTo aa
   v = CDbl(txtbox.Value)
   txtbox.Value = Math.Cos(v)
   aa: Exit Sub
End Sub

Private Sub cmddivide_Click()
   sign = "/"  
   On Error GoTo aa
   val1 = CDbl(txtbox.Value)
   txtbox.Value = ""
   aa: Exit Sub
End Sub

Private Sub cmdequal_Click()
   On Error GoTo aa
   val2 = CDbl(txtbox.Value)
   If (sign = "+") Then
        txtbox.Value = val1 + val2
   ElseIf (sign = "-") Then
        txtbox.Value = val1 - val2
   ElseIf (sign = "*") Then
        txtbox.Value = val1 * val2
   Else: txtbox.Value = val1 / val2
   End If
   aa: Exit Sub
End Sub

Private Sub cmdmultiply_Click()
   sign = "*"
   On Error GoTo aa
   val1 = CDbl(txtbox.Value)
   txtbox.Value = ""
   aa: Exit Sub
End Sub

Private Sub cmdplus_Click()
    sign = "+"
    On Error GoTo aa
    val1 = CDbl(txtbox.Value)
    txtbox.Value = ""
    aa: Exit Sub
End Sub


Private Sub cmdsin_Click()
   Dim v As Double
   On Error GoTo aa
   v = CDbl(txtbox.Value)
   txtbox.Value = Math.Sin(v)
   aa: Exit Sub
End Sub

Private Sub cmdsqrt_Click()
   Dim v As Double
   On Error GoTo aa
   v = CDbl(txtbox.Value)
   txtbox.Value = Math.Sqr(v)
   aa: Exit Sub
End Sub

Private Sub cmdsquare_Click()
   Dim v As Double
   On Error GoTo aa
   v = CDbl(txtbox.Value)
   txtbox.Value = v ^ 2
   aa: Exit Sub
End Sub

Private Sub cmdsubtract_Click()
   sign = "-"
   On Error GoTo aa
   val1 = CDbl(txtbox.Value)
   txtbox.Value = ""
   aa: Exit Sub
End Sub

Private Sub cmdtan_Click()
   Dim v As Double
   On Error GoTo aa
   v = CDbl(txtbox.Value)
   txtbox.Value = Math.Tan(v)
   aa: Exit Sub
End Sub

Private Sub Form_Load()
   txtbox.Value = ""
End Sub

Private Sub txtbox_KeyPress(KeyAscii As Integer)

'validate user inputs
If (KeyAscii >= vbKey0 And KeyAscii <= vbKey9) Or (Chr(KeyAscii) = ".") Or _         KeyAscii=vbKeyBack Then
    Exit Sub
Else: KeyAscii =0
End If
End Sub

Add a comment
Know the answer?
Add Answer to:
Write VBA functions to calculate sin (x) using the Maclaurin arcsine series, and compare the values...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Using the Maclaurin series for f(x) = sin x, derive the Maclaurin series for g(x) =...

    Using the Maclaurin series for f(x) = sin x, derive the Maclaurin series for g(x) = x sin 2x 1. Hint: It is not necessary to do any differentiation to do this problem. Using the Maclaurin series for f(x) = sin x, derive the Maclaurin series for g(x) = x sin 2x 1. Hint: It is not necessary to do any differentiation to do this problem.

  • The Maclaurin series for sin(x) is x + - + ... 3! 5! 7! sin You...

    The Maclaurin series for sin(x) is x + - + ... 3! 5! 7! sin You need not write your answer in summation notation, but you do need to list at least 4 nonzero terms. b) Find the Maclaurin series for xsin(x). You need not write your answer in summation notation, but you do need to list at least 4 nonzero terms. c) Use the first four terms of the appropriate power series to approximate V2 2

  • Convince yourself that the Maclaurin Series for cos(x) is: A. Write a function script called cos...

    Convince yourself that the Maclaurin Series for cos(x) is: A. Write a function script called cos_series that takes that takes as its inputs, x and N and has output given by the sum in the N-term Maclaurin Series approximation for Cos(x). Hint: try a “for loop” and set “format long” in your code. You may use the MATLAB built-in function factorial() B. Check your code by finding the 2-terms, 3-terms, 4-terms, 5-terms and 6-terms Maclaurin Series approximations every 30 degrees...

  • Write the first 4 non-zero terms of the Maclaurin series for: sin(- 2 x)/x

    Write the first 4 non-zero terms of the Maclaurin series for: sin(- 2 x)/x

  • By using it, show Find the Maclaurin series for sin X. sinx that lim as X...

    By using it, show Find the Maclaurin series for sin X. sinx that lim as X → 0 equals X 1.

  • (1 point) Write the Maclaurin series for f(x) = 9x2 sin(Sx) as Ženx". no Find the...

    (1 point) Write the Maclaurin series for f(x) = 9x2 sin(Sx) as Ženx". no Find the following coefficients. C3= C4= C5= C6= C7E

  • In MATLAB The value of cos(x) can be approximated using a Maclaurin series + +... cos(x)=1-1...

    In MATLAB The value of cos(x) can be approximated using a Maclaurin series + +... cos(x)=1-1 2! 4! 6! Which can be expressed compactly as cos(x) = {(-1)+7 (2(k-1))! 00 2(k-1) k-1 Write Matlab code using a while loop that calculates cos(2) with 5 terms of Maclaurin series. Compare the value with the one calculated with a built-in function cos (2) in Matlab. The following is an expected output from your code: Using the Maclaurin series cos( 2.0) with 5...

  • 4.2 The Maclaurin series expansion for cos x is 6 .8 Starting with the simplest version,...

    4.2 The Maclaurin series expansion for cos x is 6 .8 Starting with the simplest version, cos -I, add terms one at a time to estimate cos(π/3). After each new term is added, compute the true and approximate percent relative errors. Use your pocket calculator to determine the true value. Add terms until the absolute value of the approximate error estimate falls below an error crite- rion conforming to two significant figures.

  • Write a function to calculate the sum of the reciprocals of a series of odd numbers....

    Write a function to calculate the sum of the reciprocals of a series of odd numbers. The function will have one input and no output, with the input being the ending value for the series of odd values. Write the function definition statement Initialize a variable to zero. This variable will contain the sum of all the values. Create a for loop that loops over all odd numbers from 1 to the specified ending value. Inside the loop, add the...

  • Problem 5 xx The Taylor series expansion for sin(x) is sin(x) = x -H + E-E+...

    Problem 5 xx The Taylor series expansion for sin(x) is sin(x) = x -H + E-E+ = o E- (-1) . 2n +1 no (2n+1)! !57 where x is in radians. Write a MATLAB program that determines sin(x) using the Taylor series expansion. The program asks the user to type a value for an angle in degrees. Then the program uses a while loop for adding the terms of the Taylor series. If an n is the nth term in...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT