Defining Boundary Conditions - How?

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

 Accepted Answer

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

1 Comment

Excelent! Thanks a lot
Any ideas on how to define the boundary conditions with symbolic?

Sign in to comment.

More Answers (0)

Products

Release

R2015a

Community Treasure Hunt

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

Start Hunting!