Matrix dimension do not agree when solving a singular bvp using bvp4c
조회 수: 2 (최근 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!