Why do I receive error using BVP5C "The boundary condition function BCFUN should return a column vector of length 1"?
Afficher commentaires plus anciens
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
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Boundary Value Problems dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!