Solve multiple eigenvalue ODE problem with bvp4c
1 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Boundary Value Problems 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!