1
$\begingroup$

i have a vector function as:

$f:\mathbb{R}\longrightarrow \mathbb{R}^{n}$

for example:

SomeComplicatedInterpolationFunction=Interpolation[Table[{i, i^2}, {i, 1, 5}]];
f[x]:={Cos[x],Sin[x],Tan[x],Cot[x],SomeComplicatedInterpolationFunction[x]};

Now I would like to save the function f as a file so i can recall this later in a new mathematica cernel. I tried:

f>>"f.m";

but it didnt work, this gives just the symbolic expression of f. Then I tried:

f2=FunctionInterpolation[f[x],{x,0,1}];
f2>> "f2.m";

But this only stores the first entry of f.

Whats the correct way to store a vector valued function without storing each component?

$\endgroup$
3
$\begingroup$

Use Save:

f[x] := {Cos[x],Sin[x],Tan[x],Cot[x],SomeComplicatedInterpolationFunction[x]};
Save["f.m", f]

Let's check if it worked:

Clear[f];
<<f`

??f

Global`f

f[x]:={Cos[x],Sin[x],Tan[x],Cot[x],SomeComplicatedInterpolationFunction[x]}

$\endgroup$
  • $\begingroup$ wow that was easy, thank you! $\endgroup$ – Mr Puh Nov 9 '17 at 21:27
0
$\begingroup$
f[x_]:={Cos[x],Sin[x],Tan[x],Cot[x],SomeComplicatedInterpolationFunction[x]};

Save[f.m,f]
$\endgroup$
  • $\begingroup$ sorry if i my question was ambiguous. I want to store the function as a file on the hard disk of my computer not in the actual cernel. I want to recall the function in a new cernel with: f=<<"f.m". For a scalar valued function this works fine but the question is how to proceed with a vector valued function $\endgroup$ – Mr Puh Nov 9 '17 at 20:07

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.