Need to approximate Arc Cosine, math majors needed!

Train

Lifer
Jun 22, 2000
13,581
80
91
www.bing.com
I have some software that runs in MS SQL Server and utilizes the acos() function, which returns the arc cosine, aka inverse cosine. Im trying to get a client up and running in MS Access, which doesnt have the Acos or any other arc cosine function, it only had the regular cos, sin, and tan functions.

The results dont need to be exact, so even a rough estimate is ok. SO far the closest thing i have come up with is the equation
y= -1.5708x +1.5708
Which is of course a straight line, the pic below is a rough drawing of how acos(x) and my little function relate. Its a little too far off in some places, i was wondering if anyone could get closer using simple linear algebra or the 3 main trig functions?

Crude Pic

Thanks for all your help.
 

Armitage

Banned
Feb 23, 2001
8,086
0
0


<< I have some software that runs in MS SQL Server and utilizes the acos() function, which returns the arc cosine, aka inverse cosine. Im trying to get a client up and running in MS Access, which doesnt have the Acos or any other arc cosine function, it only had the regular cos, sin, and tan functions.

The results dont need to be exact, so even a rough estimate is ok. SO far the closest thing i have come up with is the equation
y= -1.5708x +1.5708
Which is of course a straight line, the pic below is a rough drawing of how acos(x) and my little function relate. Its a little too far off in some places, i was wondering if anyone could get closer using simple linear algebra or the 3 main trig functions?

Crude Pic

Thanks for all your help.
>>



Jeez, what's the point of having trig functions if you don't have the inverse functions?!?
Are you sure it doesn't have any of the inverse trig functions, they can be expressed in terms of each other.
You might also look at the first few terms of the series expansion for cos and see if you can invert it.
 

Agent004

Senior member
Mar 22, 2001
492
0
0
From the graph, it seems it can be approximated by an x^3 polynomial, rather than the trig functions, because it doesn't seem periodic at all. I think it's got a turning point as well

Guess that doesn't hep at all.

BTW, this is how Cosine is defined
infinty
Cos (x) = sigma (-1)^n *x^(2n) / (2!)
n=0

EDIT: The fomula won't shown up properly, even though in the edit it's fine:(
 

rolo

Junior Member
Oct 11, 1999
1
0
0
Try this:

p(x) = -0.54038583*x^5 + -0.14191872*x^4 + 0.07485317*x^3 + 0.06303811*x^2 + -1.02113558*x + 1.56817611

This was obtained using a "Minimax Approximation using Remes Algorithm" MATLAB program I wrote for my CS330 (Numerical Computing) course last semester.
 

J.Zorg

Member
Feb 20, 2000
47
0
0
_____oo
sin x = | [(-1^v)*x^(2v+1)]/(2v+1)!
_____v=0

= x - (x^3/3!) + (x^5/5!) - (x^7/7!) +.........................

______oo
cos x = | [(-1^v)*x^(2v)/(2v)!
______v=0

= 1 - (x^2/2!) + (x^4/4!) - (x^6/6!) + ........................


| = sigma (from v=0 to infinty)

Sorry look pretty messy. Did the best i could ;)
 

blahblah99

Platinum Member
Oct 10, 2000
2,689
0
0
Loook up "Taylor's expansion" or "taylor's approximation".

It will let you approximate any function to any complexity you want.

if i recall correctly, the format of that theorem is something like this:


f(x) = f(0) + f'(0)x + (f''(0)/(2!)*x^2 + f'''(0)/(3!) * x^3 and so on...

f(x) ~= arcsine(x) centered around 0.

If you want the approximation centered around another value, replace the 0 with that value.
 

Shalmanese

Platinum Member
Sep 29, 2000
2,157
0
0
Does it have a derivative or integral function?

If it does, you could simply find the integral of x/sqrt(1-x^2) (I think :()
 

RaynorWolfcastle

Diamond Member
Feb 8, 2001
8,968
16
81
are you allowed to use a piecewise function?

if you can, then I can build you a relatively accurate function that's not too complex quickly (using cubic splines).

otherwise, I can use an interpolated polynomial but those tend to get very intense (from a computation standpoint since for each point you use, you must increase the polynomial by one degree.

-Ice
 

RaynorWolfcastle

Diamond Member
Feb 8, 2001
8,968
16
81
Here is a pretty good approximation using cubic splines

[3216.5+9663.3*x+9674.9*x^2+3225.0*x^3, x < -.98],
[-2524.3-7910.6*x-8257.6*x^2-2874.5*x^3, x < -.96],
[-173.00-562.80*x-603.67*x^2-216.91*x^3, x < -.94],
[15.290+38.123*x+35.614*x^2+9.7878*x^3, x < -.92],
[-43.737-154.35*x-173.60*x^2-66.014*x^3, x < -.9],
[-2.8776-18.157*x-22.270*x^2-9.9662*x^3, x < -.8],
[1.0245-3.5244*x-3.9789*x^2-2.3449*x^3, x < -.7],
[1.3986-1.9210*x-1.6883*x^2-1.2541*x^3, x < -.6],
[1.5316-1.2560*x-.58006*x^2-.63848*x^3, x < -.5],
[1.5624-1.0711*x-.21020*x^2-.39191*x^3, x < -.4],
[1.5687-1.0240*x-.92540e-1*x^2-.29386*x^3, x < -.3],
[1.5703-1.0075*x-.37427e-1*x^2-.23263*x^3, x < -.2],
[1.5708-1.0007*x-.32248e-2*x^2-.17562*x^3, x < -.1],
[1.5708-1.0004*x+.90341e-7*x^2-.16487*x^3, x < 0],
[1.5708-1.0004*x+.90341e-7*x^2-.16488*x^3, x < .1],
[1.5708-1.0007*x+.32228e-2*x^2-.17562*x^3, x < .2],
[1.5713-1.0075*x+.37440e-1*x^2-.23265*x^3, x < .3],
[1.5729-1.0240*x+.92469e-1*x^2-.29379*x^3, x < .4],
[1.5792-1.0713*x+.21055*x^2-.39219*x^3, x < .5],
[1.6099-1.2552*x+.57844*x^2-.63745*x^3, x < .6],
[1.7439-1.9254*x+1.6954*x^2-1.2580*x^3, x < .7],
[2.1118-3.5020*x+3.9478*x^2-2.3306*x^3, x < .8],
[6.0333-18.208*x+22.330*x^2-9.9898*x^3, x < .9],
[47.741-157.23*x+176.80*x^2-67.202*x^3, x < .92],
[-15.352+48.503*x-46.824*x^2+13.822*x^3, x < .94],
[179.18-572.33*x+613.64*x^2-220.39*x^3, x < .96],
[2528.5-7913.9*x+8261.1*x^2-2875.7*x^3, x < .98],
[-3215.3+9669.0*x-9680.6*x^2+3226.9*x^3, otherwise]

I used a quick and dirty Maple worksheet to get it

check out the graph (arc cos function is in green, approximation is in red, sample points are in blue)
Graph

-Ice

*Edit* BTW, it looks long, but it runs very fast since it's a piecewise and each segment is a cubic.

*Edit2* Here is a quick interpolated polynomial. Not quite as nice as the cubic spline but it'll do the job if accuracy isn't all-important
-.232e-1*x^4-.43895*x^3+.53e-2*x^2-.93773*x+1.5708