Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Method of lines for diffusion equation

  1. Jun 30, 2015 #1
    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

    end


    k = 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
     
  2. jcsd
  3. Jul 4, 2015 #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.
     
  4. Jul 4, 2015 #3
    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
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Method of lines for diffusion equation
  1. Diffusion equations (Replies: 1)

  2. Diffusion equations (Replies: 0)

Loading...