Solve multiple eigenvalue ODE problem with bvp4c

2 ビュー (過去 30 日間)
Anshuman Pal
Anshuman Pal 2021 年 9 月 2 日
回答済み: darova 2021 年 9 月 5 日
Hello,
I am following the bvp4c manual to solve an eigenvalue problem with two eigenvalues. I am getting an error `Error using vertcat: Dimensions of arrays being catenated are not consistent`. However, I think that this error might be due to some other inconsistency in my code. Could someone please help?
My code:
clear all
% parameters
global L Num
Num = 3000; % number of grid points. 3000 is plenty.
L = 1.0 ; % length of buckled portion of rod
tau0_init = 0; % 2 eigenvalues
deltaL_init = 0.1*L;
ss = linspace(0, L, Num);
solinit = bvpinit(ss, @mat4init, [tau0_init, deltaL_init]);
options = bvpset('Stats','on','RelTol',1e-5,'NMax',Num);
sol = bvp4c(@bvp_RHS, @bvp_BC, solinit, options);
fprintf('The eigenvalues are approximately %.2f.\n',sol.parameters)
figure
plot(sol.x, sol.y)
xlabel('s')
grid
legend(compose('$y_{%2d}$',1:11), 'Location','bestoutside', 'Interpreter','latex')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function yinit = mat4init(x)
% initial guess for the solution
global L
yinit = [-sin(pi/L*x) % theta
-pi/L * cos(pi/L*x) % theta'
0.1 % x
0.1 % y
];
end
function dyds = bvp_RHS(x, y, tau0, deltaL)
% Total 4 variables.
% NB: eigenvalues tau0 and deltaL must be a function input even though if not present
% in any equation below.
global L
dyds = [ y(2)
-tau0*sin(y(1)) +(L-x)*cos(y(1))
cos(y(1))
sin(y(1))
];
end
function res = bvp_BC(yL, yR, tau0, deltaL)
% BCs at L and R boundaries, with constraint for eigenvalues tau0 and deltaL.
global L
res = [ yL(1)
yL(2)
yL(3)
yL(4)
yR(1)
yR(3)- 0.5*(L-deltaL)
];
end

回答 (1 件)

darova
darova 2021 年 9 月 5 日
Remove those spaces

カテゴリ

Help Center および File ExchangeOrdinary Differential Equations についてさらに検索

タグ

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by