1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Help With Finite Difference Method in Solving Second Order Differenial Equation

  1. Jun 30, 2011 #1
    1. The problem statement, all variables and given/known data
    y'' + 3y' + 2y = 0, y(0) = 1, y'(0) = 0


    2. Relevant equations
    Finite Difference Approximations:
    y'' = (y(ii+1) - 2y(ii) + y(ii-1))/h^2
    y' = (y(ii+1) - y(ii-1))/(2h)
    where h is the finite difference.


    3. The attempt at a solution
    I wrote the MATLAB code (just to try out finite differences):

    x = linspace(0,1,20);
    h = x(2) - x(1);
    N = length(x);
    y0 = 1;
    yp0 = 0;
    ynext = y0 + h*yp0;

    a = ones(size(x))*(1/h^2 - 3/(2*h))
    b = ones(size(x))*(-2/h^2 + 2);
    c = ones(size(x))*(1/h^2 + 3/(2*h))
    r = zeros(size(x));

    a(1) = 0; c(1) = 0; b(1) = 1; r(1) = y0;
    a(2) = 0; c(2) = 0; b(2) = 1; r(2) = ynext;
    %a(2) = -1/(2*h); b(2) = 0; c(2) = 1/(2*h); r(2) = yp0;

    A = diag(a(2:N),-1) + diag(b,0) + diag(c(1:(N-1)),1)
    y = inv(A)*r';
    yt = 2*exp(-x) - exp(-2*x);
    plot(x,y,'o',x,yt);

    Basically setting up a tridiagonal matrix involving terms y(ii).
    I can solve the problem by doing a two step forward iteration but do not see why solving the system does not give me the same(correct plot). yt gives the exact solution.
     
  2. jcsd
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Can you offer guidance or do you also need help?



Similar Discussions: Help With Finite Difference Method in Solving Second Order Differenial Equation
Loading...