# Handling of "Array" or Table for numerical computations with Interpolation

Posted 1 month ago
352 Views
|
7 Replies
|
2 Total Likes
|
 If one has two arrays of equal length, say{x1,x2,.......xn} and {y1,y2,...yn}, how can one combine these into a third array of equal length{{x1,y1},{x2,y2},....{xn,yn}}? This latter is actually an n x 2 matrix. I need this for a purpose which actually may have a more elegant solution than using the above. I need to solve numerically an integral equation with what is called "collision number expansion" (Neumann series expansion), i. e. repeated integration. Using Nintegrate and nested integrals is hopeless already for the first loop, it would require a supercomputer to come up to the second or third iteration.So instead I am calculating my (smoothly behaving) starting function in a number of points (say given xn coordinates), which will become the values yn. Then I use Interpolation because in the next iteration (integration) I need the value my function at points other than xn, this comes from the nature of the problem. But if I use Interpolation only on the yn, then the independent variable will not be my xn, only the natural numbers 1.2...n. Then of course I cannot perform the integration, since I lose contact with my individual dxi values. This is what I thought to solve with the above trick, since if I use Interpolation on the point pairs, then my interpolated functions will have the correct x co-ordinates. Any advice? Thanks!
Answer
7 Replies
Sort By:
Posted 1 month ago
 Does that help? ... I would do it that way, but I think there must be another way to make it easier... x = {1, 2, 3, 4}; y = {3, 5, 7, 9}; z = Table[{FromDigits[Take[x, {n}]], FromDigits[Take[y, {n}]]}, {n, 1, Count[x, _]}] .. or another case.. x2 = {{1, 2}, {2, 4}, {3, 8}, {4, 16}}; y2 = {{3, 6}, {5, 10}, {7, 14}, {9, 18}}; z2 = Table[{FromDigits[Take[FromDigits[Take[x2, {m}]], {1}]], FromDigits[Take[FromDigits[Take[y2, {m}]], {1}]]}, {m, 1, Count[x2, _]}] 
Answer
Posted 1 month ago
 Yes it definitely does the job, thank you! In the meantime I came to yet another one: x = {1, 2, 3, 4}; y = {11, 12, 13, 14}; z = Table[1, 4]; Do[z[[i]] = {x[[i]], y[[i]]}, {i, 4}]; z {{1, 11}, {2, 12}, {3, 13}, {4, 14}}Let us see if there will be more comments. Intuitively I feel that the problem with Interpolation should have a more streamlined solution, but these are sufficient for me to go ahead with the integrals. Thanks again!
Answer
Posted 1 month ago
 Note that in the table to not have to manually put the number of terms ( "4 "), you can put Count [x, _] so that it is something automatic.
Answer
Posted 1 month ago
 That is also useful, thanks!Now I think I came to the simple solution I was looking for, to make the array that I need: x = {1, 2, 3, 4}; y = {11, 12, 13, 14}; z = Transpose[{x, y}] {{1, 11}, {2, 12}, {3, 13}, {4, 14}}I still believe there is a more elegant solution for the Interpolation problem, but for the array building this is good enough.
Answer
Posted 1 month ago
 In[61]:= x = {1, 2, 3, 4}; y = {11, 12, 13, 14}; z = Thread[{x, y}] Out[62]= {{1, 11}, {2, 12}, {3, 13}, {4, 14}} 
Answer
Posted 1 month ago
 This is even shorter, thanks!
Answer
Posted 1 month ago
 My idea would be:x = Range[1 , 5] ; y = Range[6 , 10] ; combxy = Table[ { x[[ i ]] , y[[ i ]] } , { i , 1 , Length[x] } ] ;
Answer
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments