Solving second order differential equation with finite difference method (boundary conditions)

380 Views Asked by At

Hello I am trying to solve this second order differential equation:

$$r\frac{d^{2}y}{dr^{2}}+\frac{dy}{dr}=0$$

where $0\le r\le 1$, with the following boundary conditions:

$$r=0, y=200$$ $$r=1, y=36$$ $$c\frac{dy}{dr} = \beta(y-y_{b}), r=1$$

where c and beta are constants. For the outer boundary, the discretization is (only for the outer boundary):

$$\frac{dy}{dr}=\frac{3y_{n}-4y_{n-1}+y_{n-2}}{2h}, (r_{n}=1)$$

I want to use finite difference method to solve this problem. I have tried to use central differences of the second and first derivatives with the following forumlas:

$$f′(x)≈\frac{f(x+h)−f(x−h)}{2h}$$ $$f''(x)≈\frac{f(x-h)−2f(x)+f(x+h)}{h^{2}}$$

When inserting in the differential equation I get:

$$(r-\frac{h}{2})y_{j-1}-(2r)y_{j}+(r+\frac{h}{2})y_{j+1} = 0$$

and when inserting j=1 and using the initial boundary conditions I get:

$$-(2r)y_{1}+(r+\frac{h}{2})y_{2} = -(r-\frac{h}{2})*200$$

and for the outer boundary condition I get:

$$\frac{1}{2h}y_{j-2}+(\frac{r}{h^{2}}-\frac{4}{2h})y_{j-1}+(\frac{3}{2h}-\frac{2r}{h^{}})y_{j}+(\frac{r}{h^{}})y_{j+1}=0$$

but then I don't know what to do next. I am not sure if my calculations are right because I get zeros on the right hand vector (except for the boundaries) which seems strange. Can someone please help me and see where I have gone wrong? Thank you.