Crank-Nicolson Method: Solving Homework Equations

In summary, the conversation is about the use of the Crank-Nicolson method to solve a thermodynamics problem involving heat transfer in a 1m bar with a 100K temperature and both ends placed against a 0K sink. The person is struggling to understand the method and is looking for resources or help in setting up the base equations for the method. They have attempted to code a program using gaussian elimination, but their matrix seems to be incorrect. They have also come to the realization that they were expecting a PDE to have a base equation, but it seems that is not the case for Crank-Nicolson. They are looking for any guidance or examples on solving problems using this method.
  • #1
Rapier
87
0

Homework Statement


So I'm back to my wonderful computational physics course after a brief hiatus and once again, I am teaching myself the material. This unit we are working on some thermodynamics. We've just used the "Leap Frog" method to determine heat transfer of a 100k bar with both ends put in touch with a 0k sink. No problems there. The next part of the assignment is to use the Crank-Nicolson method to solve the same problem (1m bar, 100K, each end placed against a 0K sink). Our instructor and course material seem to believe that we should all be intimately familiar with Crank and Nicolson, but until now I would have thought them a body shop or law office.

Apparently the method requires some use of a guassian elimination and matrices. So I'm gone ahead and coded a program that solves a gaussian elminiation. So now my only problem is determining what the base equations are that will populate this matrix. I've been doing quite a bit of digging but I'm just not getting it. None of my textbooks I have hear speak of Crank-Nicolson. Could any link me or work through not even this problem but any problem with setting up Crank-Nicolson? What are the basic equations I'm supposed to be using?

Homework Equations


