开发者

How do I add values of one Table to another in Mathematica?

I have created a Table of values known as "value1". The "value1" is nothing but a z co-ordinate values alternatively can be called "zone" . These values depending upon the x co-ordinate and y co-ordinate given as "x" and "y" respectively.

The code is give below

value1 = Table[{(10*(Cos[((x - 75)*2*3.14159)/
      200]^2)*(Cos[((y - 75)*2*3.14159)/200]^2)) + 
20}, {y, 0, 20, 5}, {x, 0, 20, 5}]

The output of "value1" or "zone" is

{{22.5}, {21.7274}, {21.0305}, {20.4775}, {20.1224}}, {{21.7274}, and so on

I have another table of values known as "value 2". This table also gives me a different z co-ordinate value it can be alternatively called "ztwo" . This values also depends upon the x and y co-ordinates defined by "x" and "y" respectively.

Note the z value is generated defined by the expression given below

(((70 - ((10*(Cos[((x - 75)*2*3.14159)/
             200]^2)*(Cos[((y - 75)*2*3.14159)/200]^2)) + 
       20))*0.3333))

I have used the above expression in the table below to generate the "ztwo" values

value2 = Table[{x,y, (((70 - ((10*(Cos[((x - 75)*2*3.14159)/
             200]^2)*(Cos[((y - 75)*2*3.14159)/200]^2)) + 
       20))*0.3333))}, {y, 0, 20, 5}, {x, 0, 20, 5}]

Output of "value2"

{{{0, 0, 15.8318}, {5, 0, 16.0892}, {10, 0, 16.3215}, {15, 0, 16.5059}, {20, 0, 16.6242}}, {{0, 5, 16.089开发者_JS百科2}, {5, 5,16.2672}, {10, 5, 16.4277}, {15, 5, 16.555},and so on

As you can see from above the "value2" is in form of

{x1,y1,ztwo1},{x2,y2,ztwo2},{x3,y3,ztwo3}..and so on

I want to create a table of values know as "value3" which is basically the addition z values from "value 1" known to us as "zone" to ONLY the z values of "value2" known to us as "ztwo" to get the table "value3". In table "value3" only the z values change but it SHOULD be expressed as in form below

{0,0,38.3317},{5,0,37.5592},{10,0,36.8623} and so on

Explanation: How do I get the above??
this is the "zone" values:
{{22.5}, {21.7274}, {21.0305}, {20.4775}, {20.1224}}, {{21.7274}, and so on

Below is "ztwo" values but expressed in{x,y,z} format

{{{0, 0, 15.8318}, {5, 0, 16.0892}, {10, 0, 16.3215}, {15, 0, 16.5059},    
{20,0,16.6242}}, {{0, 5, 16.0892} and so on

Now I want a table of "value 3" whose z values change since it is the addition of     
corresponding z co-ordinate values from table "value1" and table "value2"

 {0,0,15.8318+22.5},{5,0,16.0892+21.7274},{10,0,16.3215+36.8623} and so on

Which will lead to the desired, ideal output like this:

{0,0,38.3317},{5,0,37.5592},{10,0,36.8623} and so on

Question How Do I create the Table "Value3" which give me the desired output by adding the corresponding z values from table "value1" to table "value2"


You have a small typo in your code... there should be a comma between y and (((70 - ... in the definition of value2 in order to get the result that you posted below.

Fixing that, you can do the following to get your result:

value3 = value2;
value3[[All, All, 3]] += value1[[All, All, 1]];

EDIT:

The code above does the addition the way you want it. I think the confusion is because you want each of the three coordinates as a list instead of a matrix. For that, you simply need to Flatten the list at Level 1.

Flatten[value3, 1]
Out[1]= {{0, 0, 38.3317}, {5, 0, 37.8167}, {10, 0, 37.3521}, {15, 0, 
  36.9833}, {20, 0, 36.7466}, {0, 5, 37.8167}, {5, 5, 37.4608}, {10, 
  5, 37.1397}, {15, 5, 36.885}, {20, 5, 36.7214}, {0, 10, 
  37.3521}, {5, 10, 37.1397}, {10, 10, 36.9482}, {15, 10, 
  36.7962}, {20, 10, 36.6986}, {0, 15, 36.9833}, {5, 15, 36.885}, {10,
   15, 36.7962}, {15, 15, 36.7258}, {20, 15, 36.6806}, {0, 20, 
  36.7466}, {5, 20, 36.7214}, {10, 20, 36.6986}, {15, 20, 
  36.6806}, {20, 20, 36.669}}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