0

I would like to evaluate cumulative normal (0,1)-distribution values using Runge-Kutta method but the problem is that I don't know how to apply the method. Namely, if I have that $y'(x)=e^{-x^2/2}, y(0)=1/2$ and $y(3)$ is the value I would like to know, then how can I form the value $f(x_n,y_n)$ given for example in Råde, Westergren, Mathematical Handbook for Science and Engineering as it has two parameters, not just one?

2 Answers2

0

From the book Numerical Recipes, third edition, section 4.0:

The evaluation of the integral

$I=\int_a^b f(x) dx$

is precisely equivalent to solving for the value $I\equiv y(b)$ the differential equation

$\frac{dy}{dx}=f(x)$

with the boundary condition

$y(a)=0$

So you can apply Runge-Kutta to solve the above differential equation.

0

If you haven't done it yet, here's simple matlab code, even though there's a ready-to-go erf function in matlab.

function test
x0 = 0;
xn = 3;
N  = 2000;
x = linspace(x0,xn,N+1);
h = x(2)-x(1);
y = zeros(1,N+1);
y(1) = 0.5;
for i = 2:N+1
    k1 = f(x(i-1),     y(i-1));
    k2 = f(x(i-1)+h/2, y(i-1)+h/2*k1);
    k3 = f(x(i-1)+h/2, y(i-1)+h/2*k2);
    k4 = f(x(i-1)+h,   y(i-1)+h*k1);
    y(i) = y(i-1) + h*(k1+2*k2+2*k3+k4)/6;
end
plot(x,y)

function val = f(x,y)
val = 1/sqrt(2*pi)*exp(-x^2/2);
Kaster
  • 9,722