Matrix dimension do not agree when solving a singular bvp using bvp4c
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposta accettata
Star Strider
il 29 Mag 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 Commenti
Più risposte (1)
Torsten
il 29 Mag 2015
Modificato: Torsten
il 23 Ago 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 Commenti
Vedere anche
Categorie
Scopri di più su Boundary Value Problems in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!