Effacer les filtres
Effacer les filtres

Error in bvp4c code

22 vues (au cours des 30 derniers jours)
Kalyani
Kalyani le 18 Oct 2023
Commenté : Kalyani le 24 Oct 2023
Hello all!
I'm a research scholar and I'm trying to solve a coupled system of ODEs with boundary conditions. I'm using bvp4c solver. However, I'm getting the error, 'Index exceeds matrix dimensions' when I run the code. I'm attaching the equations that I'm solving as pdf. I'm also giving the code below. Please advice on how to proceed.
Thank You
R=1;
ya=0; yRc=0.86; yRp=0.91; yRb=1;
M=1.5;
alpha0=1;
P0=10;
mu=0.2;
hm=0.2;
Rc=0.86;
Rp=0.91;
Rb=0.95;
Rd=1.0;
We=0.5;
m=2;
Da=0.01;
beta=0.1;
alpha=0.01;
alpha2=1.1;
phi=0.5;
ud=P0*Da;
eps=1.0000e-04;
r=linspace(eps,R,100);
solinit = bvpinit(linspace(eps,R,100),[1,1,1,1,1,1,1,1,1]);
options = bvpset('RelTol', 10e-4,'AbsTol',10e-7);
sol = bvp4c(@(r,y)base(r,y,P0,mu,hm,Rc,We,m,Da,alpha2,eps),@(r,y)baseBC(ya,yRc,yRp,yRb,P0,We,m,Da,beta,alpha,phi),solinit,options);
Index exceeds the number of array elements. Index must not exceed 1.

Error in solution>baseBC (line 41)
res=[ya(4); -(yRc(4))-(((m-1)/(2))*((We)^2)*((yRc(4))^3))+(yRc(6))+(((m-1)/(2))*((We)^2)*((yRc(6))^3));

Error in solution>@(r,y)baseBC(ya,yRc,yRp,yRb,P0,We,m,Da,beta,alpha,phi) (line 25)
sol = bvp4c(@(r,y)base(r,y,P0,mu,hm,Rc,We,m,Da,alpha2,eps),@(r,y)baseBC(ya,yRc,yRp,yRb,P0,We,m,Da,beta,alpha,phi),solinit,options);

Error in bvparguments (line 97)
testBC = bc(ya,yb,bcExtras{:});

Error in bvp4c (line 119)
bvparguments(solver_name,ode,bc,solinit,options,varargin);
y=deval(sol,r);
plot(r,y(1,:))
function dydx = base(r,y,P0,mu,hm,Rc,We,m,Da,alpha2,eps) % Details ODE to be solved
%dydx = zeros(9,1);
dydx(1)=y(4); dydx(2)=y(6); dydx(3)=y(8);
dydx(4)=y(5); dydx(6)=y(7); dydx(8)=y(9);
dydx(6)=(-P0)-((1/(r+eps))*(y(6)));
dydx(8)=((-P0)/(alpha2))+((-(1)/(r+eps))*(y(8)))+((y(3))/((alpha2)*(Da)));
dydx(4)=((1)/((1)-((mu)*(hm)*(((Rc)^2)-((r)^2)))))*(-P0+(((m-1)/(2))*((We)^2)*((3)*(y(5))*((y(4))^2)))+((mu)*(hm)*(((Rc)^2)-((r)^2))*((m-1)/(2))*((We)^2)*((3)*(y(5))*((y(4))^2)))-((2)*(mu)*(hm)*(r+eps)*(y(4)))-((2)*(mu)*(hm)*(r+eps)*((m-1)/(2))*((We)^2)*((y(4))^3))-(((1)/(r+eps))*(y(4)))-(((1)/(r+eps))*((m-1)/(2))*((We)^2)*((y(4))^3))-(((1)/(r+eps))*(mu)*(hm)*(((Rc)^2)-((r)^2))*(y(4)))-(((1)/(r+eps))*(mu)*(hm)*(((Rc)^2)-((r)^2))*((m-1)/(2))*((We)^2)*((y(4))^3)));
% This equation is invalid at r = 0, so taking r+eps in the
% denominator
end
function res = baseBC(ya,yRc,yRp,yRb,P0,We,m,Da,beta,alpha,phi) % Details boundary conditions
res=[ya(4); -(yRc(4))-(((m-1)/(2))*((We)^2)*((yRc(4))^3))+(yRc(6))+(((m-1)/(2))*((We)^2)*((yRc(6))^3));
yRc(1)-yRc(2); yRp(3)-yRp(2); yRp(3)-((((Da)^(1/2))/((beta)*(phi)))*((yRp(8))-(yRp(6))));
yRb(9)-(((alpha)/((Da)^(1/2)))*((yRb(3))-((P0)*(Da))))
];
end

Réponse acceptée

Torsten
Torsten le 18 Oct 2023
@(r,y)baseBC(ya,yRc,yRp,yRb,P0,We,m,Da,beta,alpha,phi)
You don't want to use ya and yb (in your notation: r and y), namely the values of your solution variables at a and b, to define the boundary conditions ? That's impossible.
  28 commentaires
Torsten
Torsten le 24 Oct 2023
Modifié(e) : Torsten le 24 Oct 2023
Seems your conditions lead to a jump in the derivatives at x = 0.9. But that's what you programmed - I have no answer for your question. Check your transmission and boundary conditions if you think you must get a smooth curve throughout the complete interval. Did you correct the two conditions in your previous code ?
Kalyani
Kalyani le 24 Oct 2023
Did you correct the two conditions in your previous code ?
Yes, I corrected the boundary conditions and by varying some parameters, I'm able to get a smooth curve.
Thank you!!

Connectez-vous pour commenter.

Plus de réponses (1)

Walter Roberson
Walter Roberson le 18 Oct 2023
ya is a scalar. You construct an anonymous function that ignores its parameters and passes ya to a function. Inside the called function you index ya... but ya is a scalar.
  5 commentaires
Walter Roberson
Walter Roberson le 19 Oct 2023
When I look through the pdf, it is not obvious to me that any indexing is needed.
I do see items such as but those appear to be functions such as so you would not be indexing them.
Kalyani
Kalyani le 19 Oct 2023
If I donot use indexing, then how would I define the boundary conditions? In my problem, I've three layers and so four boundaries - ya, yRc, yRp and yRb. I don't know how to define these boundaries without indexing.Can you give me some pointers?

Connectez-vous pour commenter.

Produits


Version

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by