Why do I get the error "Subscript indices must either be real positive integers or logicals." ?
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
function GrCbvpthickn
% The effect of the solutal buoyancy parameter on the fluid velocity
% profiles is modelled.
clc;
%define space from 0 to 2
x=linspace(0,2,11);
GrC=0;
%initial guess for the answer
guess= bvpinit(x,[1;0;0;0;1;0;1;0]);
%setting options
options = bvpset('Stats','on');
hold on
for i = 1:5
GrC=GrC+1;
%calling bvp4c to solve the boundary value problem
sol=bvp4c(@bvp_func_g2,@boundary_conditions,guess,options,GrC);
%export solution
f = sol.y;
if GrC==1
f_1=f(1,:);
f_11=f(2,:);
X_1=sol.x;
else if GrC==2
f_2=f(1,:);
f_22=f(2,:);
X_2=sol.x;
else if GrC==3
f_3=f(1,:);
f_33=f(2,:);
X_3=sol.x;
else if GrC==4
f_4=f(1,:);
f_44=f(2,:);
X_4=sol.x;
else if GrC==5
f_5=f(1,:);
f_55=f(2,:);
X_5=sol.x;
end
end
end
end
end
end
l=length(f);
%plotting the solutions of f with GrT parameter
figure
plot(X_1,f_1,X_2,f_2,X_3,f_3,X_4,f_4,X_5,f_5)
legend('GrC=1','GrC=2','GrC=3','GrC=4','GrC=5')
title('The influence of solutal Grashof number on radial velocity profile')
xlabel('x')
ylabel('radial velocity,f(x)')
%plotting the solutions of f' with GrT parameter
figure
plot(X_1,f_11,X_2,f_22,X_3,f_33,X_4,f_44,X_5,f_55)
legend('GrC=1','GrC=2','GrC=3','GrC=4','GrC=5')
title('The influence of solutal Grashof number on axial velocity profile')
xlabel('x')
ylabel('axial velocity,df(x)/dx')
hold off
%----------------------------------------------------------------------------------------------------------
function dYdx = bvp_func_g2(x, Y, GrC)
%The system of first order ODEs is defined in this function with necessary
%values for parameters
%defining the constants
m=2;
J=1; %first second grade fluid parameter
L=1; %second second grade fluid parameter
M=4; %magnetic parameter
P=4; %porous parameter
GrT=2; %thermal grashof numbers
%GrC=1; %solatal grashof numbers
Pr=3; %prandtil number
Ec=1; %Eckert number
Sc=1; %Schimdit number
Kr=-0.3; %Chemical reaction paramter
alpha=1; %Heat generator or absorption paramter
H=1;
%defining derivatives
%Y(1)=f0, Y(2)=f1, Y(3)=f2,Y(4)=f3,Y(5)=theta, Y(6)=theta1,Y(7)=phi,
%Y(8)=phi1
dYdx(1)=Y(2);
dYdx(2)=Y(3);
dYdx(3)=Y(4);
dYdx(4)=1/((m-1)*x*Y(2)+((m+1)/2)*Y(1))*((1/J)*(m*Y(2)+((m-1)/sqrt(2))*x*Y(3)*Y(2)+((m+1)/2)*Y(3)*Y(1)+((m-1)/2)*x*Y(3)*Y(2)-(((m+1)^2)/2)*Y(4)*(L*Y(3))^(m/2)+M*Y(2)+P*Y(2)-GrT*Y(5)-GrC*Y(7))-(3*m-2)*Y(2)*Y(4)-((m-1)/2+((m-1)/sqrt(2))*x)*Y(3)*Y(4)-m*Y(4)*Y(1));
dYdx(5)=Y(6);
dYdx(6)=(2/(m+1))*(Pr*(Y(2)*Y(6)*((m-1)/2)*x+2*Y(5)*(((m+1)^2)/2)*(Y(1)+((m-1)/(m+1))*x*Y(1))-alpha*Y(5))-Pr*Ec(((m+1)/2)*Y(3)^2+J(m*Y(2)*Y(3)+x*((m-1)/2)*Y(3)^2+Y(2)*(Y(4)+Y(4)*x)+((m+1)/2)*(Y(2)*(1+((m-1)/(m+1)))+Y(3)*((m-1)/(m+1))))+H*(Y(1)*dYdx(4)+((m-1)/(m+1))*x*Y(2)*dYdx(4))+M*Y(2)^2));
dYdx(7)=Y(8);
dYdx(8)=(1/(m+1))*(Sc(Y(2)*Y(8)*x*(m-1)+(m+1)*(Y(1)+((m-1)/(m+1))*x*Y(2))+Kr*Y(7)));
dYdx=dYdx(:);
%-------------------------------------------------------------------------------------------------------------------------
function bc = boundary_conditions(Ya,Yb,GrC)
%boundary conditions at eta=1 and when eta goes to infinity is defined
%here as boundary a and b
%boundary conditions at x=0 and x=infinity
%boundary conditions at x=0
bc1=[Ya(1); Ya(2)-1; Ya(5)-1; Ya(7)-1];
%boundary conditions at x=infinity
bc2=[Yb(2); Yb(3); Yb(5); Yb(7)];
bc=[bc1;bc2];
this is my code and i get the error:
Subscript indices must either be real positive integers or logicals.
Error in GrCbvpthickn>bvp_func_g2 (line 107)
dYdx(6)=(2/(m+1))*(Pr*(Y(2)*Y(6)*((m-1)/2)*x+2*Y(5)*(((m+1)^2)/2)*(Y(1)+((m-1)/(m+1))*x*Y(1))-alpha*Y(5))-Pr*Ec(((m+1)/2)*Y(3)^2+J(m*Y(2)*Y(3)+x*((m-1)/2)*Y(3)^2+Y(2)*(Y(4)+Y(4)*x)+((m+1)/2)*(Y(2)*(1+((m-1)/(m+1)))+Y(3)*((m-1)/(m+1))))+H*(Y(1)*dYdx(4)+((m-1)/(m+1))*x*Y(2)*dYdx(4))+M*Y(2)^2));
Error in bvparguments (line 105)
testODE = ode(x1,y1,odeExtras{:});
Error in bvp4c (line 130)
bvparguments(solver_name,ode,bc,solinit,options,varargin);
Error in GrCbvpthickn (line 22)
sol=bvp4c(@bvp_func_g2,@boundary_conditions,guess,options,GrC);
0 comentarios
Respuestas (2)
Image Analyst
el 15 de Jul. de 2023
We get this asked every day. It's our most FAQQY of FAQs, so see the FAQ for a thorough discussion:
6 comentarios
Star Strider
el 15 de Jul. de 2023
Wioth the additional multiplicationo operators in ‘dYdx(6)’ and ‘dYdx(8)’ it appears to run without error —
%define space from 0 to 2
x=linspace(0,2,11);
GrC=0;
%initial guess for the answer
guess= bvpinit(x,[1;0;0;0;1;0;1;0]);
%setting options
options = bvpset('Stats','on');
% hold on
for i = 1:5
GrC=GrC+1;
%calling bvp4c to solve the boundary value problem
sol=bvp4c(@bvp_func_g2,@boundary_conditions,guess,options,GrC);
%export solution
f = sol.y;
if GrC==1
f_1=f(1,:);
f_11=f(2,:);
X_1=sol.x;
else if GrC==2
f_2=f(1,:);
f_22=f(2,:);
X_2=sol.x;
else if GrC==3
f_3=f(1,:);
f_33=f(2,:);
X_3=sol.x;
else if GrC==4
f_4=f(1,:);
f_44=f(2,:);
X_4=sol.x;
else if GrC==5
f_5=f(1,:);
f_55=f(2,:);
X_5=sol.x;
end
end
end
end
end
end
l=length(f);
%plotting the solutions of f with GrT parameter
figure
plot(X_1,f_1,X_2,f_2,X_3,f_3,X_4,f_4,X_5,f_5)
legend('GrC=1','GrC=2','GrC=3','GrC=4','GrC=5')
title('The influence of solutal Grashof number on radial velocity profile')
xlabel('x')
ylabel('radial velocity,f(x)')
%plotting the solutions of f' with GrT parameter
figure
plot(X_1,f_11,X_2,f_22,X_3,f_33,X_4,f_44,X_5,f_55)
legend('GrC=1','GrC=2','GrC=3','GrC=4','GrC=5')
title('The influence of solutal Grashof number on axial velocity profile')
xlabel('x')
ylabel('axial velocity,df(x)/dx')
hold off
%----------------------------------------------------------------------------------------------------------
function bc = boundary_conditions(Ya,Yb,GrC)
%boundary conditions at eta=1 and when eta goes to infinity is defined
%here as boundary a and b
%boundary conditions at x=0 and x=infinity
%boundary conditions at x=0
bc1=[Ya(1); Ya(2)-1; Ya(5)-1; Ya(7)-1];
%boundary conditions at x=infinity
bc2=[Yb(2); Yb(3); Yb(5); Yb(7)];
bc=[bc1;bc2];
end
function dYdx = bvp_func_g2(x, Y, GrC)
%The system of first order ODEs is defined in this function with necessary
%values for parameters
%defining the constants
m=2;
J=1; %first second grade fluid parameter
L=1; %second second grade fluid parameter
M=4; %magnetic parameter
P=4; %porous parameter
GrT=2; %thermal grashof numbers
%GrC=1; %solatal grashof numbers
Pr=3; %prandtil number
Ec=1; %Eckert number
Sc=1; %Schimdit number
Kr=-0.3; %Chemical reaction paramter
alpha=1; %Heat generator or absorption paramter
H=1;
%defining derivatives
%Y(1)=f0, Y(2)=f1, Y(3)=f2,Y(4)=f3,Y(5)=theta, Y(6)=theta1,Y(7)=phi,
%Y(8)=phi1
dYdx(1)=Y(2);
dYdx(2)=Y(3);
dYdx(3)=Y(4);
dYdx(4)=1/((m-1)*x*Y(2)+((m+1)/2)*Y(1))*((1/J)*(m*Y(2)+((m-1)/sqrt(2))*x*Y(3)*Y(2)+((m+1)/2)*Y(3)*Y(1)+((m-1)/2)*x*Y(3)*Y(2)-(((m+1)^2)/2)*Y(4)*(L*Y(3))^(m/2)+M*Y(2)+P*Y(2)-GrT*Y(5)-GrC*Y(7))-(3*m-2)*Y(2)*Y(4)-((m-1)/2+((m-1)/sqrt(2))*x)*Y(3)*Y(4)-m*Y(4)*Y(1));
dYdx(5)=Y(6);
dYdx(6)=(2/(m+1))*(Pr*(Y(2)*Y(6)*((m-1)/2)*x+2*Y(5)*(((m+1)^2)/2)*(Y(1)+((m-1)/(m+1))*x*Y(1))-alpha*Y(5))-Pr*Ec*(((m+1)/2)*Y(3)^2+J*(m*Y(2)*Y(3)+x*((m-1)/2)*Y(3)^2+Y(2)*(Y(4)+Y(4)*x)+((m+1)/2)*(Y(2)*(1+((m-1)/(m+1)))+Y(3)*((m-1)/(m+1))))+H*(Y(1)*dYdx(4)+((m-1)/(m+1))*x*Y(2)*dYdx(4))+M*Y(2)^2));
dYdx(7)=Y(8);
dYdx(8)=(1/(m+1))*(Sc*(Y(2)*Y(8)*x*(m-1)+(m+1)*(Y(1)+((m-1)/(m+1))*x*Y(2))+Kr*Y(7)));
dYdx=dYdx(:);
end
%-------------------------------------------------------------------------------------------------------------------------
.
0 comentarios
Ver también
Categorías
Más información sobre Run-Time Parameters en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!