2
$\begingroup$

Assume that I define:

Computef[maxK_,Q_,R_]:= Module[{f},
...(some other equations)...
f[k] = Table[
     Function[{x}, 
      Evaluate[Subscript[fvar, k, i][x] /. sol[[1]]]], {i, 1, n}];
Return[Table[f[k], {k, 0, maxK}]];

so Computef is a rule that stores all these n-column functions f. Now I want to define a function of k,Q,R,x such that it gives me the k-th function that has been stored in Computef.

This can be easily done if I do not want x. So:

y[k_, Q_, R_] := Module[{fList}, fList = Computef[maxK, Q, R]; 
  fList[[k + 1]]]

And then I can look, for example, at:

y[1,Q0,R0] 

which gives: enter image description here

which are the four-components of the 1st function stored in Computef (I chose n=4).

Now assume I want to define this as function of x so that I can plot it etc. Something like:

u[k_,Q_,R_,x_]:= y[k,Q,R][x]

but I do not know how do this.

$\endgroup$
5
  • $\begingroup$ You can try something like this u[k_,Q_,R_,X_]:= y[k,Q,R]/.x->X $\endgroup$ Commented Nov 18 at 11:10
  • $\begingroup$ I tried it but does not work $\endgroup$ Commented Nov 18 at 19:34
  • $\begingroup$ Maybe your toy example is not the same as your real code. So, we need a minimal working example, and not what you show. $\endgroup$ Commented Nov 18 at 20:54
  • 2
    $\begingroup$ If you're using version >= 14, you could use Comap: u[k_, Q_, R_, x_] := Comap[y[k, Q, R], x]. Caveat... I'm not 100% sure I understand what you're trying to do since you haven't provided executable code. $\endgroup$ Commented Nov 18 at 20:57
  • $\begingroup$ As pointed out by the comment here, please show us a self-contained (minimal) working example, otherwise it'll be hard to help. The question will be reopened once it meets the standard of the site. $\endgroup$ Commented Nov 27 at 10:10

1 Answer 1

2
$\begingroup$

For a list of pure functions you could try Through:

Simple example

xi = Subdivide[0, 1, 10]; // N
funlist =Table[Interpolation[Transpose[{xi, RandomReal[{0, 1},Length[xi]]}]], {4}]

enter image description here

Plot[Evaluate@Through[funlist[x]], {x, 0, 1}] 

enter image description here

Hope it helps!

$\endgroup$
2
  • $\begingroup$ Thank you! But the problem is that my function also depends on k,Q,R, so when I try something like Evaluate@Through[y[k, Q, R][x]] it does not work. How would ago about defining u[k,Q,R,x]? $\endgroup$ Commented Nov 18 at 17:22
  • $\begingroup$ @MTYS Please provide runnable code $\endgroup$ Commented Nov 19 at 13:01

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.