help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: bug in fsolve() affecting convergence depending on the returned args


From: John W. Eaton
Subject: Re: bug in fsolve() affecting convergence depending on the returned args
Date: Wed, 26 Apr 2006 03:02:39 -0400

On 26-Apr-2006, Christophe Prud'homme wrote:

| John,
| 
| I just checked info/msg and they are ok all along when I retrieve them in 
| the "good" case, and the testcase goes all the way through without problems.
| here is the log in the good case
| ===============
| % cranknic_test2
| get w and info
| info = 1
| msg = solution converged within specified tolerance
| get w and info OK
| N = 4
| get w and info
| info = 1
| msg = solution converged within specified tolerance
| get w and info OK
| N = 8
| get w and info
| info = 1
| msg = solution converged within specified tolerance
| get w and info OK
| N = 16
| get w and info
| info = 1
| msg = solution converged within specified tolerance
| get w and info OK
| N = 32
| get w and info
| info = 1
| msg = solution converged within specified tolerance
| get w and info OK
| N = 64
| ==================
| 
| However in the "bad", it _breaks_ for N=32
| here is the log
| 
| ===================
| octave:3> cranknic_test2
| get only w
| get only w OK
| N = 4
| get only w
| get only w OK
| N = 8
| get only w
| get only w OK
| N = 16
| get only w
| get only w OK
| N = 32
| get only w
| error: fsolve: iteration is not making good progress
| error: evaluating assignment expression near line 24, column 7
| error: evaluating for command near line 22, column 1
| error: called from `cranknic_bad' in file `/tmp/cranknic_bad.m'
| error: evaluating for command near line 8, column 1
| error: near line 27 of file `/tmp/cranknic_test2.m'
| ======================
| 
| PS: this code appears in the chapter on ordinary differential equations

When you get info and msg, I think you are missing the error somehow.
Please try the following change to your original code.  Then I think
you will see the error in both cases.

--- cranknic_test2.m.orig       2006-04-26 02:54:25.000000000 -0400
+++ cranknic_test2.m    2006-04-26 02:50:01.000000000 -0400
@@ -6,21 +6,28 @@
 
 N=2;
 for k=1:5
- 
+
+try
 % call good
 disp('get w and info')
 [tt,u]=cranknic_good(f,tspan,y0,N);
 t=tt(end); 
 e_good(k)=norm(u(:,end)-eval(y)); 
 disp('get w and info OK')
+catch
+  lasterr
+end
 
+try
 % call bad
 disp('get only w')
 [tt,u]=cranknic_bad(f,tspan,y0,N);
 t=tt(end); 
 e_bad(k)=norm(u(:,end)-eval(y));
 disp('get only w OK')
-
+catch
+  lasterr
+end
 
 N=2*N
 end
\ No newline at end of file
--- cranknic_good.m.orig        2006-04-26 02:54:17.000000000 -0400
+++ cranknic_good.m     2006-04-26 02:57:19.000000000 -0400
@@ -20,8 +20,12 @@
 glob_odefun=odefun;
 
 for glob_t=tt(2:end)
+  glob_t
 % get only X INFO  from fsolve (getting MSG also works)
-    [w info] = fsolve('cranknicfun',glob_y);
+    [w info msg] = fsolve('cranknicfun',glob_y);
+    if (info != 1)
+      error (msg);
+    end
     u = [u w];
     glob_y = w;
 end
--- cranknic_bad.m.orig 2006-04-26 02:47:34.000000000 -0400
+++ cranknic_bad.m      2006-04-26 03:01:35.000000000 -0400
@@ -20,6 +20,7 @@
 glob_odefun=odefun;
 
 for glob_t=tt(2:end)
+  glob_t
 % get only X from fsolve
     w = fsolve('cranknicfun',glob_y);
     u = [u w];


When I run the modified code, I see:

  [...]
  glob_t = 8.1250
  glob_t = 8.7500
  glob_t = 9.3750
  glob_t = 10
  get only w OK
  N = 32
  get w and info
  glob_t = 0.31250
  ans = error: iteration is not making good progress

  get only w
  glob_t = 0.31250
  ans = error: fsolve: iteration is not making good progress

  N = 64

So the error happens for N = 32 on the first time through the loop
over the elements of tt(2:end).  Are you not checking info each time
fsolve is called?  If not then you could miss a case that is bad and
only see the last call which might be OK.

OTOH, I think that "iteration is not making good progress" does not
necessarily mean the solution is really bad.  I think it just means
that convergence seems to be slow.

jwe


reply via email to

[Prev in Thread] Current Thread [Next in Thread]