MATLAB Answers

0

Matrix dimension do not agree when solving a singular bvp using bvp4c

Rick D 님이 질문을 제출함. 29 May 2015
최근 활동 Torsten 님이 편집함. 23 Aug 2019
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

로그인 to comment.

제품

답변 수: 2

Star Strider 님의 답변 29 May 2015
 채택된 답변

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

로그인 to comment.


Torsten 님의 답변 29 May 2015
Torsten 님이 편집함. 23 Aug 2019

Your boundary conditions can not be handled by bvp4c:
You prescribe two times that y(2)=0 at the left boundary point and you give the contradictory condition that y(1)=cNOi and y(1)=cH2i at the right boundary point.
Best wishes
Torsten.

  댓글 수: 0

로그인 to comment.



Translated by