0
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ == 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]. $\endgroup$ – Michael E2 Jun 22 '16 at 19:15
  • 1
    $\begingroup$ Should Interpolate be Interpolation? $\endgroup$ – mikado Jun 22 '16 at 19:27
0
$\begingroup$

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}}
B = {{1, 3}, {3, 4}, {4, 2}, {5, 0}}
Af = Interpolation[A]
Bf = Interpolation[B]
c[x_] := Af[x] + x Bf[x]
Plot[c[x], {x, 1, 5}]
$\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.