Initial value problem, finite differences

Telemachus
Messages
820
Reaction score
30

Homework Statement


Given an initial value problem:

##x'(t)=f(t,x)\,,x(t_0)=x_0##

Use centered finite differences to approximate the derivative, and deduce a scheme that allows to solve the (ivp) problem.

Homework Equations



For centered finite differences ##\displaystyle\frac{dx}{dt} \approx \frac{x(t+h)-x(t-h)}{2h}##

The Attempt at a Solution


[/B]
First, I discretized the variable t: ##t_i=t_0+ih, \forall i=0,1,2,...,N##

So then, using the formula for finite differences, and calling ##x(t_i)=x_i##

I've obtained:
##x_{i+1}-x_{i-1}=2hf(t_i,x_i)##

The problem is that if I try some test function ##f(x,t)## I think that the ivp gives inssuficient data to solve the problem, I get more ##x_i's## than equations when trying to solve. So I think I'm doing something wrong.
 
Last edited:
Physics news on Phys.org
You're right. If you only consider the ##x_k## for ##k=0,1,...,n## and ##x'_k## for ##k=1,...,n-1## then, since ##x_0## is given, you have ##(n+1)+(n-1)=2n## unknowns and ##1 + (n-1) + (n-1)=2n-1## equations, so you are one equation short.

Why not extrapolate on second differences? If you bring in unknowns ##x_{-1}, x'_0, x''_1,x''_2,x''_3## then you have five more unknowns.
Add an equation that expresses ##x''_1## as an extrapolation from ##x''_2,x''_3##.
Then you can get the needed additional five equations from the relationships between ##x'_k,\ x''_k,\ ## and ##x_k## in the time steps from -1 to 5, plus using the value of ##x'_0=f(t_0,x_0)##.
 
  • Like
Likes Telemachus
Thank you verymuch for your answer. I don't know if that's the purpose of the exercise, we have only worked with differential equations of first order in this course. Any other idea? how much error would I introduce if I set, for example ##x_1=0##? I think that wouldn't be more fictitious than interpolating to second order, it would give a second boundary condition. Perhaps working with forward finite differences would solve the problem, but it asks to do it with centered differences.
 
If you don't want to go to second differences, the next best thing I can think of is to add the equation
$$x_1=x_0+hx'_0=x_0+hf(t_0,x_0)$$
That would be less accurate than using second differences because it assumes curvature (second derivative) is zero at ##t_0##. How much less accurate would depend on the curvature.

By the way, using second differences does not change the nature of the differential equation to second order. It remains first order. You are just using an additional term of the Taylor Series in approximating the values of ##x_k##.
 
  • Like
Likes Telemachus
Can you help me to extrapolate to second order then? I'm not sure how to do that.
 
From ##x'(t) = f(t,x(t))## we have
x''(t) = f_t(t,x(t)) + f_x(t,x(t)) x'(t) = f_t(t,x(t)) + f_x(t,x(t)) f(t,x(t)),
where ##f_t = \partial f/ \partial t## and ##f_x = \partial f/ \partial x##. Thus,
x''(0) = f_t(0,x_0) + f_x(0,x_0) f(0,x_0)
Use this, plus ##x'(0) = f(0,x_0)## in the expansion
x(0+h) \doteq x_0 + x'(0) h + \frac{1}{2} x''(0) h^2
 
  • Like
Likes Telemachus
Thank you verymuch. How do I use this last result in the finite difference scheme I've posted before?

From this I would deduce the value for ##x_{1}##?
 
Last edited:
The following is a simple linear extrapolation that assumes a constant third derivative at ##t_2##. First add the three centred difference equations
$$x''_k=\frac{x'_{k+1}-x'_{k-1}}{2h}$$
for ##k=2, 3##. Then add the extrapolation equation
$$x''_1=x''_2-(x''_3-x''_2)$$
That's four extra equations for only three extra unknowns.

An even simpler, slightly less accurate, approach would just add the unknowns ##x''_1,x''_2##, the associated two difference equations, and an equation ##x''_1=x''_2##.

Actually, I've just read Ray's post, and I like his solution better, because it uses the information embedded in the function ##f##, whereas mine doesn't. I suggest you use that. And in answer to your most recent question, yes, that last formula in his post will give you the value of ##x_1##.
 
  • Like
Likes Telemachus
Thank you verymuch to both of you.
 
Back
Top