Why do I receive error using BVP5C "The boundary condition function BCFUN should return a column vector of length 1"?

조회 수: 16 (최근 30일)
My code is as following, aiming to solve a first order differential equation.
xmesh = linspace(0,8.6,10);
solinit = bvpinit(xmesh,@guess);
sol = bvp5c(@bvpfcn, @bcfcn, solinit); % Recived the error warning here!!!
plot(sol.x, sol.y, '-o')
function dydx = bvpfcn(x,y) % equation to solve
np0 = 1.3861*10^8; a = 10.2041; ni = 5*10^6; Mx = 10; ne = 5388520.4418; n = np0+ne/a;
Y0 = 2.19537; Ym = -0.87074;
A=2*ni/n; B=a*Mx^2; C=np0/n; D=a*ne/n; E=2*np0/n; F=exp(Ym-Y0); G=exp(Ym/a); % parameters
dydx = -(A*B*((1-2*y/B)^0.5-(1-2*Ym/B)^0.5)+ ...
C*(exp(y-Y0)*(1-erf((y-Ym)^0.5))+F*(2/pi^0.5*(y-Ym)^0.5-1))+ ...
D*(exp(y/a)*(1-erf(((y-Ym)/a)^0.5)+G*(2/pi^0.5*((y-Ym)/a)^0.5-1)))+ ...
E*(exp(y-Y0)*erf((y-Ym)^0.5)-2/pi^0.5*F*(y-Ym)^0.5))^0.5;
end
%--------------------------------
function res = bcfcn(ya,yb) % boundary conditions Y(0)=2 Y(zm)=-0.8
res = [ya(1)-2
yb(1)+0.8];
end
%--------------------------------
function g = guess(x) % initial guess for y
g = -sin(x);
end

채택된 답변

Torsten
Torsten 2024년 11월 20일 16:44
이동: Torsten 2024년 11월 20일 16:44
You have one first-order ODE, but two boundary conditions. That's mathematically impossible - you can impose only one condition. After having done this, switch to "ode45" as solver instead of "bvp5c".

추가 답변 (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