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?
Asked
Active
Viewed 1,339 times
0
-
You should apply RK method directly as described here, it's quite straightforward. You can post here which part exactly remains unclear, if any. Otherwise, it looks like you are requesting the code. – Kaster Oct 21 '13 at 21:31
-
Also, in your case $f(x,y) = f(x)$, so $f(x_n, y_n) = f(x_n)$. – Kaster Oct 21 '13 at 21:31
-
Ah, that part $f(x,y)=f(x)$ was the part I wanted to know. Thanks! – Beginnerprogrammer Oct 21 '13 at 21:33
2 Answers
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.
Alessandro Jacopson
- 1,028
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