Finite difference method - Second order equation with special conditions

4 views (last 30 days)
Hello I am trying to solve this problem with the finite difference method.
(1)
Where and
with the following conditions:
(2)
(boundary condition when r = 2)
and this discretization when r = 2 (and only then!)
(3)
My attempt so far is to use central difference approximation with (1) and using (3) instead of first order derivative only for the last approximation (N=Nend). But when I write down the matrix I only get 0's in the b-vector (Ay = b) which feels very wrong. I have no clue how I should use (2) either. Can someone help me to think in the right direction here? Thank you.
  2 Comments
Torsten
Torsten on 28 Mar 2022
Edited: Torsten on 28 Mar 2022
You are not allowed to use bvp4c ?
What is your boundary condition at r=1 ?
Casper Hae
Casper Hae on 28 Mar 2022
Edited: Casper Hae on 28 Mar 2022
I don't know what bvp4c is and we've never used it. But it says in the task that we should use finite difference method
The boundary condition at r=1 is

Sign in to comment.

Answers (1)

Torsten
Torsten on 28 Mar 2022
Edited: Torsten on 28 Mar 2022
As your equation can be written as
1/r * d/dr (r*dT/dr) = 0
the usual discretization in r = r_i is
1/r_i * [(r_i + dr/2)*(T(r_(i+1))-T(r_i))/dr - (r_i - dr/2)*(T(r_i)-T(r_(i-1)))/dr] = 0,
thus
(ri + dr/2)*(T(r_(i+1))-T(r_i)) - (r_i - dr/2)*(T(r_i)-T(r_(i-1))) = 0 (2 <=i <= n-1)
The boundary condition at r = 1 gives
T(r_1) = T_a
The discretization at r_n of the differential equation gives
r_n*dT/dr(r_n) - (r_n-dr/2)*dT/dr(r_n-dr/2) = 0
Inserting
dT/dr(r_n) = -alpha/k*(T(r_n)-T_b)
from the boundary condition and discretizing
dT/dr(r_n-dr/2) = (T(r_n)-T(r_(n-1))/dr
leads to
r_n * alpha/k*(T_b-T(r_n)) - (r_n - dr/2)*(T(r_n)-T(r_(n-1))/dr = 0
or
T(r_n)*r_n*alpha/k + (r_n - dr/2)*(T(r_n)-T(r_(n-1))/dr = r_n*alpha/k*T_b
Thus the vector of the right hand side is not zero - it has entries at the first and last position coming from the boundary values.
  42 Comments
Casper Hae
Casper Hae on 6 Apr 2022
Edited: Casper Hae on 6 Apr 2022
Alright. So when discretizising with this discretization at r=b you don't have to account for eq (1) at all? Then it's so much easier lol.
Also, it is very weird that when I change to your last discretization in r=b the order of accuracy of the method suddenly drops to 1. It's like the new discretization has an order of accuracy of 1 (even though it says that it has 2)... do you know why?
Torsten
Torsten on 6 Apr 2022
Edited: Torsten on 6 Apr 2022
Also, it is very weird that when I change to your last discretization in r=b the order of accuracy of the method suddenly drops to 1. It's like the new discretization has an order of accuracy of 1 (even though it says that it has 2)... do you know why?
No, because the code i posted gives order 2 for both discretizations. Must be something wrong with your evaluation.
But you previously wrote that you got order 1 for the "old" discretization, too. Now you write that the order of accuracy "suddenly drops to 1". Did your result for the order of the "old" discretization change meanwhile ?

Sign in to comment.

Products


Release

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!