Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Sorry if this is a duplicate, but I have a variable called H. H is some complicated function of s.

Now I want to make this variable H into a formal function f[s]. I've tried just doing

f[s_] := H

But that doesn't seem to work.

H was initially a value in a InputField and the type on that InputField was an Expression.

Any ideas on how I can turn this into a proper Mathematica function?

share|improve this question
h = 3*s - 1; f[s_] := Evaluate@h; then f[3] – Nasser Mar 12 '14 at 23:34

Couple of ways, e.g.:

ClearAll[h, f]

h = 2 s + 3 s^2 + Sin[s];
f[sarg_] := h /. (s -> sarg)

(* just define directly *)
ClearAll[h, f]
f[s_] := 2 s + 3 s^2 + Sin[s]

16 + Sin[2]
16 + Sin[2]
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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