Re: Linear Interpolation problems

*To*: mathgroup at smc.vnet.net*Subject*: [mg102371] Re: Linear Interpolation problems*From*: Valeri Astanoff <astanoff at gmail.com>*Date*: Fri, 7 Aug 2009 05:29:35 -0400 (EDT)*References*: <h5ebm0$1u1$1@smc.vnet.net>

On 6 ao=FBt, 12:35, kosal lee <leeko... at yahoo.com> wrote: > Hello, > > I am new to Mathematica. Please help me with linear interpolation problems. Thank you for your help. > > First, suppose I have two real values > > year earnings > x = 3 f(x) = 20 > x= 10 f(x) = 50 > > I want to have the interpolated values of f(4), f(5), to f(9) which is between actual values of f(3) and f(10). How can I do that with Mathematica? > > Second, suppose I have an excel spreadsheet having those above values for multiples firms as of the following > > firm f(3) f(10) > A 20 50 > B 30 55 > C 60 25 > > I want to have the values of f(4) till f(9) as above and are stored in excel spreadsheet as of the following: > > firm f(3) f(4) f(5) ... (f9) f(10) > A 20 50 > B 30 55 > C 60 25 > > Best Regards, > Kosal Good day, Here is an example of what you could do : In[1]:= data = Import["data.xls"] // First Out[1]= {{"Firm", 3., 4., 5., 6., 7., 8., 9.}, {"a", 20., 0., 0., 0., 0., 0., 25.}, {"b", 30., 0., 0., 0., 0., 0., 55.}, {"c", 60., 0., 0., 0., 0., 0., 25.}} In[2]:= inter = Table[If[i == 1 || j == 1, data[[i, j]], InterpolatingPolynomial[{{data[[1, 2]], data[[i, 2]]}, {data[[1, -1]], data[[i, -1]]}}, data[[1, j]]]], {i, 1, Length[data]}, {j, 1, Length[data[[1]]]}] Out[2]= {{"Firm", 3., 4., 5., 6., 7., 8., 9.}, {"a", 20., 20.8333, 21.6667, 22.5, 23.3333, 24.1667, 25.}, {"b", 30., 34.1667, 38.3333, 42.5, 46.6667, 50.8333, 55.}, {"c", 60., 54.1667, 48.3333, 42.5, 36.6667, 30.8333, 25.}} In[3]:= Export["inter.xls", inter] Out[3]= "inter.xls" -- V.Astanoff