Use finite difference method to solve for eigenvalue E in Matlab

In summary: Another option is to use a built-in function or software specifically designed for solving eigenvalue problems. In summary, the conversation discusses the use of the finite difference method to solve for an eigenvalue E in a second order ODE. The equation is discretized and a code is provided to solve for the eigenvalues. However, there is a discrepancy between the numerical and analytic solutions, and the issue of imposing boundary conditions is also raised. Suggestions for alternative methods, such as the shooting method or specialized software, are also mentioned.
  • #1
EigenCake
13
0
Use finite difference method to solve for eigenvalue E from the following second order ODE:

- y'' + (x2/4) y = E y

I discretize the equation so that it becomes

yi-1 - [2 + h2(x2i/4)] yi + yi+1 = - E h2 yi

where xi = i*h, and h is the distance between any two adjacent mesh points.

This is my code:
Code:
clear all
n = 27;
h = 1/(n+1);
voffdiag = ones(n-1,1);
for i = 1:n
    xi(i) = i*h;
end
mymat = -2*eye(n)-diag(((xi.^2).*(h^2)./4),0)+diag(voffdiag,1)+diag(voffdiag,-1);
D=sort(eig(mymat),'descend');
lam= -D/(h^2);
spy(mymat)
fprintf(1,' The smallest eigenvalue is %g \n',lam(1));
fprintf(1,' The second smallest eigenvalue is %g \n',lam(2));
fprintf(1,' The 3rd eigenvalue is %g \n',lam(3));

it returns
Code:
 The smallest eigenvalue is 9.92985 
 The second smallest eigenvalue is 39.3932 
 The 3rd eigenvalue is 88.0729

Obviously, something wrong here, since the analytic solution should be
E = n + 1/2 (for n = 0, 1, 2, 3...)
The smallest eigenvalue should be 0.5, instead of 9.92985.

I don't know whether my numerical solution agrees with the analytic solution or not, if I impose a boundary condition (ie. when x goes to infinity, y(x) should vanish to 0). And I don't know how to impose boundary condition. Please help, thank you very much!

By the way, is there any another way to find the eigenvalue E please?
 
Last edited:
Physics news on Phys.org
  • #2
Yes. You can use the shooting method to solve for the eigenvalue. This involves solving the differential equation by integrating from a given boundary condition and then using an iterative process to find the eigenvalue that produces the desired boundary condition.
 

FAQ: Use finite difference method to solve for eigenvalue E in Matlab

What is the finite difference method?

The finite difference method is a numerical method used to solve differential equations. It involves approximating the derivatives in the equation using finite differences and then solving the resulting algebraic equations.

Why is the finite difference method used to solve for eigenvalues?

The finite difference method is used to solve for eigenvalues because it is a robust and efficient numerical method for solving differential equations. It allows for the computation of eigenvalues without needing to know the analytical solution of the equation.

How does the finite difference method work?

The finite difference method works by discretizing the domain of the differential equation into a grid of points. The derivatives at each point are then approximated using the values at neighboring points. These approximations are then used to create a system of algebraic equations, which can be solved to obtain the eigenvalues.

Is there a specific syntax for using the finite difference method in Matlab?

Yes, there is a specific syntax for using the finite difference method in Matlab. First, the differential equation is discretized into a grid using the meshgrid function. Then, the finite difference approximations are applied using the diff function. Finally, the resulting system of equations can be solved using the eig function to obtain the eigenvalues.

Are there any limitations to using the finite difference method to solve for eigenvalues?

Yes, there are some limitations to using the finite difference method to solve for eigenvalues. The accuracy of the results depends on the size of the grid and the choice of finite difference approximations. It may also be computationally expensive for problems with high dimensionalities or complex boundary conditions.

Similar threads

Replies
1
Views
1K
Replies
1
Views
1K
Replies
4
Views
3K
Replies
2
Views
2K
Replies
2
Views
3K
Replies
2
Views
1K
Back
Top