BVP4C:error Unable to solve the collocation equation -- a singular jacobian encountered
3 次查看(过去 30 天)
显示 更早的评论
Hello, I am facing this error below is my code
function dYdx = bvp_func_pw1(x, Y, GrT)
%defining the constants
lambda=0.4; %second grade fluid parameter
M=5; %magnetic parameter
P=5; %porous parameter
%GrT=[1:5]; %thermal grashof numbers
GrC=1; %solatal grashof numbers
Pr=1; %prandtil number
Ec=0.1; %Eckert number
Sc=1; %Schimdit number
Kr=-0.3; %Chemical reaction paramter
alpha=2; %Heat generator or absorption paramter
%defining derivatives
%Y(1)=f0, Y(2)=f1, Y(3)=f2,Y(4)=theta, Y(5)=theta1,Y(6)=phi,
%Y(7)=phi1
dYdx(1)=Y(2);
dYdx(2)=Y(3);
dYdx(3)=(1/(2*x*Y(3)))*(Y(2)^2-Y(1)*Y(3)+M*Y(2)+P*Y(2)-GrT*Y(4)-GrC*Y(6));
dYdx(4)=Y(5);
dYdx(5)=-Pr*Y(1)*Y(5)+Pr*(2*Y(2)-alpha)*Y(4)-Pr*Ec*(Y(3)^2+lambda*Y(3)*(Y(2)*Y(3)-Y(1)*dYdx(3))+M*Y(2)^2);
dYdx(6)=Y(7);
dYdx(7)=-Sc*(Y(1)*Y(7)-Kr*Y(6));
dYdx=dYdx(:);
end
function bc = boundary_conditions_pw(Ya,Yb,GrT)
%boundary conditions at x=0 and x=infinity
%boundary conditions at x=0
bc1=[Ya(1); Ya(2)-1; Ya(4)-1; Ya(6)-1];
%boundary conditions at x=infinity
bc2=[Yb(2); Yb(4); Yb(6)];
bc=[bc1;bc2];
end
2 个评论
Torsten
2023-4-22
Please include the part of the code in which you call bvp4c.
If your x-interval contains 0, the error can be explained by the term (1/(2*x*Y(3))) where you would get a division by zero.
采纳的回答
Torsten
2023-4-22
编辑:Torsten
2023-4-23
As I said before: Remove x=0 from your interval of integration to avoid a division-by-zero.
Nonetheless, bvp4c has problems with your equations. You should check for programming errors or errors in the mathematical formulation of the problem.
%define space from 0 to 2
x=linspace(1e-6,2,11);
GrT=0;
%initial guess for the answer
guess= bvpinit(x,[1;0;1;0;0;1;1]);
%setting options
options = bvpset('Stats','on','RelTol',10e-4,'AbsTol',10e-7);
hold on
for i = 1:5
GrT=GrT+1;
%calling bvp4c to solve the boundary value problem
sol=bvp4c(@(x,y)bvp_func_pw1(x,y,GrT),@boundary_conditions_pw,guess,options);
%export solution
f = sol.y;
if GrT==1
f_1=f(1,:);
f_11=f(2,:);
X_1=sol.x;
elseif GrT==2
f_2=f(1,:);
f_22=f(2,:);
X_2=sol.x;
elseif GrT==3
f_3=f(1,:);
f_33=f(2,:);
X_3=sol.x;
elseif GrT==4
f_4=f(1,:);
f_44=f(2,:);
X_4=sol.x;
elseif GrT==5
f_5=f(1,:);
f_55=f(2,:);
X_5=sol.x;
end
end
plot(X_1,f_1,X_2,f_2,X_3,f_3,X_4,f_4,X_5,f_5)
grid on
function dYdx = bvp_func_pw1(x, Y, GrT)
%defining the constants
lambda=0.4; %second grade fluid parameter
M=5; %magnetic parameter
P=5; %porous parameter
%GrT=[1:5]; %thermal grashof numbers
GrC=1; %solatal grashof numbers
Pr=1; %prandtil number
Ec=0.1; %Eckert number
Sc=1; %Schimdit number
Kr=-0.3; %Chemical reaction paramter
alpha=2; %Heat generator or absorption paramter
%defining derivatives
%Y(1)=f0, Y(2)=f1, Y(3)=f2,Y(4)=theta, Y(5)=theta1,Y(6)=phi,
%Y(7)=phi1
dYdx(1)=Y(2);
dYdx(2)=Y(3);
dYdx(3)=(1/(2*x*Y(3)))*(Y(2)^2-Y(1)*Y(3)+M*Y(2)+P*Y(2)-GrT*Y(4)-GrC*Y(6));
dYdx(4)=Y(5);
dYdx(5)=-Pr*Y(1)*Y(5)+Pr*(2*Y(2)-alpha)*Y(4)-Pr*Ec*(Y(3)^2+lambda*Y(3)*(Y(2)*Y(3)-Y(1)*dYdx(3))+M*Y(2)^2);
dYdx(6)=Y(7);
dYdx(7)=-Sc*(Y(1)*Y(7)-Kr*Y(6));
dYdx=dYdx(:);
end
function bc = boundary_conditions_pw(Ya,Yb)
%boundary conditions at x=0 and x=infinity
%boundary conditions at x=0
bc1=[Ya(1); Ya(2)-1; Ya(4)-1; Ya(6)-1];
%boundary conditions at x=infinity
bc2=[Yb(2); Yb(4); Yb(6)];
bc=[bc1;bc2];
end
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!