1

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}];
CR36
  • 127
  • 9
  • 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. – Steffen Jaeschke Mar 19 '20 at 17:01
  • 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. – CR36 Mar 19 '20 at 20:20
  • Perhaps a nice example with an explanation is [https://mathematica.stackexchange.com/questions/85750/memoization-with-pure-functions/85762#85762]. – Steffen Jaeschke Mar 24 '20 at 16:50
  • This question seems of bigger importance for Your forthcoming: [https://mathematica.stackexchange.com/questions/56504/v10s-operator-forms-what-are-they-good-for]: get the Function to the standard introduced in V10. – Steffen Jaeschke Mar 24 '20 at 17:39

1 Answers1

3

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.

axtimhaus
  • 56
  • 3