Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

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

I want to define function in Mathematica on different way. Actually, if I already have functions a and b. How can I print the value in some point of function f but without defining functions a and b like f. I dont want to use this before a[x_]:=..., b[x_]:=... because a and b I obtained different and I can not change everything above in my code because of this.

  a = x;
  b = 2*x;

  f[x_] := a + b; 
share|improve this question
The output from this is 3 x. Isn't this what you want? It is not at all clear what you are asking. – Verbeia Jan 16 '12 at 14:14
I want value of function in point 2, I need f[2], but I got the function – Pipe Jan 16 '12 at 15:00
up vote 0 down vote accepted

Use Set instead of SetDelayed, like this:

a = x
b = 2*x

f[x_] = a + b

Be sure to read the documentation on this to understand the implications of using one or the other.

share|improve this answer
@Szabolics Thanks, I will. I must put stronger question because of negative points. – Pipe Jan 16 '12 at 15:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .