Solving a boundary value problem using bvp4c
Show older comments

I am attempting to solve this boundary value problem however I am struggling with actually obtaining the correct results. Here is the code I have:
function [sol] = bvs(Pr)
%Inputs:
%Pr - the Prandtl number
%If Pr not given
if nargin < 1
Pr = .7;
end
%Set upper boundary
yinf = 10;
%Create node vector and initial guesses
x = linspace(0,yinf,100);
init = bvpinit(x,[0,0,1,1,0]);
%Run ODE solver
options = bvpset('RelTol',1e-8,'AbsTol',1e-12);
sol = bvp4c(@odefun,@bcfun,init,options);
%Nested funtion to define the ODE
function dydx = odefun(x,y)
dydx = zeros(5,1);
dydx(1) = y(2);
dydx(2) = y(3);
dydx(3) = (-y(1).*y(3))./2;
dydx(4) = y(5);
dydx(5) = ((Pr.*y(2).*y(4)) - (Pr.*y(1).*y(5)))./2;
end
%Nested function to define the boundary conditions
function res = bcfun(yl,yr)
res = zeros(5,1);
res(1) = yl(1);
res(2) = yl(2);
res(3) = yr(3)-1;
res(4) = yl(4)-1;
res(5) = yr(5);
end
end
Can anyone help point out errors I have in my code?
Accepted Answer
More Answers (0)
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!