MathGroup Archive 2006

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

Search the Archive

Re: "Declaring" a vector for NDSolve

  • To: mathgroup at smc.vnet.net
  • Subject: [mg70766] Re: "Declaring" a vector for NDSolve
  • From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
  • Date: Thu, 26 Oct 2006 02:39:29 -0400 (EDT)
  • References: <ehmu5d$sf7$1@smc.vnet.net>

Hi,

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

tmp[t] /. t -> 0.5

and I'm not able to understand your problem.


Eric Poolman wrote:
> Hello,
> 
> 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'[t]=A.P[t],
> 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
> 
> --------------------------------
> 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 yale.edu
> 203-589-8925 cell
> 
> 


  • Prev by Date: Re: Memory problem when multiplying large sparse matrices...
  • Next by Date: Re: two questions
  • Previous by thread: "Declaring" a vector for NDSolve
  • Next by thread: Re: [TS 27522]--Re:Re: PageWidth option is not measured in characters