Say I define an equation line[t_] = {t, 2t, 3t}. What code will define x[t] = t, y[t] = 2t, and z[t] = 3t, but without hardcoding?

  • $\begingroup$ Evaluate[Through[{x, y, z}[t_]]] = line[t] $\endgroup$
    – Bob Hanlon
    Sep 22 at 4:28

but without hardcoding?

First of all, line[t_] = {t, 2t, 3t} is not an equation. Equation should have == in it. This is function definition. Second, better to use delayed := instead of immediate = when making functions, unless there is a good reason to use immediate definition.

I do not know why you do not want to do normal explicit definitions for x[t_] and y[t_] and [z_] it would be more clear when looking at the code that way.

But this does what you want. I am sure there are other ways to do it.

ClearAll[x, y, z, t];
line[t_] := {t, 2 t, 3 t}
MapThread[(#1[t_] := #2) &, {{x, y, z}, line[t]}];

And now you have these functions defined.

Mathematica graphics


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