Solving a boundary value problem using bvp4c

12 ビュー (過去 30 日間)
Swil
Swil 2016 年 12 月 11 日
コメント済み: Swil 2016 年 12 月 12 日
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.
  1 件のコメント
Swil
Swil 2016 年 12 月 12 日
Thanks for the help!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeBoundary Value Problems についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by