LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Newton-Raphson cannot solve trig functions among others?

Hi all,

 

I am trying to use the Newton Raphson zero solver to solve an equation, however, I am having a problem.

 

Even if I just set the program to say solve the function cos(x) - 0.3 = 0 I receive NaN as my result. Similar problems occur with log/ln/acosh..etc.

 

Ironically, everything involving the sin function does work (sin, sinh, etc).

 

Limit for the above cos(x) - .3 example is set to between -10 to 10. Accuracy and others are left empty.

 

I am completely confused as to why such a problem exists?

 

Does anyone have any advice?

 

 

0 Kudos
Message 1 of 4
(3,921 Views)

My advice to you is to not use the Newton-Raphson root finder.  NR is a very useful method in many cases with one notable exception.  1D cases where the derivative is evaluated numerically.  For 2D problems, it is a real winner (due mostly to lack of competition), in 1D in is acceptable when you can efficiently evaluate the derivative.  Unfortunately, the VI that ships with LV is for the one case where NR is a bad idea.  If I remember correctly, even the secant method is much improved, and far less suceptible to roundoff error.  I recommend that you go next door and use the Ridder's Zero finder. 

 

That said, in your case you are just entering bad values for the start and stop.  Try something closer to a known root like 0 to 2 for the start and try again.  You have to do some work to bracket your zero.  I didn't test it, but I'll wager Kudos.

 

Convergence of the simple Newton's method is explored here.

0 Kudos
Message 2 of 4
(3,916 Views)

Sorry, I guess I did not clearly explain my problem. Regardless of if I use Riddlers or N-R I am unable to obtain any result for any higher order function other than sin. Any cos/cot/cosh/ln/log etc will produce a solution of NaN. If I use the equation cos(x) + 1 and start at 3 I still receive a result of NaN.

 

Has anyone had an issue like this before? It seems as if t he cos() etc functions are not being recognized by labview itself.

0 Kudos
Message 3 of 4
(3,907 Views)
Cos(x) + 1 is very different than Cos(x) - 0.3 which you originally mentioned.  Cos(x) + 1 does not satisfy the criterion for NR (it does not pass through 0, it only touches 0).  Cos(x) - 0.3 will work with proper starting points.
Message Edited by Darin.K on 09-01-2009 06:02 PM
0 Kudos
Message 4 of 4
(3,904 Views)