- #1

member 428835

## Homework Statement

Write an implicit Euler code to solve the system ##c'(x) = \epsilon c''(x)-kc(x)## subject to ##1-c(0)+\epsilon c'(0) = 0## and ##c'(1)=0##.

## Homework Equations

Nothing out of the ordinary comes to mind.

## The Attempt at a Solution

In the following code, there is central difference implicit Euler being used, taking the form ##A*Y=B## where ##Y = [c_0,c_1...c_{N+1}]^T##. I understand the procedure except when considering the boundary conditions. I marked the three lines corresponding to this confusion with a HOW TO ARRIVE comment. This isn't the entire script, but this is the part I need help with. There is the BC at ##x=1## but I think if I understand how the ##x=0## BC works I can figure out ##x=1##.

Code:

```
A=zeros(nstep+1,nstep+1); % initialize A matrix (A*Y=B)
B=zeros(nstep+1,1); % initialize B matrix
% components of the matrix A (A*Y=B)
a1=eps/h^2+1/(2*h);
b1=-2*eps/h^2-k;
c1=eps/h^2-1/(2*h);
% configuration of the matrix A
A(1,1)=b1-a1*2*h/eps;% HOW TO ARRIVE
A(1,2)=c1+a1;% HOW TO ARRIVE
B(1,1)=-2*a1*h/eps;% HOW TO ARRIVE
for i=2:N
A(i,i-1)=a1;
A(i,i)=b1;
A(i,i+1)=c1;
end
A(N+1,N)=a1+c1;
A(N+1,N+1)=b1;
AI=inv(A); % matrix inversion by Matlab func.
Y=AI*B; % final solution of y
```