MathGroup Archive 2006

[Date Index] [Thread Index] [Author Index]

Search the Archive

"Declaring" a vector for NDSolve

  • To: mathgroup at
  • Subject: [mg70734] "Declaring" a vector for NDSolve
  • From: Eric Poolman <emp35 at>
  • Date: Wed, 25 Oct 2006 01:40:00 -0400 (EDT)


I am trying to use Mathematica to solve a set of differential 
equations in an epidemiological model (of sexually-transmitted disease.)

I have been using NDSolve on a system that consists of the following 
two equations:

P[0]={0.9, 0.1, ...}

Where P is a vector and A a matrix. Initial efforts with a simple A 
went fine (Mathematica gives an error, "Part :: partw:: Part 2 of P
[t] does not exist," but it still produces a correct interpolating 
function (verified by solving the simple system with each equation 
written out separately.))

I am now complicating the matrix, A, by including in some of its 
cells functions of P[t]. In particular, some of the terms in A will 
include P[t][[1]] through P[t][[9]].  While P[t][[2]] and higher 
terms are handled "correctly" (I get the error message, but it does 
not interrupt the solving process), P[t][[1]] is not.  P[t][[1]] is 
immediately evaluated as t.

I have the following simplified formulation which shows the issue:

S = {T[t][[1]], T[t][[2]]}
ModelEqs = {T'[t] == S, T[0] == {0, 0}}
sol = NDSolve[ModelEqs, {T}, {t, 0, 1}]
T[1] /. sol

S Evaluates immediately to {t,T[t][[2]]}, which then leads to the 
final line evaluating to {{0.5,0}}, rather than {{0,0}} as it should.

My naive thought is that I need to be able to declare T[t] as a 
vector, so that  T[t][[1]] is not immediately evaluated. I do not 
know if that is a reasonable approach, or if that would work (or how 
to do it.)

I am attempting to write out the program flexibly enough to handle 
varying numbers of diseases (and thus varying dimensions for the 
matrices), and would much prefer not to write out the equations if I 
can do this generally.  If worst came to worst, I suspect I could use 

subscripts instead of indices and generate each equation, but the 
matrix solution would be much more elegant (excepting this one issue.)

Thanks in advance; any guidance is appreciated.


Eric Poolman, MD, MBA
Post-doctoral Fellow
Epidemiology of Microbial Diseases
Yale School of Medicine
60 College Street, Room 147
New Haven, CT 06520-8034
eric.poolman at
203-589-8925 cell

  • Prev by Date: Re: [TS 27419]--Re:TreePlot from DiscreteMath`GraphPlot shadows TreePlot from DiscreteMath`Tree
  • Next by Date: Re: Evaluate, /., {{...}}, etc.
  • Previous by thread: Re: [TS 27419]--Re:TreePlot from DiscreteMath`GraphPlot shadows TreePlot from DiscreteMath`Tree
  • Next by thread: Re: "Declaring" a vector for NDSolve