I wish to solve the second order ODE
$$\frac{\partial ^2 c}{\partial x^2} = kn(x)c(x)$$ using BVP4C in MATLAB. As usual, I decomposed it in to two first order ODEs. I think my problem lies with the fact that I'm trying to pass the known vector as a parameter in to bvp4c. My code is as follows;
function ConcBVP = CellConcBVP(space_steps,n,s,c_bound,Diff,K_c)
xmesh = linspace(0,1,space_steps);
solinit = bvpinit(xmesh, @guess);
sol = bvp4c(@(x,y)bvpfcn(x,y,n,K_c,Diff,s), @(ya,yb)bcfcn(ya,yb,c_bound), solinit);
ConcBVP = sol.x;
function dydx = bvpfcn(y,n,K_c,Diff,s)
dydx = [y(2)
-K_c*s^2*y(1)*n/Diff];
end
function res = bcfcn(ya,yb,c_bound)
res = [ya(2)
yb(1) - c_bound];
end
function g = guess(x)
g = [sin(x)
cos(x)];
end
and when I run my code I just get the errors
Error using bvparguments (line 108)
Error in calling BVP4C(ODEFUN,BCFUN,SOLINIT):
The derivative function ODEFUN should return a column vector of length 2.