# Homework Help: Ordinary differential equation with boundary value condition

Tags:
1. Nov 13, 2015

### Linder88

1. The problem statement, all variables and given/known data
Consider the boundary value problem

u''(t)=-4u+3sin(t),u(0)=1,u(2)=2sin(4)+sin(2)+cos(4)

2. Relevant equations
Derive the linear system that arise when discretizating this problem using

u''(t)=\frac{u(t-h)-2u(t)+u(t+h)}{h^2}

where h=0.5 is the step length.
3. The attempt at a solution
Evaluate the second derivative at the first boundary

u''(0)=-4u(0)=-4

Now if iterating with step length h=0.5 we should have
for t=1:100

\begin{cases}
u''(t)=-4u(t)+3sin(t)\\
u(t+1)=u(t)+h^2u''(t)
\end{cases}

end
When I do this iteration in I don't end up at u(2)=2sin(4)+sin(2)+cos(4) which make me conclude that I am doing something wrong. Can somebody please explain how I should use Equation (2) to calculate the next value?

Last edited: Nov 13, 2015
2. Nov 13, 2015

### Staff: Mentor

I don't know where your second equation above comes from. Let's assume for the moment that it is correct. The main problem I see is that your step of h = 0.5 is way too large. Your interval is [0, 2]. If you divide that into 100 subintervals, each is of length .02. Possibly h is half of that, or h = .01.
When t = 100, you are calculating u(101), not u(2).

Also, do you mean equation 10 rather than equation 45? That equation is only an approximation, with closer values for smaller values of h.

3. Nov 13, 2015

### Linder88

Well, the original question looks like in the attached picture. Let me know if it doesn't work or if you can't see it. I am excited to hear your comments on the questions.

#### Attached Files:

• ###### Screenshot_2015-11-13-20-57-46.png
File size:
36.9 KB
Views:
76
4. Nov 13, 2015

### Staff: Mentor

I believe that the first part ("Derive the linear system that arise when discretizating this problem using... h = 0.5") is
$u''(.5) = \frac{u(0) - 2u(.5) + u(1)}{(.5)^2}$
$u''(1) = \frac{u(.5) - 2u(1) + u(1.5)}{(.5)^2}$
$u''(1.5) = \frac{u(1) - 2u(1.5) + u(2)}{(.5)^2}$
I could be wrong, but I think this is what they're looking for.
For the other part, take a look at the Matlab code that is mentioned in the problem statement in your book.

5. Nov 13, 2015

### Linder88

Thank you, this at least gives me something to write in the report :)

Last edited by a moderator: Nov 13, 2015
6. Nov 13, 2015

### Staff: Mentor

You should also look in your textbook and class notes for a similar problem to see how it was done.

7. Nov 13, 2015

### Ray Vickson

No: you do not have $u(t+1)=u(t)+h^2u''(t)$; if anything, you should have $u(t+h) \approx u(t) + h u'(t) + \frac{1}{2} h^2 u''(t)$. However, when you make the finite-difference approximation to $u''(t)$ and substitute that into the DE, you will get an equation linking $u(t-h), u(t)$ and $u(t+h)$, so if you know $u(0)$ and $u(h)$ you can get $u(2h)$, then $u(3h)$, etc. However, this is a so-called two-point boundary value problem (because your boundary conditions are given at two separate point $t = 0$ and $t = 2$), so your condition at $t = 0$ is not enough, by itself. You do know $u(0)$, so if you assume a value $u(h)= c$ as an unknown problem parameter, you will be able to carry out all the iterations in terms of a symbolic $c$, until you reach $t = 2$. At that point you will have $u(2)$ expressed as a linear function of the parameter $c$, so you get an equation that determines $c$.

Last edited: Nov 13, 2015