I get this message(Attempted to access F(5); index out of bounds because numel(F)=4.) when I run the code below..

2 views (last 30 days)
refpaper3
Index exceeds the number of array elements. Index must not exceed 4.

Error in solution>refpaper3/fsode (line 68)
F(5)=(-1/(M1*M2))*((2*M2*Omega*Y(5))+(Pr*Y(1)*Y(5))+(Du*((M1*F(7))+(2*Omega*Y(7))))+(Pr*Ec*M1*(Y(3))^2));

Error in bvparguments (line 96)
testODE = ode(x1,y1,odeExtras{:});

Error in bvp4c (line 119)
bvparguments(solver_name,ode,bc,solinit,options,varargin);

Error in solution>refpaper3 (line 40)
sol = bvp4c(@fsode,@fsbc,solinit,options);
function refpaper3
format long
%% ------------------------------------------------------------------------
% Parameters
%--------------------------------------------------------------------------
NP=200; %the number of meshpoints
eta_infty =15;
%% ------------------------------------------------------------------------
for i=1:4
A=0.1*[0 2 4 6];
Omega=A(i);
% eps=0.1; %A=0.1*[2 4 6 8 9]; %Medium porosity
% gamma=3; %A=[2 3 4 5 6];
% M=0.6; %A=[2 3 4 5 6]; %magnetic field parameter
% Omega=3; %A=[4 5 6 7 8]; %cylinder curvature parameter
Alpha=45; %curvature angel
P=0.2; %A=[3 4 5 6 7]; %porous medium parameter
Gr=0.2; %A=[0 2 3 4 5]; %themal Grashof number
Gm=0.2; %mass Grashof number
Rd=0.1; %A=0.1*[0 1 3 5 7]; %Radiation parameter
Ec=0.1; %Eckert number
Du=0.5; %A=0.1*[1 2 3 4 5]; %Defour number
Sr=0.2; %A=0.1*[2 3 4 5 6]; %Soret number
Pr=1.0; %for water7.56 %prentdl number
Sc=5; %A=[5 7 9 11 13]; %Schmidt number
Bi1=0.2;
Bi2=0.2;
% QM=0.1; %mass flux
% QH=0.24; %heat flux
%--------------------------------------------------------------------------
% Solve the problem
%--------------------------------------------------------------------------
int=ones(1,7); %We have 7 variables
int=0.*int;
% int=[0 0 -0.003 -0.35 0 0 -0.05];
options = [];
solinit = bvpinit(linspace(0,eta_infty,NP),int);
sol = bvp4c(@fsode,@fsbc,solinit,options);
eta = sol.x; %this is eta
f = sol.y; %These are the dependenat variables
FF=f(1,:);
DF=f(2,:);
DDF(i)=-f(3,1);
TH=f(4,:);
DTH(i)=f(5,1);
Fi =f(6,:);
DFi=f(7,1);
HH(i)= -2*DTH(i);
RR(i)=Omega;
%QH=(1+xi_2)*gamma+(1/Pr)*(1+((4*Rd)/3))*DTH;
%% ------------------------------------------------------------------------
% Plot the results
%--------------------------------------------------------------------------
end
%% ------------------------------------------------------------------------
% The model equations
%--------------------------------------------------------------------------
function dfdeta = fsode(eta,Y)
M1=1+(2*Omega*eta);
M2=1+(4*Rd/3);
F(1) = Y(2);
F(2) = Y(3);
F(3) =(-1/M1)*((2*Omega*Y(3))+(Y(1)*Y(3))+(Y(2)^2)-(P*Y(2))+(((Gr*Y(4))+(Gm*Y(6)))*cosd(Alpha)));
F(4)=Y(5);
F(5)=(-1/(M1*M2))*((2*M2*Omega*Y(5))+(Pr*Y(1)*Y(5))+(Du*((M1*F(7))+(2*Omega*Y(7))))+(Pr*Ec*M1*(Y(3))^2));
F(6)=Y(7);
F(7)=(-1/M1)*((2*Omega*Y(7))+(Sc*Y(1)*Y(7))+(Sr*((M1*F(5))+(2*Omega*Y(5)))));
dfdeta = [ F(1)
F(2)
F(3)
F(4)
F(5)
F(6)
F(7)
];
end
% --------------------------------------------------------------------------
function res = fsbc(ya,yb)
res = [ya(1)
ya(2)-1
ya(5)+(Bi1*(1-ya(4)))
ya(7)+(Bi2*(1-ya(6)))
yb(2)
yb(4)
yb(6)
];
end
end

Accepted Answer

Alan Stevens
Alan Stevens on 28 Jan 2024
In fsode you try to use F(7) when calculating F(5), before you have calculated F(7)!
  2 Comments
Nora Fattah Ahmed
Nora Fattah Ahmed on 28 Jan 2024
Edited: Nora Fattah Ahmed on 28 Jan 2024
No, it is F(7), not Y(7). I discovered where the problem was.The last two equations in the system I work on had to be solved together first to obtain the values of F(5) and F(7) because they depend on each other.This is the second time I discover my mistake after sending the question.but thank you so much.It's like brain refreshment..

Sign in to comment.

More Answers (0)

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!