Re: question

• To: mathgroup at smc.vnet.net
• Subject: [mg15660] Re: question
• From: "Allan Hayes" <hay at haystack.demon.co.uk>
• Date: Sat, 30 Jan 1999 04:28:53 -0500 (EST)
• References: <78pa6k\$cn1@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```Alice M. Dean wrote in message <78pa6k\$cn1 at smc.vnet.net>...
>Hi, I was given this address by a colleague, who said you could quickly
>answer what I think is a very simple question.  After I evaluate the
>following in mathematica,
>
>DSolve[{P'[t]==0.031P[t], P[0]==5.3}, P[t],t]
>
>I get a result which is essentially: {{P[t] -> 5.3 E ^(0.031t)}}
>
>inside two sets of curly brackets.
>
>I would now like to compute P[10], P[100], etc.  Is there a reasonable
>way to do this?  Thanks, Alice Dean
>
>~~~~~~~~~~~~~~~~~~~~~~~~~
>Alice Dean
>Mathematics & Computer Science Department Skidmore College
>Saratoga Springs, NY 12866
>
>Phone: (518) 580-5286
>Fax: (518) 580-5936
>Skidmore College Information: (518) 580-5000   E-mail:
>~~~~~~~~~~~~~~~~~~~~~~~~~
>

Alice:

I'll begin with how it can be done; then offer some explanation.

HOW

First extract the formula  5.3 E ^(0.031t

fmla= P[t] /.{{P[t] -> 5.3 E ^(0.031t)}}[[1]]

5.3E^(0.031*t)

You could use this directly to get the values

fmla/.{{t->10},{t->100}}

{7.22615,117.649}

But it is usually better to define a function using the formula

P[t_] = fmla; (* the semicolon stops output being displayed when this is
not wanted*)

Now we have

{P[10],P[100]}

{7.22615,117.649}

Which can be done more conveniently  by mapping the function P over the
list {10,100,1000}

P/@{10,100}

{7.22615,117.649}

The FullForm of P/@{10,100,1000} is Map[P, {10,100,1000}] (*please look
up Map*)

WHY

Why a list of lists?
Because, in general, equations can have several solutions for several
variables.

For simplicity, I'll use an ordinary algebraic problem.

sol=Solve[{y ^2== x^2, y==t},{x,y}]

{{x -> -t, y -> t}, {x -> t, y -> t}}

Why rules instead of  simply {{-t, -t},{t,t}}?                (**)

Because (1)  the rules make clear which formula goes with which
variable; and (2) they allow subsititutions of the solutions in any
formula:

A[x,y]/.sol

{A[-t,t],A[t,t]}

We can get the separate solutions

sol1=sol[[1]]

{x -> -t, y -> t}

sol2=sol[[2]]

{x -> t, y -> t}

And make functions corresponding to them

{x1[t_],y1[t_]}={x,y}/.sol1;

Then

{x1[3],y1[3]}

{-3,3}

Allan

---------------------
Allan Hayes
Mathematica Training and Consulting
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565

```

• Prev by Date: Re: How to construct all possible orderings
• Next by Date: Re: How to construct all possible orderings
• Previous by thread: Re: question
• Next by thread: RE: Re: question