Crank-Nicolson Method: Solving Homework Equations

AI Thread Summary
The discussion revolves around using the Crank-Nicolson method for solving heat transfer equations in a computational physics course. The user has successfully implemented the Leap Frog method but struggles with the Crank-Nicolson approach, particularly in setting up the necessary equations for a matrix that requires simultaneous solutions. They express frustration over the lack of clear guidance in textbooks and online resources, despite extensive searching. The conversation highlights the need for a better understanding of how to translate theoretical concepts into practical equations for matrix population. Ultimately, the user seeks a worked example to clarify the application of the Crank-Nicolson method in their specific problem context.
Rapier
Messages
83
Reaction score
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
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.
 
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:
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.
 
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:
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.
 
Thread 'Help with Time-Independent Perturbation Theory "Good" States Proof'
(Disclaimer: this is not a HW question. I am self-studying, and this felt like the type of question I've seen in this forum. If there is somewhere better for me to share this doubt, please let me know and I'll transfer it right away.) I am currently reviewing Chapter 7 of Introduction to QM by Griffiths. I have been stuck for an hour or so trying to understand the last paragraph of this proof (pls check the attached file). It claims that we can express Ψ_{γ}(0) as a linear combination of...
Back
Top