Ed said:
On a (related) side note, if I have
x - A sin(x) = B
where A, B are known constants, how do I solve for x?
Use a differential calculus procedure for finding roots by successive approximations, such as Newton's method (uses the function and the first derivative) or Danby's method (uses the function and the 1st, 2nd, and 3rd derivatives).
Note that you are seeking the value of a transcendental variable having some arguments inside and outside trigonometric functions. That means you must keep x in radians.
Newton's method.
define:
F(x) = B + A sin x - x
differentiate:
dF/dx = F1(x) = A cos x - 1
You want to find the roots of F(x); i.e., the values of x that make F(x)=0.
Choose an initial guess for x.
x = X0
Repeat while incrementing i,
X(i+1) = X(i) - F(X(i)) / F1(X(i))
Until |X(i+1) - X(i)| approaches zero.
x = X(i+1)
The converged value of X is assigned to x, and it is a root of F(x).
Beware! The root you find might not be the root you need. If F(x) has several roots, you could get the wrong one. It helps to know enough about F(x) so that you can pick a good initial guess for X0.
(I think I've seen Newton's method fail once or twice by trying to find a root at infinity.)
Danby's method.
define:
F(x) = B + A sin x - x
derivatives:
F1(x) = A cos x - 1
F2(x) = -A sin x
F3(x) = -A cos x
Find the roots of F(x).
x = X0
Repeat while incrementing i,
d1 = -F(X(i))/F1(X(i))
d2 = -F(X(i))/{ F1(X(i)) + d1 F2(X(i))/2 }
d3 = -F(X(i))/{ F1(X(i)) + d1 F2(X(i))/2 + d2^2 F3(X(i))/6 }
X(i+1) = X(i) + d3
Until |X(i+1) - X(i)| approaches zero.
x = X(i+1)
The converged value of X is assigned to x, and it is a root of F(x).
Bisection method.
define:
F(x) = B + A sin x - x
choose x0 and x1 such that
F(x0) F(x1) < 0
Repeat
Xmid = (x0 + x1)/2
Q0 = F(x0) F(Xmid)
Q1 = F(x1) F(Xmid)
if Q0<0 then x1 = Xmid
if Q1<0 then x0 = Xmid
Until |x1 - x0| approaches zero, or until F(Xmid)=0.
If F(Xmid)=0 then x=Xmid
else...
x = (x0 + x1)/2
This method is slow! But it doesn't require differentiation.
Peck-Peck-Peck method.
define:
F(x) = B + A sin x - x
choose an initial value, x0, and a small incremental value dx.
Repeat
x1 = x0 + dx
Until F(x1) F(x0) < 0
x ~ (X1 + x0)/2
This method is slow and imprecise. The smaller dx is, the better is the precision but the slower is the procedure. It might be used just to get an initial guess for a more exact procedure.
Jerry Abbott