1
$\begingroup$

I am new to Mathematica and am doing work involving interpolating functions from NDSolve. I would like to use the interpolating functions from NDSolvein calculations but I can't seem to figure out the proper way to do this. So say I have the following interpolating function:

myInt = Interpolation[{{0, 0}, {1, 3}, {4, 2}, {7, 9}}]

InterpolatingFunction[{{0, 7}}, <>]

I would then like to take this interpolating function and use it like a variable or function and perform math operations on it like:

modMyInt = myInt*3 + 1

1 + 3 InterpolatingFunction[{{0, 7}}, <>]

But when I plot modMyInt I get an empty plot.

Plot[modMyInt[t], {t, 0, 9}]

I think I am misunderstanding what interpolating functions are; can someone please explain how to do this?

$\endgroup$
  • 1
    $\begingroup$ Try modMyInt = myInt[t]*3 + 1; Plot[modMyInt, {t, 0, 9}]. You can't do arithmetic operations with interpolation functions, but you can include them in expressions. Interpolation functions are black boxes; things like addition and multiplication are not defined for them. $\endgroup$ – C. E. Apr 5 '17 at 23:27
1
$\begingroup$

This is really just an issue with how to define functions in Mathematica. Most intuitive is with rules (though there are other ways):

modMyInt[t_] = myInt[t]*3 + 1
$\endgroup$
1
$\begingroup$

Are you looking for something like this?

eqn1 = x''[t] == Sin[t]*y[t] + t;
eqn2 = y''[t] == Sin[t]*x[t] + t;

sol = NDSolve[{eqn1, eqn2, x[0] == 0, x'[0] == -0.2, y[0] == 0, y'[0] == 1}, {x[t], y[t]}, 
              {t, 0, 10}];

{xsol, ysol} = sol[[1, All, 2]];

modMyInt = 3*xsol + 1;

Plot[modMyInt, {t, 0, 10}, PlotRange -> All]
$\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.