MathGroup Archive 2003

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

Search the Archive

Re: Re: Summation Problem w/ 5.0

  • To: mathgroup at smc.vnet.net
  • Subject: [mg43846] Re: [mg43815] Re: Summation Problem w/ 5.0
  • From: "Peter Pein" <petsie at arcor.de>
  • Date: Wed, 8 Oct 2003 04:48:14 -0400 (EDT)
  • References: <blr1f1$3ge$1@smc.vnet.net> <200310070640.CAA14821@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

----- Original Message -----
From: "Andrea" <andrea.knorr at engr.uconn.edu>
To: mathgroup at smc.vnet.net
Subject: [mg43846] [mg43815] Re: Summation Problem w/ 5.0


> Bill Rowe <readnewscix at mail.earthlink.net> wrote in message
news:<blr1f1$3ge$1 at smc.vnet.net>...
> > On 10/4/03 at 2:05 AM, andrea.knorr at engr.uconn.edu (Andrea) wrote:
> >
> > > Has anyone else had this problem with the new version?  I have created
> > > multiple lists with multiple elements, and I am trying to sum all
> > > elements of all lists.  As output I don't get a single value; instead
> > > I get several numbers separated by a plus sign.  For example, instead
> > > of Mathematica giving "2" as output, I get "1+1".
> >
> > I am using ver 5.0 under Max OSX version 10.2.8 and do not see this
behavior. I or someone else here might be able to offer constructive
suggestions if you post the code leading to this problem.
> >
> > To reply via email subtract one hundred and nine
>
>
> I posted code Saturday morning, but it has not been added, so I will
> try again.  In my program I have created three lists, "virus",
> "uninfected", and "infected" which are concentrations at a particular
> time.  "vtime", "xtime", and "ytime" are the time points that
> correspond to the given concentration.  The function "titer" solves
> three differential equations that model a viral system.  minfcn is a
> part of nonlinear regression.  The problem I am having occurs when I
> evaluate minfcn, using the parameters published in a journal article,
> at values above a particular element of "virus", "uninfected", and
> "infected".  Here's the code:
>
> titer[lambda_, beta_, d_, k_, a_, u_] :=
>
>     Module[{soln, x, y, v, valueslist, xeval, yeval, veval},

you should get rid of unused locals (valueslist, xeval, yeval, veval).

>       soln = NDSolve[{
>             x'[t] == lambda - d x[t] - beta x[t] v[t],
>             y'[t] == beta x[t] v[t] - a y[t],
>             v'[t] == k y[t] - u v[t],
>             x[0] == 10^9, y[0] == 0, v[0] == 10^9},
>           {x, y, v}, {t, 0, 2500}];
>
>       xtiter = Evaluate[x[xtime] /. soln];
>       ytiter = Evaluate[y[ytime] /. soln];
>       vtiter = Evaluate[v[vtime] /. soln];
>
>       values = Table[Flatten[{xtiter, ytiter, vtiter}, 1]];
>       values
>       ];

Each call to titer changes the global variable "values". Is this what you
want?

IMHO it would be better to avoid all these assignments:
obviously, xtime,ytime and vtime are lists.
titer[lambda_, beta_, d_, k_, a_, u_] :=
     Module[{soln, x, y, v, t},
     {x /@ xtime, y /@ ytime, v /@ vtime}/.NDSolve[....][[1]]
];
returns a list with three elements (the lists corresponding to the
time-lists).
Omit the "[[1]]" at the end of NDSolve[], if you want a list with the list
of lists as only element.
But minfcn would lead to trouble, if you do so.

(The global variables {x|y|v}time should have values assigned before titer
is called)

> calcs = titer[10^7, 5*10^-10, 0.1, 500, 0.5, 5];
>
> minfcn[lambda_, beta_, d_, k_, a_, u_] :=
>
>   Module[{i, j},
>
>     diffsum =
>       Sum[10000*(uninfected[[i, 2]] - calcs[[1, i]])^2 +
>             10000*(infected[[i, 2]] - calcs[[2, i]])^2, {i,
>             Length[uninfected]}] +
>         Sum[(virus[[j, 2]] - calcs[[3, j]])^2, {j, Length[virus]}];
>     diffsum
>     ]
>

I do not know the datastructure of "(un)infected" and "virus". So I can't
say anything about these.
But the calcs[[1|2,i]] should return the expected values now.
If the problem stays, it could help to replace the last line of the
definition of minfcn by Expand[diffsum] or N[diffsum].

> minfcn[10^7, 5*10^-10, 0.1, 500, 0.5, 5]
>
> Here is the output:
>
> (2.518473817923033*10^24 +
>     10000*(-1.80000521715242*10^7 + 20000)^2 +
>     10000*(-1.8*10^7 + 20000)^2 +
>     10000*(-1.*10^7 + 980000)^2 +
>     10000*(-9.99926182857273*10^6 + 980000)^2)
>
> I need a single number to continue my calculations.
>
> ~Andrea
>


Peter Pein, Berlin
petsie at arcAND.de
replace && by || to write to me


  • Prev by Date: Re: poisson equation
  • Next by Date: How can I use the Input as a string, without checking by the kernel
  • Previous by thread: Re: Summation Problem w/ 5.0
  • Next by thread: Re: Summation Problem w/ 5.0