My previous problem is here and I 've done. Laplace equation in 1D with MATLAB - Dirichlet boundary condition
I have the next problem: solve Laplace equation in $1$D with boundary condition $u'(0)=u'(1)=0$
Help me some hints.
Thanks in advanced.
My previous problem is here and I 've done. Laplace equation in 1D with MATLAB - Dirichlet boundary condition
I have the next problem: solve Laplace equation in $1$D with boundary condition $u'(0)=u'(1)=0$
Help me some hints.
Thanks in advanced.
On
@7raiden7 have given you the answer. If you partition the region $[0,1]$ by $N+1$ points, there are $N$ intervals and $N+1$ unknown variables in your numerical scheme. When you discretize your PDE or ODE, you can obtain $N-1$ equations. Both in Dirichlet and Neumann boundary problem, the boundary conditions given you two extra equations. Thus you have $N-1+2=N+1$ equations and same mount variables. Then the problem will be solved.
But I must point out that this is only one of method to deal with the Neumann boundary. Although this one is most widely used and simplest method, there also a lot other methods such as use 2nd order scheme to approximate $u'(x)$ at boundary.
I saw your code there. Just use it, and replace the boundary conditions with the following: $$ u'(0)\approx\frac{u_1-u_0}{\Delta x}, $$ $$ u'(1)\approx\frac{u_M-u_{M-1}}{\Delta x}, $$ where $u_j$ is your numerical solution.
Thus you have: $$ u_0=u_1-u'(0)\Delta x, $$ $$ u_M=u_{M-1}+u'(0)\Delta x. $$
This is a first order approximation. Expand further the Taylor series (using more grid points) to enhance the approximation goodness.
In your specific case: $$ u_0=u_1, $$ $$ u_M=u_{M-1}. $$