Can't figure out where my mistake is?
조회 수: 1 (최근 30일)
이전 댓글 표시
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?
댓글 수: 0
답변 (1개)
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
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 Center 및 File Exchange에서 Boundary Value Problems에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!