Finding all the eigen values through bvp4c
7 views (last 30 days)
Show older comments
Dear members,
I am trying to find all the eigen values of y''+lambda*y=0
I know that y=sin(kx) with lambda=k^2, k=1,2,3.. are the solutions.
When I try to find this solution numerically, I miss some of the roots. Is there a way to get all the solutions
Here is the code:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
lambda = 0;
k= 1;
hold on
for i=1:5
lambda=lambda+1;
k=k+1;
solinit = bvpinit(linspace(-pi,pi,20),@matinit,k,lambda);
sol = bvp4c(@matode, @matbc, solinit);
fprintf(' eigenvalue is approximately %7.3f.\n',...
sol.parameters)
xint = linspace(-pi,pi);
Sxint = deval(sol,xint);
plot(xint,Sxint(1,:))
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
end
hold off
function yinit = matinit(x,k) % initial guess function
yinit = [sin(k*x)
k*cos(k*x)];
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function res = matbc(ya,yb,lambda) % boundary conditions
res = [ya(1)
yb(1)
ya(2)-1];
end
%%%%%%%%%%%%%%%%
function dydx = matode(x,y,lambda) % equation being solved
dydx = [y(2)
-(lambda)*y(1)];
end
%%Output:
eigenvalue is approximately 1.000.
eigenvalue is approximately 4.000.
eigenvalue is approximately 4.000. ** This is repeated I expect 9 here
eigenvalue is approximately 16.001.
eigenvalue is approximately 4.000. ** I expect 25 here.
PS: If I change my initial guess to more points I see more roots appearing but then again I miss some of them.
2 Comments
Torsten
on 17 Nov 2022
Why is k*cos(k*(-pi)) = 1 as you claim in your boundary condition ya(2) - 1 = 0 ?
Answers (1)
Saarthak Gupta
on 7 Sep 2023
Hi Gaurav,
I understand you are trying to find all eigenvalues of the second order differential equation y” + lambda*y = 0 using ‘bvp4c’.
The ‘bvp4c’ code is for general BVPs, so all it can do is compute the eigenvalue closest to a guess. This BVP can be solved with a constant guess for the eigenfunction, but we can make it much more likely that we compute the desired eigenvalue by supplying a guess for the eigenfunction that has the correct qualitative behaviour.
You can make the following modifications to the code to achieve the desired result:
1. Parametrize the ‘matinit’ function w.r.t. k, and supply the function handle in the call to ‘bvpinit’. Please refer to the MATLAB documentation for Parameterizing Functions for more details: https://in.mathworks.com/help/matlab/math/parameterizing-functions.html
2. Give the initial guess for lambda as k^2, to increase the likelihood of getting the desired eigenvalue (as per the analytical solution).
The following code computes all eigenvalues for the BVP:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
lambda = 0;
k= 1;
hold on
for i=1:5
lambda=lambda+1;
k=k+1;
matinit = @(x) [sin(k*x) k*cos(k*x)];
solinit = bvpinit(linspace(-pi,pi,20),matinit,lambda.^2);
sol = bvp4c(@matode, @matbc, solinit);
fprintf(' eigenvalue is approximately %7.3f.\n',...
sol.parameters)
xint = linspace(-pi,pi);
Sxint = deval(sol,xint);
plot(xint,Sxint(1,:))
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
end
hold off
% function yinit = matinit(x,k) % initial guess function
% yinit = [sin(k*x)
% k*cos(k*x)];
% end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function res = matbc(ya,yb,lambda) % boundary conditions
res = [ya(1)
yb(1)
ya(2)-1];
end
%%%%%%%%%%%%%%%%
function dydx = matode(x,y,lambda) % equation being solved
dydx = [y(2)
-(lambda)*y(1)];
end
Please refer to the following MATLAB documentation for more details:
0 Comments
See Also
Categories
Find more on Boundary Value Problems in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!