
Defining Boundary Conditions - How?
11 views (last 30 days)
Show older comments
Gabriel Coelho
on 13 Jun 2020
Commented: Gabriel Coelho
on 30 Jun 2020
Hello there,
I was trying to script the following ODE problem to solve it on matlab:

Considering the following bondary conditions:

What would be the best way to define the last two BCs?
How could I script then in MATLAB language?
Currently, I am using MATLAB R2015a.
Thank you for the help!
Gabriel
0 Comments
Accepted Answer
Ameer Hamza
on 14 Jun 2020
This link shows how to use bvp5c to solve multiple boundary condition problem: https://www.mathworks.com/help/matlab/math/solve-bvp-with-multiple-boundary-conditions.html. Try following code.
L = 3;
xmesh = [linspace(0, L/2, 50) linspace(L/2, L, 50)];
yguess = bvpinit(xmesh, [0; 0]);
sol = bvp5c(@odefun, @bcFun, yguess);
plot(sol.x, sol.y);
legend({'$y$', '$\dot{y}$'}, ...
'Interpreter', 'latex', ...
'FontSize', 16, ...
'Location', 'best');
function dydx = odefun(x, y, region)
W = 1;
T = 2;
dydx = zeros(2, 1);
dydx(1) = y(2);
if region==1
dydx(2) = 3*W/T;
else
dydx(2) = W/T;
end
end
function res = bcFun(yl, yr)
res = [yl(1,1) - 0; % y(0)=0
yr(1,1) - yl(1,2); % y(L/2-)=y(L/2+)
yr(2,1) - yl(2,2); % y'(L/2-)=y'(L/2+)
yr(1,2)]; % y(L)=0
end

More Answers (0)
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!