(adsbygoogle = window.adsbygoogle || []).push({}); 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.

**Physics Forums | Science Articles, Homework Help, Discussion**

Dismiss Notice

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Homework Help: Help With Finite Difference Method in Solving Second Order Differenial Equation

Can you offer guidance or do you also need help?

Draft saved
Draft deleted

**Physics Forums | Science Articles, Homework Help, Discussion**