Computational issues with the Runge Katta method for ODE first order

40 Views Asked by At

Since the corona virus there are no office hours hence I can only come here for help and the internet got hacked so school email is down. Plus its even harder to get feedback through an email. I am not sure why my answer is off. I am not sure how many times I have to do the method.This took an hour for me to type up because I caught a mistake in my first steps so I had to type this up while doing it on a calculator

$\frac{dy}{dx}=y+1$ where $y(0)=1$ $h=.25$ on the interval $[0,.5]$ round to 5 decimal places

The formulas are:

$k_1=f(x_n,y_n)$

$k_2=f(x_n+\frac{1}{2}h,y_n+\frac{1}{2}hk_1)$

$k_3 = f(x_n+\frac{1}{2}h,y_n+\frac{1}{2}hk_2)$

$k_4 = f(x_{n+1},y_nhk_3)$

$y_{n+1} = y_n+\frac{h}{6}[k_1+k_2+2k_3+k_4]$

Okay here we go:

$k_1 = f(x_n,y_n)=f(0,1)=1+1=2$

$k_2 = f(x_n+\frac{1}{2}h,y_n+\frac{1}{2}hk_1)=f(0+\frac{1}{4}\frac{1}{2},1+\frac{1}{2}\frac{1}{4}2)=f(0 + \frac{1}{8}, 1+\frac{1}{8}2)=f(\frac{1}{8},1+.25) = 1+.25=1.25$

$k_3 = f(x_n + \frac{1}{2}h, + y_n + \frac{1}{2}hk_2)=f(0+\frac{1}{2}\frac{1}{4},1+\frac{1}{2}\frac{1}{4}1.25)=f(0+\frac{1}{8},1+\frac{1}{8}1.25)=f(\frac{1}{8},1+.15625)=1+1.15625=2.15626$

$k_4=f(x_n+1,y_nhk_3)= f(.25,1+\frac{1}{4}2.15626)=f(.25,1+.53907)=1+1.53907=2.53907$

$y_{n+1}= y_n + \frac{h}{6}[k_1+2k_2+2k_3+k_4]=1 +\frac{.25}{6}[2+[2(1.25)]+[2(2.15626)]+2.93507]=1+.04167[2+2.5+4.31252+2.93507]=1+.41607[11.74759]=1+.48952=1.48952$

so we have $y_1=1.48952$

Now I assume I do the whole thing over with $y(.25)=1.48952$

$k_1= f(.25,1.48952)=1+1.48952=2.48952$

However I run into the problem that the answer is supposed to be $2.29740$...I am already over the answer on my first iteration.....I assume that I am supposed to do the two iterations stop at $y_2$I don't understand what I am doing wrong...

1

There are 1 best solutions below

5
On BEST ANSWER

The provided function is $f(x,y)=\color{red}{1+{}}y$. You seem to have dropped the $+1$ on several steps.

Fixing it, you should get for $n=0:$

$k_1=2\\k_2=9/4=2.25\\k_3=73/32=2.28125\\k_4=329/128\simeq2.57031$

Which gives us $(1/4,4817/3072)\simeq(0.25,1.56803)$ as our next point.

I leave the next step for you to verify.

Also it would seem you made a typo in the definition of $k_4$.