       Re: display of function

• To: mathgroup at smc.vnet.net
• Subject: [mg58516] Re: display of function
• From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
• Date: Tue, 5 Jul 2005 04:52:24 -0400 (EDT)
• Organization: The Open University, Milton Keynes, England
• Sender: owner-wri-mathgroup at wolfram.com

```Bosch, Darrell wrote:
> Dear Math Group:
>
>             The first equation below shows a function for u(y) which is
> the sum of the products of pi times yi.  In the following steps, I
> assign values of p and y.   How can I get Mathematica to display the
> numerical value of u for the given p and y values?  When I insert the
> u[y] command, I just get a repeat of the equation I have entered.
> Thanks for your suggestions.  This group is a great help.  Darrell
>
>
>
> u[y_] := Sum[Subscript[p, i]*Subscript[y, i],
>
>    {i, 1, n}]
>
>
>
> p = {.3,.4,.3}
>
>
>
> y={10000, 20000, 30000}
>
>
Hi Darrell,

Assuming that I have correctly understood what you tried to do, you
could use either one of the following approaches:

In:=
p = {0.3, 0.4, 0.3}
y = {10000, 20000, 30000}

Out=
{0.3, 0.4, 0.3}

Out=
{10000, 20000, 30000}

We take the product of the corresponding elements in each list

In:=
p*y

Out=
{3000., 8000., 9000.}

Finally, we take the sum of these products

In:=
Plus @@ %

Out=
20000.

This series of operations is indeed the dot product of p and y
In:=
p . y

Out=
20000.

If you need to use some other functions in place of *Plus* and *Times*,
have a look at the *Inner* product.

Best regards,
/J.M.

```

• Prev by Date: Re: Function to handle array with variable _number_ of dimensions?
• Next by Date: Re: How to simulate random samples from crooked coin toss?
• Previous by thread: Re: display of function
• Next by thread: Re: display of function