solve pde with neumann boundary conditions
56 views (last 30 days)
Show older comments
Good mornirg.
I have to solve a PDE: dydt=-vdydx+Dd2ydx2+Ay. The boundary condition are y=cost whent x=0 and dy/dt=0 when x=L; whereas the initial condition y=0 when t=0.
I use the method of line to solve the problem. So I rewrite the equation as dydt=-v/h*(y(i)-y(i-1))+D/h^2(2y(i-1)-2y(i)+A(i).
How can I write the boundary condition at x=L dydx=0?
thank you
1 Comment
Evelyn
on 8 Mar 2023
To incorporate the Neumann boundary condition of dy/dx = 0 at x=L, we can use a backward difference approximation. Specifically, we can approximate the derivative at the last grid point using the following formula:
dy/dx ≈ (y(i) - y(i-1))/h
At x=L, this approximation gives:
dy/dx ≈ (y(n) - y(n-1))/h = 0
where n is the total number of grid points. Solving for y(n-1), we get:
y(n-1) = y(n)
Therefore, we can incorporate the Neumann boundary condition into our finite difference equation by replacing the expression for dy/dx at x=L with:
(y(n) - y(n-1))/h = 0
which simplifies to:
y(n) = y(n-1)
Substituting this expression into our finite difference equation for the second derivative term at x=L, we get:
D/h^2 (2y(n-1) - 2y(n) + A(n)) = 0
Solving for y(n-1), we obtain:
y(n-1) = y(n) - A(n)h^2/2D
Therefore, we can use this expression for y(n-1) in our finite difference equation to incorporate the Neumann boundary condition into the numerical solution of the PDE.
___
Answers (1)
Torsten
on 15 Jan 2019
Edited: Torsten
on 15 Jan 2019
At the right boundary (x=x_n)
D^2y/dx^2 ~
(dy_n/dx - dy_(n-1/2)/dx) /(x_n-x_(n-1/2)) ~
(dy_n/dx - (y_n-y_(n-1))/(x_n-x_(n-1)))/(x_n-x_(n-1/2))
Thus with your boundary condition dy_n/dx = 0 you get the ODE
dy_n/dt = D*(- (y_n-y_(n-1))/(x_n-x_(n-1)))/(x_n-x_(n-1/2)) + A*y_n
with x_(n-1/2) = (x_n+x_(n-1))/2
0 Comments
See Also
Categories
Find more on Boundary Conditions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!