471,309 Members | 1,426 Online

# Solving equation phi(x) = k in C++, how? 11
Hi again guys :)

Ok i have this problem, i need to solve the equation phi(x) = 0.1

(where phi is the area under the gaussian normal distribution function)

apparently im supposed to solve it as f(x)=0 , ( phi(x) - 0.1 =0 ) , which can be solved by iteration, for example by using newton-raphson. But i have no idea how to do this. NR needs f(x), f'(x), how can i get that from phi? :s since that function cant be differentiated or integrated.. i can construct a taylor polynomial for the function, not sure if thats what im supposed to.. any tips ? :) Thx all!
Aug 21 '07 #1
5 2451 ahoyer
14 Hi again guys :)

Ok i have this problem, i need to solve the equation phi(x) = 0.1
(where phi is the area under the gaussian normal distribution function)
apparently im supposed to solve it as f(x)=0 , ( phi(x) - 0.1 =0 ) , which can be solved by iteration, for example by using newton-raphson. But i have no idea how to do this. NR needs f(x), f'(x), how can i get that from phi? :s since that function cant be differentiated or integrated.. i can construct a taylor polynomial for the function, not sure if thats what im supposed to.. any tips ? :) Thx all!

if you set phi(x) -0.1 = 0 then all youre doing is root finding right? For that you dont need to do newton-raphson (its sometimes unstable anyways), you could just use the bisection method or even go up to doing the secant method.

the wiki page for the secant method is pretty good, the same goes for bisection method.

if youre looking for speed, you should probably do the secant method, but if you just want to get it done use the bisection.

hope that helps.
Aug 21 '07 #2
2wycked
14 Hi again guys :)

Ok i have this problem, i need to solve the equation phi(x) = 0.1

(where phi is the area under the gaussian normal distribution function)

apparently im supposed to solve it as f(x)=0 , ( phi(x) - 0.1 =0 ) , which can be solved by iteration, for example by using newton-raphson. But i have no idea how to do this. NR needs f(x), f'(x), how can i get that from phi? :s since that function cant be differentiated or integrated.. i can construct a taylor polynomial for the function, not sure if thats what im supposed to.. any tips ? :) Thx all!
Actually you can differentiate the function. The function is an integral, so differentiation will simply be removing the integral (and hence return to the Gaussian curve). Knowing that, if you already have a function that gives you the function value of phi, the Newton method can be used. If you don't have a function that returns the value of phi, then you may need to construct a Taylor series approximation to evaluate phi. I'm not sure the rate of convergence for that function though, so it may take quite a few iterations just to get a reliable value for phi.
Aug 21 '07 #3
Deviate
11 Hi, thanks for the reply! :)

Well i realize i can use the secant method, but dont i also have to calculate phi(x)? I mean, what should i set f(x) to be in this case?

Suppose start out choosing x0 and x1 to start the secant method, i would the have to calculate f(x) to be phi(x)-0.1 .. how do i calculate phi(x)? I could either use simpsons rule or create a taylor polynomial ...am i correct? So it would look something like this to start out with:

x2 = x1 - (( x1 - x0 ) / (phi(x1)-0.1) - (phi(x0)-0.1)) * f(x1)

where x1 and x0 are initial values that are chosen by the user, and where phi of these 2 values are calculated using e.g. simpsons rule ?

Thx to anyone who can confirm this for me :)
Aug 21 '07 #4
Deviate
11 hey 2wycked, thx for ur reply :) u just got it in while i was typing mine above, thx for pointing out that in fact u differentiate it by removing the integral, i had sort of overlooked that :p but i think i will just go for the secant method now, since it wont really change alot for me.. the thing is i just have to recode a fuction that can calculate the value of phi for me.. i have done this previously, but unfortunately i have lost the code somewhere.. and i think i will go for using simpsons rule to calculate it, since its a 4th order approximation it should be faster that taylor approx.. also taylor will spin out of control for larger values of x .. do you guys agree? :)

Thx to all for the help!
Aug 21 '07 #5
2wycked
14 hey 2wycked, thx for ur reply :) u just got it in while i was typing mine above, thx for pointing out that in fact u differentiate it by removing the integral, i had sort of overlooked that :p but i think i will just go for the secant method now, since it wont really change alot for me.. the thing is i just have to recode a fuction that can calculate the value of phi for me.. i have done this previously, but unfortunately i have lost the code somewhere.. and i think i will go for using simpsons rule to calculate it, since its a 4th order approximation it should be faster that taylor approx.. also taylor will spin out of control for larger values of x .. do you guys agree? :)

Thx to all for the help!

Certainly. Taylor series aren't the greatest for genral approximations and Simpon's rule has pretty good convergance. Also, because of the symetry and knowing the area under the enitre curve, you get a few places to make some simplifications.
Aug 21 '07 #6