Solving a boundary value problem using bvp4c

11 次查看(过去 30 天)
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?

采纳的回答

Torsten
Torsten 2016-12-12
function res = bcfun(yl,yr)
res = zeros(5,1);
res(1) = yl(1);
res(2) = yl(2);
res(3) = yr(2)-1;
res(4) = yl(4)-1;
res(5) = yr(4);
end
Best wishes
Torsten.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Boundary Value Problems 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by