Info

This question is closed. Reopen it to edit or answer.

Error: a singular Jacobian encountered When I use bvp4c

1 view (last 30 days)
Sho
Sho on 10 Dec 2014
Closed: MATLAB Answer Bot on 20 Aug 2021
This is my first time using bvp4c.
I don't know why but when I run the code below, I get error message that a singular Jacobian encountered.
It is strange because first time I run the code with
C1 = 2.6247e+16;
C2 = 1.6201e+15;
C3 = 3.7795e+17;
though I got a warning, it worked. Then I found a mistake and changed these constants to correct ones. And the error appeared.
Could you help me to find my mistake?
% ****************************my code**************************** %
function fcn
clear
n1 = 0;
n2 = 1;
C1 = 2.6247e-2;
C2 = 1.6201;
C3 = 3.7795e+2;
a = 0;
b = 10;
step = 0.01;
solinit = bvpinit(linspace(a,b,10),@schrodINIT);
sol = bvp4c(@schrodODE,@schrodBC,solinit);
z = linspace(a,b,b/step+1);
fint = deval(sol,z);
f = fint(1,:);
plot(z,f,'-');
% *************************** set ODE *************************** %
function dydx=schrodODE(x,y)
if x==0
dydx=[ 0
0 ];
else
X = x*1.0e-8;
dydx=[ y(2)
y(1)*(C1*x^2+C2*(n1+1)+C3/x-(n2/x)^2)-y(2)/x ];
end
end
% **************************** set BC *************************** %
function res=schrodBC(ya,yb)
res=[ ya(1)
ya(2)-1];
end
% ********************* set initial function ******************** %
function yinit=schrodINIT(x)
b1=1.0;
if x==a
yinit=[ 0
1]; % end point B.C.
else
yinit=[ x/exp(b1*x)
b1*(b1*x-2)/exp(b1*x)];
end
end
% *************************************************************** %
end
  1 Comment
Torsten
Torsten on 10 Dec 2014
Your problem is an IVP, not a BVP (both boundary conditions are given at x=a).
Use an ODE integrator to solve it (e.g. ODE45).
Best wishes
Torsten.

Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!