Re: About function to evaluation
- To: mathgroup at smc.vnet.net
- Subject: [mg74519] Re: About function to evaluation
- From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
- Date: Fri, 23 Mar 2007 19:18:40 -0500 (EST)
- Organization: The Open University, Milton Keynes, UK
- References: <ett7mp$ifv$1@smc.vnet.net>
Evanescence wrote:
> Hello Dear all:
> My questions are as follows:
> First I definite a function is f[x_,y_]:=2x+3y
> Then I have a list is data={{1,2,0},{2,3,0},{4,1,0},{6,3,0},{1,3,0}}
> For example{y,x,z}={1,2,0} {y,x,z}={2,3,0} {y,x,z}={4,1,0}
> {y,x,z}={6,3,0} {y,x,z}={1,3,0}
> I want to take the list data to the function to get the function
> values.
> Then express the form as follows at last
>
> x y f[x,y]
> 2 1 7
> 3 2 12
> 1 4 14
> 3 6 24
> 3 1 9
>
> PS: The z values is zero overall.
> Please tell me how to get the function values in the list
> Thank you very much
> Evanescence 2007 03 21
>
>
One way of doing what you want is the following:
In[1]:=
f[{x_Integer, y_Integer, _}] := 2*x + 3*y;
data = {{1, 2, 0}, {2, 3, 0}, {4, 1, 0}, {6, 3, 0}, {1, 3, 0}};
data[[All,3]] = f /@ data[[All,{2, 1, 3}]];
TableForm[data[[All,{2, 1, 3}]],
TableHeadings -> {None, {"x", "y", "f[z,y]"}},
TableAlignments -> Right]
Out[5]//TableForm=
x y f[z,y]
2 1 7
3 2 12
1 4 14
3 6 24
3 1 9
Regards,
Jean-Marc