Can't figure out where my mistake is?

1 次查看(过去 30 天)
Aaron
Aaron 2013-9-16
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;
%
%
xlow=Z;
xhigh=L;
solinit=bvpinit(linspace(Z,L,20),[Z 0]);
sol=bvp4c(@bvpode,@bvpbc,solinit);
plot(sol.x,sol.p(2,:),'b--');
%
%
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?

回答(1 个)

Walter Roberson
Walter Roberson 2013-9-16
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 ?
  2 个评论
Aaron
Aaron 2013-9-17
I've been trying to figure out where I messed up. I just can't find the error?
Walter Roberson
Walter Roberson 2013-9-17
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?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Boundary Value Problems 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by