Robert Kern schrieb:
On Mon, Nov 04, 2002 at 01:51:19PM +0100, Nils Wagner wrote:
[snip]
Traceback (most recent call last): File "ivp.py", line 46, in F return linalg.solve(A(P, Pl, M, K, t,z), f(P, M, K, z)) File "ivp.py", line 37, in A A[0:n,0:n] = (1.0-t)*(K[0:n,0:n]-z[n]*M[0:n,0:n])+t*P[0:n,0:n] TypeError: unsubscriptable object odepack.error: Error occured while calling the Python function named F
So, what has to be amended in my program ivp.py ?
First, you must return values from functions, not assign values to the name of the function.
Incorrect:
def A(): A = zeros(...)
Correct:
def A(): return zeros(...)
or
def A(): tmp = zeros(...) tmp[n,:] = ... return tmp
Secondly, I don't think you are indexing correctly in A(). A[0:n,0:n] references the whole array, not just the diagonal.
To reference a diagonal, A.flat[0:n:n+1] works if A is still contiguous.
(Side-question to everybody else: Is there a convenience function somewhere in Numeric or scipy_base that allows setting the k-diagonal of a matrix? A.flat[0:n:n+1]?)
Third, (this is what's causing the exception) you aren't actually calling P(t,z) and Pl(t,z) so Python is trying to index a function.
I've attached my modifications. By the way, is z[n] supposed to change? Because the return value of F() has n elements, not n+1. I'm surprised the code runs, but it does. If it doesn't change, then you shouldn't have to recalculate P or Pl all the time.
I have to hit the sack now, so I'll try to get back to this tomorrow.
Nils
--
Actually, A is a so-called bordered matrix. A = [A_11 a_12; a_21 0] where A_11 = (1-t)*(K-lambda*M)+ t*P a_12 = -(1-t)*M*x + t*Pl*x s_21 = x^T s_22 = 0 The first elements of z should contain the time-varying eigenvector x(t) The last element of z should be the eigenvalue, which varies with time, that is lambda=lambda(t). Nils
Robert Kern Ruddock House President kern@caltech.edu
"In the fields of hell where the grass grows high Are the graves of dreams allowed to die." -- Richard Harter
------------------------------------------------------------------------
ivp_kern.pyName: ivp_kern.py Type: Plain Text (text/plain)