Help With Finite Difference Method in Solving Second Order Differenial Equation

In summary, the finite difference method is a numerical technique used to approximate solutions to differential equations by dividing a continuous domain into a discrete grid of points and using neighboring points to calculate derivatives. It can be used for a wide range of differential equations, including ODEs and PDEs, and has advantages such as simplicity and versatility. However, it is limited by grid accuracy, complexity of the equation, and may not be suitable for certain types of problems.
  • #1
abooaboo110
1
0

Homework Statement


y'' + 3y' + 2y = 0, y(0) = 1, y'(0) = 0


Homework 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.


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 news on Phys.org
  • #2



Hello,

Thank you for sharing your MATLAB code and approach to solving this problem. It looks like you are on the right track with using finite difference approximations to solve for y'' and y'. However, I noticed that in your code, you are using a two-step forward iteration to solve for y, rather than using the tridiagonal matrix approach you mentioned. This could be the reason why your plot is not matching the exact solution.

I would suggest trying to solve the system using the tridiagonal matrix approach, as it will give you a more accurate solution. Also, make sure to double check your boundary conditions and ensure that they are being properly incorporated into your code.

Overall, your approach seems sound and I believe with a few adjustments, you will be able to obtain the correct plot. Keep up the good work!
 

What is the finite difference method?

The finite difference method is a numerical technique used to approximate solutions to differential equations. It works by dividing a continuous domain into a discrete grid of points and approximating the derivatives at each point using the values of neighboring points. This method is commonly used to solve differential equations that cannot be solved analytically.

How does the finite difference method work?

The finite difference method works by approximating the derivatives of a function at discrete points on a grid. The derivatives are calculated using the values of the function at neighboring points, and the grid is refined to improve the accuracy of the solution. The final solution is obtained by solving a system of linear equations that represent the differential equation at each point on the grid.

What types of differential equations can be solved using the finite difference method?

The finite difference method can be used to solve a wide range of differential equations, including ordinary differential equations (ODEs) and partial differential equations (PDEs). It is particularly useful for solving boundary value problems, as it allows for the accurate approximation of boundary conditions.

What are the advantages of using the finite difference method?

One advantage of using the finite difference method is its simplicity and ease of implementation. It also allows for the solution of complex differential equations that cannot be solved analytically. Additionally, the finite difference method can handle nonlinear and time-dependent problems, making it a versatile tool for solving a variety of scientific and engineering problems.

What are the limitations of the finite difference method?

The finite difference method is limited by the accuracy of the grid used and the complexity of the differential equation being solved. In some cases, the method may also require a large number of grid points to achieve an accurate solution, making it computationally expensive. Additionally, the finite difference method may not be suitable for problems with irregular boundaries or complex geometries.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
2
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
826
  • Engineering and Comp Sci Homework Help
Replies
3
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
6
Views
860
  • Engineering and Comp Sci Homework Help
Replies
4
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
6
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
958
  • Engineering and Comp Sci Homework Help
Replies
7
Views
732
Back
Top