Can't figure out where my mistake is?

1 view (last 30 days)
Aaron on 16 Sep 2013
Trying to solve boundary value problem. I have a template to work off of but I'm not sure where I am coding wrong.
function bvp4c_prob4hw3
global L epsf epsi R T F Cint Z
% assign values to constants
L = (50*10^-9);
epsf = 80;
epsi = (8.854*10^-12);
R = 8.314;
T = 298;
F = 96490;
Cint = 10;
Z = -0.05;
solinit=bvpinit(linspace(Z,L,20),[Z 0]);
function dydx=bvpode(x,p)
global L epsf epsi R T F Cint Z
dydx=[p(2) -(F*Cint/epsf*epsi)*(exp(-F*p(1)/R*T) - exp(F*p(1)/R*T))];
function res=bvpbc(ya,yb)
global L epsf epsi R T F Cint Z
res=[ya(1)-Z yb(1)-L];
This is the error I get:
Error using bvp4c (line 252)
Unable to solve the collocation equations -- a singular Jacobian encountered.
Error in bvp4c_prob4hw3 (line 19)
Line 252? There aren't enough lines?

Answers (1)

Walter Roberson
Walter Roberson on 16 Sep 2013
Your dydx calculation is generating NaN or infinity for at least one of the entries.
At the command prompt, give the command
dbstop if infnan
and run; it should stop when it has encountered the problem. Then try to figure out why it happened. For example could p entries become large and negative ?
Walter Roberson
Walter Roberson on 17 Sep 2013
Has the dbstop worked?
Have you tried standard debugging such as adding in a counter that prints out, so you can tell how many iterations until failure? And then putting in a breakpoint that keys on that counter, then step through looking at the arguments?

Sign in to comment.


Community Treasure Hunt

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

Start Hunting!