3
$\begingroup$

Please, feel free to edit the title, if necessary.

Hi, this is my code working, but actually, the size of my real dataset is 100x100. So, this is very inefficient way. What would be the most efficient way to make this work? Please, see an attached photo. What I'm trying to do are doubling my data by Interpolation or extrapolation function and generating x- and y-axis, automatically.

enter image description here

Here is my inefficient code.

mat = {{0, 1, 2, 3}, {1, 1, 2, 3}, {2, 2.83, 8, 17}, {3, 5.12, 18, 
    46.7}};
x1 = mat[[2 ;;, 2]];
x2 = mat[[2 ;;, 3]];
x3 = mat[[2 ;;, 4]];
TableForm@mat

intx1 = Interpolation[x1];
intx2 = Interpolation[x2];
intx3 = Interpolation[x3];
doublex1 = Flatten[Table[{intx1[x]}, {x, 6}], 1];
doublex2 = Flatten[Table[{intx2[y]}, {y, 6}], 1];
doublex3 = Flatten[Table[{intx3[z]}, {z, 6}], 1];
doublemat = Transpose[{doublex1, doublex2, doublex3}];
(*In my actual data set, the size of matrix is 100 x 100. So, this \
method won't be efficient at all*) 

xaxis = Flatten[Range[1, Flatten[Dimensions[x1], 1], 1], 1];
yaxis = Flatten[Range[0, 2*Flatten[Dimensions[x1], 1], 1], 1];
xdoublemat = Join[{xaxis}, doublemat];
yxdoublemat = Join[List /@ yaxis, xdoublemat, 2];
TableForm@yxdoublemat
$\endgroup$
  • $\begingroup$ Although the function you are using is named Interpolation, you are in fact fitting the three points in each column to a quadratic polynomial and then using that polynomial to extrapolate three more points. In a hundred point column, the default for Interpolation will fit the last four points to a cubic, from which another 100 points will be determined by extrapolation. Is this what you really want? If so, some version of Map will allow the code to be written compactly. Use Quiet to suppress the many warning messages. $\endgroup$ – bbgodfrey Mar 26 '16 at 4:34
  • $\begingroup$ My real dataset is 100*100 and I am trying to make it by 200*100 using Extrapolation. I also thought that there should be a compact way to write this code using Map, but I was not able to find it yet. If you can help, it would be very appreciable. Thank you. $\endgroup$ – SungwooY Mar 26 '16 at 12:07
4
$\begingroup$

The extrapolated solution described in the question can be computed using the following compact code.

n = Length[mat] - 1;
Quiet@Map[Join[#, Interpolation[#[[2 ;;]]][Range[n+1, 2n]]] &, mat//Transpose]//Transpose

(* {{0, 1, 2, 3}, {1, 1, 2, 3}, {2, 2.83, 8, 17}, {3, 5.12, 18, 46.7}, 
    {4, 7.87, 32, 92.1}, {5, 11.08, 50, 153.2}, {6, 14.75, 72, 230.}} *)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.