Computation Error Approximating Cos(x)

Page 1 of 1

0 Replies - 1069 Views - Last Post: 18 February 2013 - 01:45 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=312639&amp;s=a3c3c3d2a31893d8afe419ad2db7991b&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

#1 CynicalWhiskey

Reputation: 0
• Posts: 1
• Joined: 18-February 13

Computation Error Approximating Cos(x)

Posted 18 February 2013 - 01:45 PM

Hey, not sure if I'm posting this in the right spot, but here goes.

I wrote this program to take a degree variable from cell A2, say, "x" and spit out an approximate value for cos(x) and an exact value. I'm using VBA within Excel. However, the number I am getting for my Approximate Cos(x) is off.

Here is the relative part of my code:

```'Variables
Dim Angle As Double
Dim ApproxCos As Double
Dim ActualCos As Double
Dim TrueError As Double
Dim CosDegrees As Double

'Below Variables are For Output File
Dim a As Double
Dim b As Double
Dim c As Double
Dim d As Double
Dim e As Double
Dim f As Double

Angle = Cells(2, "a").Value
RadianAngle = Angle * (4 * Atn(1)) / 180

'Approximate Cos(x)
ApproxCos = 1 - xrad ^ 2 / 2! + xrad ^ 4 / 4! - xrad ^ 6 / 6! + xrad ^ 8 / 8!
Cells(2, "c").Value = FormatNumber(ApproxCos, 4)

'Conversion for Actual Cos(x)
Cells(2, "d").Value = FormatNumber(ActualCos, 4)

'Output True Error
TrueError = Abs(ActualCos - ApproxCos)
Cells(2, "e").Value = FormatNumber(TrueError, 4)

'Output to File Where a = Angle in Degree, b = Radian angle, c = Approximated Cos(x), d = Actual Cos(x) and e = True Error
'Define Variables "a, b, c, d, e and f"

a = Cells(2, "a").Value
b = Cells(2, "b").Value
c = Cells(2, "c").Value
d = Cells(2, "d").Value
e = Cells(2, "e").Value
f = Cells(2, "f").Value

```

Is This A Good Question/Topic? 0

Page 1 of 1

 .related ul { list-style-type: circle; font-size: 12px; font-weight: bold; } .related li { margin-bottom: 5px; background-position: left 7px !important; margin-left: -35px; } .related h2 { font-size: 18px; font-weight: bold; } .related a { color: blue; }