フィルターのクリア

Finding all the eigen values through bvp4c

19 ビュー (過去 30 日間)
Gaurav Singh
Gaurav Singh 2022 年 11 月 17 日
回答済み: Saarthak Gupta 2023 年 9 月 7 日
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
eigenvalue is approximately 1.000. eigenvalue is approximately 4.000. eigenvalue is approximately 4.000. eigenvalue is approximately 16.001. eigenvalue is approximately 4.000.
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 件のコメント
Torsten
Torsten 2022 年 11 月 17 日
Why is k*cos(k*(-pi)) = 1 as you claim in your boundary condition ya(2) - 1 = 0 ?
Gaurav Singh
Gaurav Singh 2022 年 11 月 17 日
As Lamdda is a parameter, so by using this BC, I am fixing the amplitude.

サインインしてコメントする。

回答 (1 件)

Saarthak Gupta
Saarthak Gupta 2023 年 9 月 7 日
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:

カテゴリ

Help Center および File ExchangeBoundary Value Problems についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by