Matrix dimension do not agree when solving a singular bvp using bvp4c
4 次查看(过去 30 天)
显示 更早的评论
I try to solve a singular boundary value problem using bvp4c. When I run the code I get the error below:
Error using *
Inner matrix dimensions must agree.
Error in bvpsingular/odeSingular (line 108)
f = PImS*f;
Error in bvp4c>colloc_RHS (line 622)
Freg(:,i) = Fcn(xreg(i),yreg(:,i),FcnArgs{:});
Error in bvp4c (line 189)
[RHS,yp,Fmid,NF] = colloc_RHS(n,x,Y,ode,bc,npar,xyVectorized,mbcidx,nExtraArgs,ExtraArgs);
Error in effectiveness_multiple_reactions (line 27)
sol = bvp4c(@der_y,@bc,solinit,options);
I already searched on this warning but I cannot find the solution. Can anyone help me? Below is an excerpt of my code
solinit = bvpinit([linspace(0,L,10)],[cNOi 0 cH2i 0]);
S = [0 0 0 0; 0 -2 0 0; 0 0 0 0; 0 0 0 -2];
options =bvpset('SingularTerm',S);
sol = bvp4c(@der_y,@bc,solinit,options);
function der = der_y(r,c)
der(1) = c(2);
der(2) = (R1(c(3),c(1),T) + R2(c(3),c(1),T) + R3(c(3),T))./DeNO;
der(3) = c(4);
der(4) = (1.5.*R1(c(3),c(1),T) + 2.5.*R2(c(3),c(1),T) + 0.5.*R3(c(3),T))./DeH2;
end
function res=bc(cl,cr)
res(1) = cl(2);
res(2) = cr(1)-cNOi;
res(3) = cl(2);
res(4) = cr(1)-cH2i;
end
0 个评论
采纳的回答
Star Strider
2015-5-29
Your functions have to return column vectors. They are by default row vectors if you define them as you did. There are several ways to force ‘der’ and res to be column vectors, the easiest way is to add this assignment as the last line in the respective functions:
der = der(:);
res = res(:);
I didn’t run your code, so there could be other problems.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Boundary Value Problems 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!