# Defining a function using an InterpolatedFunction from a data set

suppose I have two data sets A and B, which are tables/lists/arrays/whatever Mathematica calls it, from an imported CSV. there'd be lines that look like this:

A = Import["file.csv"];


(the CSV file is two columns, x and y. the range of x in file A is not the same as in B, but they coincide at a given interval)

and then I get the interpolation function of A and B, let's call them Af and Bf. I add lines like these:

Af = Interpolation[A];


above is edited: wrong function (/edit)

But now I want a new function, C, defined as C = A+Bx. I write it like this:

C[x_] == Af[x] + Bf[x]*x


edit: I'm not really using A, B, and C, these are just placeholder names because the names I used are pretty long. I changed the stuff above to:

C[x_] := Af[x] + Bf[x]*x


and I get

"Tag Plus in (<<1>>)[x_] is Protected"


(/edit. tho plotting/evaluating it still gets me nothing)

I plot it and get nothing. I try to evaluate it and get

InterpolatingFunction[{{0.1879, 1.937}}, <>] +
x InterpolatingFunction[{{0.1879, 1.937}}, <>])[0.2]


I looked online, and the only example I found used /., for an NDSolve problem, which didn't seem to work for my case. what am I doing wrong?

edit: it appears that restarting the program got rid of the "protected" error. the code works now.

• == is for testing equality. Use c[x_] := Af[x] + Bf[x]*x. Note capital C is a reserved symbol, used by Mathematica. -- Also, assuming the == is a typo (I don't see how you got anything), your output suggests you defined C by Af + Bf*x and omitted the [x]. – Michael E2 Jun 22 '16 at 19:15
• Should Interpolate be Interpolation? – mikado Jun 22 '16 at 19:27

Here is some code that does what I think you are trying to do. It is best to avoid C as a variable name because it has predefined behaviour
A = {{1, 2}, {2, 5}, {3, 8}, {5, 16}}