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
- References: <dad7oo$t91$1@smc.vnet.net>
- 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[1]:= p = {0.3, 0.4, 0.3} y = {10000, 20000, 30000} Out[1]= {0.3, 0.4, 0.3} Out[2]= {10000, 20000, 30000} We take the product of the corresponding elements in each list In[3]:= p*y Out[3]= {3000., 8000., 9000.} Finally, we take the sum of these products In[4]:= Plus @@ % Out[4]= 20000. This series of operations is indeed the dot product of p and y In[5]:= p . y Out[5]= 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.