Anyone who can help on the bvp4c code?

The models to be solved are for the Maxwell fluid:
Honorsboundary01()
Error using bvp4c (line 100)
Unable to solve the collocation equations -- a singular Jacobian encountered.

Error in solution>Honorsboundary01 (line 46)
sol=bvp4c(@odefun,@BCfun,solinit,options);
function Honorsboundary01
%Special variables
M=1; %Magnetic parameter
gamma=1; % Porosity parameter
Rd=1; %Radiation parameter
lambda=1; %Heat Souce parameter
Pr=1; %Prandtl number
Ec=2; %Eckert number
De=2; %Deboarh number has a range of 0<De<0.1 else the solution may explode
GrT=2;%Thermal Grashof number holds for range 0<GrT<1
GrC=2;%Concentration Grashof number
Le=2;% Lewis number
%System of first order equations
function dydx=odefun(~,y)
dydx=zeros(7,1);
dydx(1)=y(2);
dydx(2)=y(3);
dydx(3)=((M+gamma)*y(2)+(y(2)^2)-(M.*De+1)*y(1)*y(3)-GrT*y(4)-GrC*y(6)-2*De*y(1)*y(2)*y(3))/(1-De*(y(1)^2));
dydx(4)=y(5);
dydx(5)=(y(4)*y(2)-y(1)*y(5)-Ec*(y(3)^2)-M.*Ec*(y(2)^2)-lambda*y(4))/((1/Pr)*(1+(4/3)*Rd));
dydx(6)=y(6);
dydx(7)=Le*y(1)*y(7);
end
%Boundary conditions of the study
function Res=BCfun(ya,yb)
Res=zeros(7,1);
Res(1)=ya(1);
Res(2)=ya(2)-1;
Res(3)=ya(4)-1;
Res(4)=ya(6)-1;
Res(5)=yb(2);
Res(6)=yb(4);
Res(7)=yb(6);
end
%Initial guess for the problem
solinit=bvpinit(linspace(0,20,10),[0 0 0 0 0 0 0]);
% Vector used for studying the parameter variations
%Implementation of the bvp5c
options=bvpset('RelTol',1e-10,'AbsTol',1e-10);
sol=bvp4c(@odefun,@BCfun,solinit,options);
eta=linspace(0,10,400);
y=deval(sol,eta);
%
% Cfx(j)=y(3,1);
% Nux(j)=-(1+(4/3)*Rd(i))*y(5,1);
% Shx(j)=-y(7,1);
% Plots
figure(1);
plot(eta,y(1,:),Linestyle='--',LineWidth=2);
xlabel("\eta");
ylabel("f(\eta)");
hold on
figure(2);
plot(eta,y(2,:),Linestyle='-',LineWidth=2);
xlabel("\eta");
ylabel("f'(\eta)");
hold on
figure(3);
plot(eta,y(3,:),Linestyle='-',LineWidth=2);
xlabel("\eta");
ylabel("f''(\eta)");
hold on
figure(4);
plot(eta,y(4,:),Linestyle='-',LineWidth=2);
xlabel("\eta");
ylabel("\theta(\eta)");
hold on
figure(5);
plot(eta,y(5,:),Linestyle='-',LineWidth=2);
xlabel("\eta");
ylabel("\theta'(\eta)");
hold on
% figure(6)
% plot(M,Cfx,Cl(i),LineWidth=2);
% xlabel('M');
% ylabel("$(1/2)Re_{x}^{(1/2)}$",Interpreter="latex");
% hold on
% figure(7)
% plot(M,Nux,Cl(i),LineWidth=2);
% xlabel('M');
% ylabel("$Re_{x}^{-(1/2)}Nu_{x}$",Interpreter="latex");
% hold on
% figure(8)
% plot(M,Shx,Cl(i),LineWidth=2);
% xlabel('M');
% ylabel("$Re_{x}^{-(1/2)}Sh_{x}$",Interpreter="latex");
% hold on
figure(1);
legend([repmat('M=',length(M),1),num2str(M')]);
figure(2);
legend([repmat('M=',length(M),1),num2str(M')]);
figure(3);
legend([repmat('M=',length(M),1),num2str(M')]);
figure(4);
legend([repmat('M=',length(M),1),num2str(M')]);
figure(5);
legend([repmat('M=',length(M),1),num2str(M')]);
%fprintf('%.10f\n ',y(5,1));
end

2 comentarios

Torsten
Torsten el 26 de Abr. de 2026 a las 11:24
I didn't test if this solves the problem, but
dydx(6)=y(6);
should be
dydx(6)=y(7);
Testing what @Torsten found.
If the NMax parameter of bvpset is configured to more than roughly 2e4, then insetad of mesh tolerance, you get a singular jocobian.
Honorsboundary01()
Warning: Unable to meet the tolerance without using more than 1428 mesh points.
The last mesh of 730 points and the solution are available in the output argument.
The maximum residual is 111.107, while requested accuracy is 1e-10.
function Honorsboundary01
%Special variables
M=1; %Magnetic parameter
gamma=1; % Porosity parameter
Rd=1; %Radiation parameter
lambda=1; %Heat Souce parameter
Pr=1; %Prandtl number
Ec=2; %Eckert number
De=2; %Deboarh number has a range of 0<De<0.1 else the solution may explode
GrT=2;%Thermal Grashof number holds for range 0<GrT<1
GrC=2;%Concentration Grashof number
Le=2;% Lewis number
%System of first order equations
function dydx=odefun(~,y)
dydx=zeros(7,1);
dydx(1)=y(2);
dydx(2)=y(3);
dydx(3)=((M+gamma)*y(2)+(y(2)^2)-(M.*De+1)*y(1)*y(3)-GrT*y(4)-GrC*y(6)-2*De*y(1)*y(2)*y(3))/(1-De*(y(1)^2));
dydx(4)=y(5);
dydx(5)=(y(4)*y(2)-y(1)*y(5)-Ec*(y(3)^2)-M.*Ec*(y(2)^2)-lambda*y(4))/((1/Pr)*(1+(4/3)*Rd));
dydx(6)=y(7);
dydx(7)=Le*y(1)*y(7);
end
%Boundary conditions of the study
function Res=BCfun(ya,yb)
Res=zeros(7,1);
Res(1)=ya(1);
Res(2)=ya(2)-1;
Res(3)=ya(4)-1;
Res(4)=ya(6)-1;
Res(5)=yb(2);
Res(6)=yb(4);
Res(7)=yb(6);
end
%Initial guess for the problem
solinit=bvpinit(linspace(0,20,10),[0 0 0 0 0 0 0]);
% Vector used for studying the parameter variations
%Implementation of the bvp5c
options=bvpset('RelTol',1e-10,'AbsTol',1e-10);
sol=bvp4c(@odefun,@BCfun,solinit,options);
eta=linspace(0,10,400);
y=deval(sol,eta);
%
% Cfx(j)=y(3,1);
% Nux(j)=-(1+(4/3)*Rd(i))*y(5,1);
% Shx(j)=-y(7,1);
% Plots
figure(1);
plot(eta,y(1,:),Linestyle='--',LineWidth=2);
xlabel("\eta");
ylabel("f(\eta)");
hold on
figure(2);
plot(eta,y(2,:),Linestyle='-',LineWidth=2);
xlabel("\eta");
ylabel("f'(\eta)");
hold on
figure(3);
plot(eta,y(3,:),Linestyle='-',LineWidth=2);
xlabel("\eta");
ylabel("f''(\eta)");
hold on
figure(4);
plot(eta,y(4,:),Linestyle='-',LineWidth=2);
xlabel("\eta");
ylabel("\theta(\eta)");
hold on
figure(5);
plot(eta,y(5,:),Linestyle='-',LineWidth=2);
xlabel("\eta");
ylabel("\theta'(\eta)");
hold on
% figure(6)
% plot(M,Cfx,Cl(i),LineWidth=2);
% xlabel('M');
% ylabel("$(1/2)Re_{x}^{(1/2)}$",Interpreter="latex");
% hold on
% figure(7)
% plot(M,Nux,Cl(i),LineWidth=2);
% xlabel('M');
% ylabel("$Re_{x}^{-(1/2)}Nu_{x}$",Interpreter="latex");
% hold on
% figure(8)
% plot(M,Shx,Cl(i),LineWidth=2);
% xlabel('M');
% ylabel("$Re_{x}^{-(1/2)}Sh_{x}$",Interpreter="latex");
% hold on
figure(1);
legend([repmat('M=',length(M),1),num2str(M')]);
figure(2);
legend([repmat('M=',length(M),1),num2str(M')]);
figure(3);
legend([repmat('M=',length(M),1),num2str(M')]);
figure(4);
legend([repmat('M=',length(M),1),num2str(M')]);
figure(5);
legend([repmat('M=',length(M),1),num2str(M')]);
%fprintf('%.10f\n ',y(5,1));
end

Iniciar sesión para comentar.

Respuestas (1)

Torsten
Torsten hace 29 minutos
Editada: Torsten hace 17 minutos
Reducing the Deborah number gives smooth results.
I guess 1-De*max(f)^2 (i.e. the factor in front of f''') should remain positive during the computation.
L = 10;
N = 50;
xmesh = linspace(0,L,100);
M = 1; %Magnetic parameter
gamma = 1; %Porosity parameter
Rd = 1; %Radiation parameter
lambda = 1; %Heat Souce parameter
Pr = 1; %Prandtl number
Ec = 2; %Eckert number
De = 0.2; %Deboarh number has a range of 0<De<0.1 else the solution may explode
GrT = 2; %Thermal Grashof number holds for range 0<GrT<1
GrC = 2; %Concentration Grashof number
Le = 2; %Lewis number
% Fsolve
[D,x] = cheb(N);
eta = L/2*(1-x);
u10 = 1 - exp(-eta);
u20 = exp(-eta);
u30 = -exp(-eta);
u40 = exp(-eta);
u50 = -exp(-eta);
u60 = exp(-eta);
u70 = -exp(-eta);
%
u0 = [u10;u20;u30;u40;u50;u60;u70];
options = optimset('TolX',1e-8,'TolFun',1e-8,'MaxFunEvals',100000,'MaxIter',100000);
%
[sol_fsolve,fval,info] = fsolve(@(u)Maxwell_fsolve(L,N,...
D,u,...
M,gamma,Rd,lambda,Pr,Ec,De,GrT,GrC,Le),u0,options);
Equation solved. fsolve completed because the vector of function values is near zero as measured by the value of the function tolerance, and the problem appears regular as measured by the gradient.
sol_fsolve = reshape(sol_fsolve,[],7);
info
info = 1
norm(fval,Inf)
ans = 5.7170e-11
sol_fsolve = interp1(eta,sol_fsolve,xmesh);
figure(1)
plot(xmesh,sol_fsolve(:,1))
figure(2)
plot(xmesh,sol_fsolve(:,2))
figure(3)
plot(xmesh,sol_fsolve(:,3))
figure(4)
plot(xmesh,sol_fsolve(:,4))
figure(5)
plot(xmesh,sol_fsolve(:,5))
figure(6)
plot(xmesh,sol_fsolve(:,6))
figure(7)
plot(xmesh,sol_fsolve(:,7))
function res = Maxwell_fsolve(L,N,...
D,u_in,...
M,gamma,Rd,lambda,Pr,Ec,De,GrT,GrC,Le)
%
u1 = u_in(0*(N+1)+1:1*(N+1));
u2 = u_in(1*(N+1)+1:2*(N+1));
u3 = u_in(2*(N+1)+1:3*(N+1));
u4 = u_in(3*(N+1)+1:4*(N+1));
u5 = u_in(4*(N+1)+1:5*(N+1));
u6 = u_in(5*(N+1)+1:6*(N+1));
u7 = u_in(6*(N+1)+1:7*(N+1));
%
Mat1 = diag(1-De*u1.^2)*(-2/L)*D + De*2*diag(u1.*u2) + ...
(M*De+1)*diag(u1);
Mat = [-2/L*D,-eye(N+1),zeros(N+1);...
zeros(N+1),-2/L*D,-eye(N+1);...
zeros(N+1),-diag((M+gamma)*ones(N+1,1)),Mat1;...
[1,zeros(1,N)],zeros(1,N+1),zeros(1,N+1);...
zeros(1,N+1),[1,zeros(1,N)],zeros(1,N+1);...
zeros(1,N+1),[zeros(1,N),1],zeros(1,N+1)];
rhs = [zeros(N+1,1);zeros(N+1,1);u2.^2 - GrT*u4 - GrC*u6;0;1;0];
u123 = Mat\rhs;
%
Mat = [-2/L*D,-eye(N+1);...
diag(lambda-u2),1/Pr*(1+4/3*Rd)*(-2/L)*D + diag(u1);...
[1,zeros(1,N)],zeros(1,N+1);...
[zeros(1,N),1],zeros(1,N+1)];
rhs = [zeros(N+1,1);-Ec*u3.^2-M*Ec*u2.^2;1;0];
u45 = Mat\rhs;
%
Mat = [-2/L*D,-eye(N+1);...
zeros(N+1),-2/L*D-Le*diag(u1);...
[1,zeros(1,N)],zeros(1,N+1);...
[zeros(1,N),1],zeros(1,N+1)];
rhs = [zeros(N+1,1);zeros(N+1,1);1;0];
u67 = Mat\rhs;
%
res = [u123;u45;u67] - u_in;
end
function [D, x] = cheb(N)
if N == 0
D = 0;
x = 1;
return
end
x = cos(pi * (0:N) / N)';
c = [2; ones(N - 1, 1); 2] .* (-1).^(0:N)';
X = repmat(x, 1, N + 1);
dX = X - X';
D = (c * (1 ./ c)')./(dX + (eye(N + 1)));
D = D - diag(sum(D, 2));
end

Categorías

Más información sobre Fluid Dynamics en Centro de ayuda y File Exchange.

Productos

Etiquetas

Preguntada:

P
P
el 26 de Abr. de 2026 a las 10:15

Editada:

el 29 de Abr. de 2026 a las 10:17

Community Treasure Hunt

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

Start Hunting!

Translated by