Method of lines for diffusion equation

In summary: The equations used in the method are described and the need for a stiff equation solver is mentioned. The function definitions used in the conversation are also questioned.
  • #1
k0st123
2
0
Hello,

I am trying to solve the following simple diffusion equation using the method of lines:

du/dt=D(du2/dx2)function k=func1()
k = [0, 0, 0, 0, 0, 0, 0.4380, 0, 1e5]; %k(9) initial value of the molecules
end %k(7) D/dx2

function k=func2()
c = [0 0 0 0 0 0 0 0];
end

function cx = eqn(t,c,k)

fb = [ 2*k(7)*c(2)-2*k(7)*c(1)-k(7)*k(9); % du1/dt
k(7)*c(3)-2*k(7)*c(2)+k(7)*c(1); % du2/dt
k(7)*c(4)-2*k(7)*c(3)+k(7)*c(2); % du3/dt
k(7)*c(5)-2*k(7)*c(4)+k(7)*c(3); % du4/dt
k(7)*c(6)-2*k(7)*c(5)+k(7)*c(4); % du5/dt
k(7)*c(7)-2*k(7)*c(6)+k(7)*c(5); % du6/dt
k(7)*c(8)-2*k(7)*c(7)+k(7)*c(6); % du7/dt
-2*k(7)*c(8)+k(7)*c(7)]; % du8/dt

endk = func1;

c = func2;

ts1 = [1 1000];

[A,B] = ode45(@(t,y)eqn(t,y,k),ts1, c);

I am using mesh for A and B but the results I get seem unexpected.
Could anyone please point me to what the problem could be? Are my equations right??

Thanks

k0st123
 
Physics news on Phys.org
  • #2
Your function definitions looks weird. Do they even work( I suppose it is matlab)? Also I do not know what the method of lines is( wiki is no help) so please give a link describing the discretization function.
 
  • #3
Strum said:
Your function definitions looks weird. Do they even work( I suppose it is matlab)? Also I do not know what the method of lines is( wiki is no help) so please give a link describing the discretization function.
In the method of lines, you descretize the spatial derivatives, but not the time derivatives. So you end up with a set of first order coupled ODEs in time. For a problem like this, the spatial derivative would be descretized using a 2nd order central difference approximation. In this kind of problem, the ODEs will be stiff, so you typically use a stiff equation solver to do the time integration.

Chet
 

FAQ: Method of lines for diffusion equation

1. What is the method of lines for diffusion equations?

The method of lines is a numerical technique for solving partial differential equations, such as the diffusion equation. It involves discretizing the spatial domain into a set of grid points and then solving the resulting system of ordinary differential equations using a numerical method, such as the Runge-Kutta method.

2. How does the method of lines differ from other numerical methods?

The method of lines is unique in that it first discretizes the spatial domain and then solves the resulting system of ordinary differential equations. Other numerical methods, such as finite difference or finite element methods, typically solve the equations directly on the continuous domain.

3. What are the advantages of using the method of lines?

The method of lines offers several advantages, such as flexibility in choosing the spatial discretization and numerical method, as well as the ability to handle complex boundary conditions. It also allows for the use of efficient solvers for ordinary differential equations.

4. Are there any limitations to the method of lines?

One limitation of the method of lines is that it can be computationally expensive when the spatial domain is highly discretized. Additionally, the accuracy of the solution can be affected by the choice of spatial discretization and numerical method.

5. How can the method of lines be applied to real-world problems?

The method of lines is commonly used to solve diffusion equations in various fields, such as physics, chemistry, and engineering. It can be applied to model and analyze diffusion processes in materials, chemical reactions, and heat transfer, among others.

Similar threads

Back
Top