Solution of a system of ODEs by means of bvp4c
9 views (last 30 days)
Show older comments
Hi eveyone,
I am trying to solve the following problem thorugh the bvp4c solver:
clear,clc,close all
%% coordinate
R=1e-3;
%% xmesh command
xmesh = linspace(1e-8,R,50);
%% bvp4c
solinit = bvpinit(xmesh, @guess);
sol = bvp4c(@bvpfcn, @bcfcn, solinit);
plot(sol.x,sol.y(1,:))
where, in separated .m files, I defined:
function dydx = bvpfcn(r,y)
k_0=3508;
n=0.2;
T0=373.15;
a=0.01;
k=0.18;
k0=3508;
dP=100;
dZ=1e-3;
dydx = zeros(5,1);
dydx = [y(2)
(k0*exp(a*T0-y(1))*(((dP/dZ)*(r/2)*(1/k0*exp(a*(T0-y(1)))))^((n+1)/n))*(r/k)-y(2))*(1/r)
(((dP/dZ)*(r/2)*(1/k0*exp(a*(T0-y(1)))))^((1)/n))
y(5)
-(a*k0*exp(a*T0-y(1))*y(4)*(((dP/dZ)*(r/2)*(1/k0*exp(a*(T0-y(1)))))^((n+1)/n))*(r/k)-y(5))*(1/r)];
end
function res = bcfcn(ya,yb)
Tw=500;
res = [ yb(3)
yb(1)-Tw
ya(2)
yb(4)
ya(5)];
end
function g = guess(x)
Tw=500;
g = [Tw
x^2
x^2
x
x^0.5];
end
The following error is returned:
Error using bvp4c (line 197)
Unable to solve the collocation equations -- a singular Jacobian encountered.
Error in untitled5 (line 11)
sol = bvp4c(@bvpfcn, @bcfcn, solinit);
I would appreciate Your help in finding the solution to this problem.
Best regards,
AP
0 Comments
Answers (2)
Star Strider
on 15 Oct 2022
The singlular Jacobian was likely the result of the ‘(1/r)’ term, since ‘r’ initially begins at 0. While changing that removed the error, it likely does not do much for the result —
%% coordinate
R=1e-3;
%% xmesh command
xmesh = linspace(1E-8,R,50);
%% bvp4c
solinit = bvpinit(xmesh, @guess);
sol = bvp4c(@bvpfcn, @bcfcn, solinit)
r = sol.x;
y = sol.y;
figure
semilogy(r, real(y))
grid
figure
semilogy(r, abs(y))
grid
% where, in separated .m files, I defined:
function dydx = bvpfcn(r,y)
k_0=3508;
n=0.2;
T0=373.15;
a=0.01;
k=0.18;
k0=3508;
dP=100;
dZ=1e-3;
dydx = zeros(5,1);
dydx = [y(2)
(k0*exp(a*T0-y(1))*(((dP/dZ)*(r/2)*(1/k0*exp(a*(T0-y(1)))))^((n+1)/n))*(r/k)-y(2))*(1/r)
(((dP/dZ)*(r/2)*(1/k0*exp(a*(T0-y(1)))))^((1)/n))
y(5)
-(a*k0*exp(a*T0-y(1))*y(4)*(((dP/dZ)*(r/2)*(1/k0*exp(a*(T0-y(1)))))^((n+1)/n))*(r/k)-y(5))*(1/r)];
end
function res = bcfcn(ya,yb)
Tw=500;
res = [ yb(3)
yb(1)-Tw
ya(2)
yb(4)
ya(5)];
end
function g = guess(x)
Tw=500;
g = [Tw
x^2
x^2
x
x^0.5];
end
.
0 Comments
See Also
Categories
Find more on Boundary Value Problems 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!

