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?
댓글 수: 0
채택된 답변
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 Center 및 File Exchange에서 Boundary Value Problems에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!