1
$\begingroup$

I would like to construct a list of Functions that can be used like: F[z][[i]]

Where one can choose between list elements with i and that the function evaluates at the point z. So that one can have either a List of Functions when z is declared or a List of Values when z has a particular value.

I tried to do it like:

n = 10;
t[z_] := 0.58 ( 1 - 0.02624 Power[ Abs[z]/500, 2.2306]);
c[z_] := t[z] - t[0];
R1[z_] := 125 + t[z] + c[z];
RList = {Function[z, R1[z]]};
Do[AppendTo[RList, RList[[i]] + Function[z, t[z] + c[z]] ], {i,n-1}];
$\endgroup$
4
  • $\begingroup$ Your problems are manifold. This is not a list. It is a sum. AppendTo works that way. But You misuse Function. The example from the Mathematica documentation for Function is f = (3 + #) & and {f[a], f[b]} with the result {3 + a, 3 + b}. Pure functions are the path to success for such kind of operation. Best luck. $\endgroup$ Commented Mar 19, 2020 at 17:01
  • $\begingroup$ Thanks for your answer. Can you maybe give a small example for a solution? I've read through the Pure Function Tutorial but I don't quiet get how it fits to my problem. $\endgroup$
    – CR36
    Commented Mar 19, 2020 at 20:20
  • $\begingroup$ Perhaps a nice example with an explanation is [mathematica.stackexchange.com/questions/85750/…. $\endgroup$ Commented Mar 24, 2020 at 16:50
  • $\begingroup$ This question seems of bigger importance for Your forthcoming: [mathematica.stackexchange.com/questions/56504/…: get the Function to the standard introduced in V10. $\endgroup$ Commented Mar 24, 2020 at 17:39

1 Answer 1

3
$\begingroup$

The general case: I can mention some patterns with different interfaces. Just a small example. f1 is just a list of functions. f2 is a vector valued function. f3 is like f2, but encapsulates the indexing as function parameter.

f1 = Table[With[{nn = n}, Function[x, x^nn]], {n, 1, 5}]
f1[[2]][x]

f2 = Function[{x}, Table[x^n, {n, 1, 5}] // Evaluate]
f2[x][[2]]

f3 = Function[{i, x}, Indexed[Table[x^n, {n, 1, 5}], i] // Evaluate]
f3[2, x]

For your special purpose:

n = 10;
t[z_] := 0.58 (1 - 0.02624 Power[Abs[z]/500, 2.2306]);
c[z_] := t[z] - t[0];
R1[z_] := 125 + t[z] + c[z];
RList = {Function[z, R1[z] // Evaluate]};
Do[AppendTo[RList, Function[z, RList[[i]][z] + t[z] + c[z] // Evaluate]], {i, n - 1}];

You need to use Function outermost of your list element and insert z everywhere it must be inserted, so resolving all inner Function objects.

It's a quick and dirty way. Maybe it can be done more efficently with NestList or something similar.

$\endgroup$
1
  • $\begingroup$ Exactly what I meant. Thank you! $\endgroup$
    – CR36
    Commented Mar 23, 2020 at 15:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.