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
Write VBA functions to calculate sin (x) using the Maclaurin arcsine series, and compare the values...
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 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_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
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 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 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, 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. 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+ = 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...