From the class slides I have:
T(i, j+1) - T(i,j) = η/2 [T(i-1,j+1) - 2T(i,j+1) + T(i+1,j+1) + T(i-1,j) - 2T(i,j) + T(i+1,j)
-T(i-1,j+1) + (2/η + 2)*T(i,j+1) - T(i+1,j+1) = T(i-1,j)+(2/η - 2)*T(i,j) + t(i+1,j)

The Attempt at a Solution


Obviously T is the temperature and T(i,j) refers to the temperature at position i (assuming that the left side of the bar is at 0 and the right side is at 1m) and j is the time elapsed since the start (this was how we defined the problem in the first portion so I can't imagine that has changed). Personally I've been using T(x,t) because that seems to make a whole heck of a lot more sense to me than i and j.

I'm kind of lost. If I could just see how any Crank-Nicolson problem was solved I think I could do it. But I'm trying to create code based off a half-assed stab at instruction and no fore-knowledge of the method in question. Please help!
 
Physics news on Phys.org
  • #2
Google is your friend here. Just search using "Crank-Nicolson method" and you'll get plenty of hits and even a few examples using the method to solve a heat equation problem.
 
  • #3
With all due respect, saying "Google it" isn't exactly helpful. I have been Googling and while I still am not positive, I believe that my issue was that I was expecting a PDE to actually have some kind of equation at the base. I am getting the impression that (at least in this case) that isn't true. We've previously done the Jacobi relaxation and forward looking (and backwards looking) and I always thought, wouldn't this be more accurate if we included this side points as well? Clearly the answer is "YES!" So I grasped CN before I knew who either of them was.

So, this is my understanding:

I have a 1m bar at 100K and each end is placed against a 0K sink. For simplicity, I'll use .2m divisions. My initial state looks like:

0 100 100 100 100 0 for future reference this will be 0 A B C D 0.

Given the initial condition I can calculate the next time interval as so, given:

0 A B C D 0
0 E F G H 0

The temp at E will be the average of (0 + A + B + E + 0 + F). The problem is that I don't have a value for F because F is the average of (A + B + C + E + F + G) and I don't have G because G is the average of (B + C + D + F + G + H) and H is the average of (C + D + 0 + G + H + 0). So the problem with CN is that all the equations for the next time interval must be solved simultaneously. Thus we have a system of equations that can be solved using a gaussian elimination.

E = 100 + 100 + E + F = 1E + 1F + 0G + 0H + 200
F = 100 + 100 + 100 + E + F + G = E + F + G = 1E + 2F + 1G + 0H + 500
G = 100 + 100 + 100 + F + G + H = 1E + 2F + 2G + 1H + 800
H = 100 + 100 + G + H = 1E + 2F + 2G + 2H + 1000

So my matrix is:
1 1 0 0 -200
1 2 1 0 -500
1 2 2 1 -800
1 2 2 2 -1000

But if I solve that I get:
E = 0
F = -200
G = -100
H = -200

Which is nonsense. So clearly my matrix is screwed up.
 
Last edited:
  • #4
Rapier said:
With all due respect, saying "Google it" isn't exactly helpful. I have been Googling and while I still am not positive, I believe that my issue was that I was expecting a PDE to actually have some kind of equation at the base.

It's not clear what you mean by "a PDE to actually have some kind of equation at the base."

CN is a method to convert a PDE into a set of algebraic equations using finite differences instead of partial differentials or some other form of discretization like a finite element method.

IDK what kind of hits you got with your google search, but mine turned up a couple of articles on CN being used to solve a heat equation problem:

http://people.sc.fsu.edu/~jpeterson/5-CrankNicolson.pdf

http://web.cecs.pdx.edu/~gerry/class/ME448/notes/pdf/CN_slides.pdf

https://www.google.com/search?q=crank-nicholson&ie=utf-8&oe=utf-8

I'm sure if you add more descriptive search terms besides "Crank-Nicholson", you may obtain hits more pertinent to your problem.
 
  • #5
SteamKing said:
IDK what kind of hits you got with your google search, but mine turned up a couple of articles on CN being used to solve a heat equation problem:

http://people.sc.fsu.edu/~jpeterson/5-CrankNicolson.pdf

These are the same things I've been looking at. Let's just go ahead and assume for future reference that I know how to Google. Googling solutions is a lot easier than typing all of this up. While I may not have specifically and explicitly said so in my initial post, the "I've been doing quite a bit of digging but I'm just not getting it." referred to Google searches and actual searches through the few textbooks I have access to. So let's further assume that I've already done the Googling. I don't need help in how to use a search engine.

This particular link does not solve a problem. It outlines the theory behind CN. I get the theory behind CN. I understand what the purpose of it is, how it works and why it is better than the other methods. The difficulty I am having is turning that theory into a set of equations that I can use to populate a matrix.This link discusses the theoretical aspects of using CN to solve a problem. This is also why I requested in my initial post a worked through solution. So that I could see how one translates the theoretical into actual results.

SteamKing said:
http://web.cecs.pdx.edu/~gerry/class/ME448/notes/pdf/CN_slides.pdf[/QUOTE][/URL]

While this was one of the more useful links I found still does not actually solve a problem but just lays out the theory behind how one goes about using CN to solve a problem.

[URL='https://www.google.com/search?q=crank-nicholson&ie=utf-8&oe=utf-8']
SteamKing said:
https://www.google.com/search?q=crank-nicholson&ie=utf-8&oe=utf-8
SteamKing said:
SteamKing said:
I'm sure if you add more descriptive search terms besides "Crank-Nicholson", you may obtain hits more pertinent to your problem.

My last response was rather detailed and went through an attempt at a solution and laid out my understanding of the problem. If you would like to comment on that, I would appreciate it. However, pasting in a bunch of links from Google isn't helping.
 
Last edited by a moderator:
  • #6
It's hard for me to understand what more you want than what is in, e.g., http://web.cecs.pdx.edu/~gerry/class/ME448/notes/pdf/CN_slides.pdf

On page 6, equation (3) gives you explicitly what you need. The RHS depends only on the known solution at step k, the matrix on the LHS is the thing you keep saying you are looking for, and the vector u is the unknown at step k+1 you are looking for. This is a problem of type ##A x = b##, which I gather you know how to solve.
 

1. What is the Crank-Nicolson method?

The Crank-Nicolson method is a numerical method used to solve differential equations, specifically partial differential equations. It is a combination of the explicit and implicit methods, and is known for its accuracy and stability.

2. How does the Crank-Nicolson method work?

The Crank-Nicolson method works by taking the average of the explicit and implicit methods. It uses a finite difference approximation to discretize the differential equation into a system of linear equations, which can then be solved using matrix operations. The method is based on the trapezoidal rule and uses a half-step time difference to improve accuracy.

3. What types of equations can the Crank-Nicolson method solve?

The Crank-Nicolson method can solve both parabolic and hyperbolic partial differential equations. It is particularly useful for solving diffusion-type equations, such as heat transfer and diffusion of particles in fluids.

4. What are the advantages of using the Crank-Nicolson method?

The Crank-Nicolson method has several advantages. It is unconditionally stable, meaning that it can handle a wide range of time steps without causing instability in the solution. It is also second-order accurate, which means that it provides a more accurate solution compared to other methods. Additionally, it is relatively easy to implement and has a low computational cost.

5. Are there any limitations to the Crank-Nicolson method?

The Crank-Nicolson method is not suitable for solving stiff equations, as it can be computationally expensive for these types of equations. It also may not be the best choice for problems with rapidly changing solutions. Additionally, the method may not work well for problems with irregular or discontinuous boundaries.

Similar threads

  • Advanced Physics Homework Help
Replies
1
Views
1K
  • Advanced Physics Homework Help
Replies
6
Views
4K
  • Differential Equations
Replies
23
Views
2K
  • Advanced Physics Homework Help
Replies
1
Views
951
Replies
2
Views
1K
  • Advanced Physics Homework Help
Replies
2
Views
1K
  • Advanced Physics Homework Help
Replies
4
Views
1K
  • Differential Equations
Replies
3
Views
1K
  • Precalculus Mathematics Homework Help
Replies
18
Views
587
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
3K
Back
Top