Errors in computing the Crank-Nicolson Method

In summary: The author is trying to adapt the Crank-Nicolson algorithm to solve a one-dimensional heat equation with trivial boundary conditions. However, the results are not satisfactory. He is looking for someone to help him resolve the discrepancy.
  • #1
danielakkerma
231
0
Hi all!
Having decided to return to coding some of the physical problems that I require solving(in lieu say, of Mathematica), I endeavored to adapt the Crank-Nicolson to my needs, but, in order to test my algorithm, I had first attempted to resolve the common and trivial heat equation, in one dimension, e.g [tex] \alpha\frac{\partial^2u}{\partial x^2} = \frac{\partial u}{\partial t} [/tex], with some plain boundary conditions, that is u(x, 0) = some trivial function(sine times cosine) and u(0, t) = 10(or some value), and at the end-point(10, t in this case), the same(essentially a rod kept at both ends at an equal temperature).
The results however, are unsatisfactory; For sake of my equation, I used:
[tex] \beta u^{i+1}_{j+1}+(1+2\beta)u^{i+1}_{j}+\beta u^{i+1}_{j-1}=u^{i}_{j} [/tex]
Where beta is a constant derived from my step sizes(i.e, dx, dt) and i & j denote the step in time and displacement respectively.
This, as is well known, creates a tridiagonal system, which is readily evaluated for all U(i+1)ns(in my case, I've got a grid with a size of 100 units).
I've attached two graphs corresponding to the solutions; Image2 was created by Mathematica, and Image1 is done using my program. You can see the very disturbing groove that's created, that seems to wedge and ebb towards the margins of the computational region. This is, first-and-foremost, physically inaccurate, and should not occur, and in fact, using Mathematica, does not.
In short, I am reliant on your aid to solve this discrepancy,
I thank you for your attention,
Beholden,
Daniel
 

Attachments

  • Image1.gif
    Image1.gif
    12 KB · Views: 522
  • Image2.gif
    Image2.gif
    7.8 KB · Views: 513
Technology news on Phys.org
  • #2
One obvious difference between the plots is that the slope of the function at the left and right edges is different.

In the right hand plot the slopes apparear to be constrained to be 0, in the left hand plot they are not.

It's not very clear from your description of the problem or from the the plots (no labels on the axes) exactly what you were trying to do, but I would guess the boundary conditions are different in your code and in Mathematica.
 
  • #3
You're absolutely right on the matter, and indeed, correct, or rather, setting the proper Dirichlet boundary conditions aligned the two!
Thank you for your help!
Daniel
 

Related to Errors in computing the Crank-Nicolson Method

1. What is the Crank-Nicolson method?

The Crank-Nicolson method is a numerical technique used to solve partial differential equations (PDEs). It is a combination of the forward and backward Euler methods, and it provides a more accurate solution compared to these methods by taking into account both present and future time steps.

2. What are the sources of errors in computing the Crank-Nicolson method?

There are several sources of errors in computing the Crank-Nicolson method, including truncation error, round-off error, and stability error. Truncation error occurs due to the use of finite difference approximations, round-off error is caused by the limited precision of computer arithmetic, and stability error arises when the time step chosen is too large.

3. How can truncation error be reduced in the Crank-Nicolson method?

Truncation error can be reduced by using a smaller time step and a finer mesh size. This will result in a more accurate approximation of the PDE solution. Additionally, higher-order finite difference schemes can also be used to reduce truncation error.

4. What is the effect of round-off error on the Crank-Nicolson method?

Round-off error can lead to inaccuracies in the computed solution. It can accumulate over time steps and affect the overall accuracy of the solution. To minimize round-off error, it is important to use a computer with a higher precision arithmetic or to implement error-reducing techniques such as Richardson extrapolation.

5. How can stability error be avoided in the Crank-Nicolson method?

To avoid stability error, the time step chosen should be within a certain range known as the stability limit. This limit depends on the properties of the PDE being solved and can be determined through stability analysis. Generally, using a smaller time step and a finer mesh size can help to ensure stability in the Crank-Nicolson method.

Similar threads

  • Programming and Computer Science
Replies
5
Views
3K
  • Programming and Computer Science
Replies
6
Views
1K
  • Differential Equations
Replies
2
Views
2K
  • Differential Equations
Replies
8
Views
4K
Replies
1
Views
1K
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
3K
  • Programming and Computer Science
Replies
4
Views
4K
  • Programming and Computer Science
Replies
1
Views
1K
Replies
19
Views
1K
Back
Top