online advertising
Processing math: 100%

Saturday, November 21, 2015

Scientific Computing - Quiz 1 - Question 6

Problem:

Walk through one time-step of 4th-order Runge-Kutta with simple differential equation system y=y, y(0)=1 and Δt=2.
Identify the correct values for f1; f2; f3; f4 and y(2).

Solution:

It is always good to know the solution to the differential equation first, in this case it is really easy.

dydt=y1ydydt=11ydydtdt=1dtlogy=t+C1y=et+C1=C2et

Now the initial condition decides C2=1, making the solution simply y=et.

The analytic solution is not required, it is just that it is a perfect guide for us to evaluate whether our solution make sense. Now, looking up the Runge-Kutta equations, we have

f1=f(tn,yn)
f2=f(tn+Δt2,yn+Δt2f1)
f3=f(tn+Δt2,yn+Δt2f2)
f4=f(tn+Δt,yn+Δtf3)

Next, we substitute f(t,y)=y in the expressions above, then we get:

f1=yn
f2=yn+Δt2f1
f3=yn+Δt2f2
f4=yn+Δtf3

Excel will just happy to crank those answers for us now.

The final answer is

f1=1
f2=2
f3=3
f4=7
y(2)=7.

With excel, I fiddled around the parameter. In particular, I tried to tune Δt to 0.1 and iterate 20 times, the result has 1.1×105 error only. It is in fact quite accurate.

As an aside to the analytic solution - the integral of 1ydy=logy only make sense when y>0. To make sense of cases when y<0, we can take the sign out first before the integration and the expression become log|y|=sign(y)t+C1e|y|=e|sign(y)|et+C1ey=et+C1 and the rest follows as is.

No comments:

Post a Comment