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 about 17 hours 前
移动:Torsten about 17 hours 前
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