Crank-Nicolson method for a parabolic differential equation

Click For Summary

Homework Help Overview

The discussion revolves around the Crank-Nicolson method applied to a parabolic differential equation, specifically the equation du/dt = d²u/dx² - 2. Participants are exploring how to implement this in MATLAB, particularly how to incorporate the constant term -2 into their existing code.

Discussion Character

  • Exploratory, Mathematical reasoning, Problem interpretation

Approaches and Questions Raised

  • Participants are attempting to adapt existing MATLAB scripts for solving a parabolic PDE, questioning how to modify the code to account for the constant term -2. Some are discussing the implications of boundary and initial conditions, while others are exploring the setup of the problem and the necessary adjustments to the numerical method.

Discussion Status

There is an ongoing exchange of ideas, with some participants providing links to resources and others sharing snippets of code. A few suggestions have been made regarding how to approach the implementation, but there is no clear consensus on the best method to incorporate the constant term or to achieve steady-state conditions.

Contextual Notes

Participants are working under specific constraints related to their assignment, including the requirement to use a certain number of steps and to plot representative profiles for temperature. There are also boundary conditions specified for the problem, which are influencing the discussion on how to proceed with the numerical solution.

jamesponty
Messages
4
Reaction score
0
Hi,

Just wondering if somebody could point me in the right direction.

I have the parabolic differential equation:

du/dt=d2u/dx2 -2

I need to get a MATLAB script to solve this but I have no idea how to handle the -2. I also have no idea how to edit the MATLAB scripts I've found to encorporate this?

Any ideas?

Thanks
Jamesponty
 
Physics news on Phys.org
Last edited by a moderator:
Thanks for your reply. I've looked through the links you gave me fairly thoroughly but still really don't know where to start from. I have sample code for Matlab to solve the problem du/dt=d^2u/dx^2 and am only meant to be able to alter this code to account for the "-2".
 
Just add -2 at ever iteration. Why don't you post what you have so far.
 
OK, here is what I've done so far. It is only an adaption of code that we were given for the assignment. We are supposed to plot a number of representitive prolfiles for temp and use trial and error to determine a suitable value for the t interval. It also states to use N=12 steps and to advance the solution until you consider steady state to be reached.

I am pretty sure I have adjusted the code to use 12 steps but can't see how to alter the time interval. It is also not reaching a steady state either. I have just added the -2 as constant because it gives a form in the textbook of A*u(j+1)=Bu(j)+c. I have just made c = -2.

The other relevant info is the boundary conditions
u(x,0)=100x(1-x)^2 for 0<x<1
u(0,t)=u(1,t)=0 for t>0

Where should I go from here? Am I on the right track?

hold on
r=0.7;
cons=-2;
A=eye(11);
A=2*(1+r)*A;
for i=1:10
A(i,i+1)=-r;
A(i+1,i)=-r;
end
B=eye(11);
B=2*(1-r)*B;
for i=1:10
B(i,i+1)=r;
B(i+1,i)=r;
end
C=inv(A)*B+inv(A)*cons;
y=0:1/12:1.001;
x=y(2:12);
u=(100*x.*(1-x).^2)';
v(1)=0;
v(13)=0;
for j=1:31
for i=1:11
v(i+1)=u(i);
end
plot(y,v)
u=C*u;
end
 
Last edited:
Can anyone offer a suggestion please?
 
What are the initial conditions and boundary conditions? Can you set it up like this please and fill in any changes that are required?

[tex]\text{DE:}\quad u_{t}=u_{xx}-2 \quad 0\leq x \leq L[/tex]

[tex]\text{BC:}\quad u(0,t)=0\quad u(L,t)=0[/tex]

[tex]\text{IC:}\quad u(x,0)=f(x)[/tex]

Me, first I'd solve it directly using Duhamel's method to get the right answer, then debug the Crank-Nicoloson method to match what I got via separation of variables. Hey, I ain't proud.

Edit: Oh yea, if for some reason your problem is such that it's not solved easily directly via SOV and Duhamel's method, then set up one that IS easily solved directly, get the right answer, then debug Crank-Nicoloson to match that one, then substitute your problem into the bug-free method.
 
Last edited:
Crank Nicholson says something like

[tex] u^{j+1} = \frac{1}{2}[f(u^j(x),t^{j})+f(u^{j+1}(x),t^{j+1})][/tex]

And you are solving

[tex] \frac{\partial u}{\partial t} = \frac{\partial^2 u}{\partial x^2} - 2[/tex]

So discretize your equation, I use subscript i for position and superscript j for time.

[tex] \frac{u_i^{j+1}-u_i^j}{\Delta t} = \frac{u_{i+1}^{j}-2u_i^j+u_{i-1}^j}{2 \Delta x^2} + \frac{u_{i+1}^{j+1}-2u_i^{j+1}+u_{i-1}^{j+1}}{2 \Delta x^2} -2[/tex]

Then rearrange

[tex] u^{j+1}_i = \frac{\Delta t}{2 \Delta x^2}u^{j}_{i+1} + (-2 \frac{\Delta t}{2 \Delta x^2}+1)u^{j}_{i} + \frac{\Delta t}{2 \Delta x^2}u^{j}_{i-1} <br /> + <br /> \frac{\Delta t}{2 \Delta x^2}u^{j+1}_{i+1} + (-2 \frac{\Delta t}{2 \Delta x^2})u^{j+1}_{i} + \frac{\Delta t}{2 \Delta x^2}u^{j+1}_{i-1}<br /> - 2 \Delta t[/tex]


That is an equation for an interior node in your domain.

I'm pretty sure I see [one of] the problem with your code. I guess just telling you to add -2 at each step is not entirely accurate. It is weighted by something, and you don't want it on every node because of boundary conditions. See if you can figure out what to do from there.
 
hi,
i'm stuck with that homework .could someone help me pls?

d2u/dt2=d2u/dx2 , 0<x<1 , t>=0,

boundary conditions : u(0,t)=0=u(1,t), t>=0
initial conditions : u(x,0)=sin(pi*x) , 0<x<1
u(x,0)=0, 0<x<1
 

Similar threads

  • · Replies 32 ·
2
Replies
32
Views
3K
Replies
16
Views
2K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 5 ·
Replies
5
Views
5K
  • · Replies 5 ·
Replies
5
Views
3K
Replies
5
Views
1K
Replies
40
Views
4K
  • · Replies 40 ·
2
Replies
40
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 8 ·
Replies
8
Views
3K