Passing a known vector to BVP4C

2 次查看(过去 30 天)
Jacob Jepson
Jacob Jepson 2020-3-2
Hi All,
I wish to solve the second order BVP (which has been turned in to a system of two first order ODEs in the code):
for the function c (where K_c,s and Diff are all constants) and where n is a known vector. I am having trouble passing the vector n to BVP4C (I think).. The following is my code
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
when I run this I get the error:
Error using bvparguments (line 108)
Error in calling BVP4C(ODEFUN,BCFUN,SOLINIT):
The derivative function ODEFUN should return a column vector of length 2.

回答(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