Thread: formula code
View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.misc
Dana DeLouis Dana DeLouis is offline
external usenet poster
 
Posts: 947
Default formula code

Hi. For discussion, these types of problems need to have some type of
checking. We note that different values of a,b,f, & p can make this harder
to solve.
If we make our first guess 0, then we note that for this problem, there is
no need to calculate the big equation for the next value. It simplifies to
just:
x = (p - a) / (b - f)

So, instead of starting out with x=0, it would be better to use x= (p - a)
/ (b - f). This reduces the number of loops by 1.
However, it is now clearer to see that there will be an error if b = f !!
The closer b is to f, then x will tend to be a large number. The code will
zero in on a very large angle x.
Your code will have to adjust if you think b=f, p=a, x is a large number,
....etc.
A slight improvement, but not complete, might be something like this:

Function Find_x(a, b, f, p)
Dim x As Double
Dim t As Double

On Error Resume Next
x = (p - a) / (b - f)
If x = 0 Then x = 1 'try different value

Do
t = x
x = x + (a + (b - f) * Tan(x) - p * Cos(x)) / _
(f - b + a * Tan(x) - 2 * p * Sin(x))
Loop Until Round(x - t, 16) = 0
Find_x = x
End Function

One example might be that if b =f, then the loop equation could be reduced
to :
x = x + (p*Cos(x) - a)/(2*p*Sin(x) - a*Tan(x))

Again, lots of variations to account for different values.
--
HTH. :)
Dana DeLouis
Windows XP, Office 2003