Crank-Nicolson method for a parabolic differential equation

In summary: ,
  • #1
jamesponty
6
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
  • #3
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".
 
  • #4
Just add -2 at ever iteration. Why don't you post what you have so far.
 
  • #5
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 becuase 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:
  • #6
Can anyone offer a suggestion please?
 
  • #7
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:
  • #8
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}
+
\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}
- 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.
 
  • #9
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
 

1. What is the Crank-Nicolson method for solving parabolic differential equations?

The Crank-Nicolson method is a numerical method used to solve parabolic differential equations, which are equations that involve two independent variables and one dependent variable. This method involves discretizing the equation in both space and time, and then using a finite difference scheme to approximate the derivatives. It is a popular method because it is unconditionally stable and has second-order accuracy.

2. How does the Crank-Nicolson method differ from the Forward Euler method?

The Crank-Nicolson method differs from the Forward Euler method in that it uses a combination of the values at the current time step and the previous time step to approximate the derivative, whereas the Forward Euler method only uses the values at the current time step. This results in the Crank-Nicolson method being more accurate and stable for solving parabolic differential equations.

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

The Crank-Nicolson method has several advantages, including being unconditionally stable, which means that the time step size does not need to be restricted for the method to work. It is also second-order accurate, which means that it converges to the true solution faster than other methods. Additionally, it can handle a wide range of boundary conditions and is relatively easy to implement.

4. What are the limitations of the Crank-Nicolson method?

Although the Crank-Nicolson method has many advantages, it also has some limitations. One limitation is that it can be computationally expensive, especially for larger systems. The method also requires a large number of time steps to accurately solve the equation, which can be time-consuming. Additionally, the method is only applicable to parabolic differential equations and cannot be used for other types of equations.

5. How do I choose the appropriate time step and grid size for the Crank-Nicolson method?

The time step and grid size for the Crank-Nicolson method should be chosen carefully to ensure accuracy and efficiency. A smaller time step and grid size will result in a more accurate solution, but it will also increase the computational cost. It is important to balance these factors and choose a time step and grid size that is appropriate for the problem at hand. In general, a smaller time step and grid size may be necessary for complex systems with steep gradients, while a larger time step and grid size may be sufficient for simpler systems.

Similar threads

  • Introductory Physics Homework Help
Replies
16
Views
993
  • Introductory Physics Homework Help
Replies
5
Views
3K
  • Introductory Physics Homework Help
2
Replies
40
Views
780
  • Introductory Physics Homework Help
2
Replies
40
Views
2K
  • Introductory Physics Homework Help
Replies
1
Views
932
  • Calculus and Beyond Homework Help
Replies
10
Views
409
  • Introductory Physics Homework Help
Replies
17
Views
277
  • Introductory Physics Homework Help
Replies
12
Views
721
  • Calculus and Beyond Homework Help
Replies
7
Views
132
  • Science and Math Textbooks
Replies
5
Views
2K
Back
Top