How to define function different in Mathematica

-2

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; 
  f[2]

Pipe

Posted 2012-01-16T13:29:21.200

Reputation: 133

The output from this is 3 x. Isn't this what you want? It is not at all clear what you are asking. – Verbeia – 2012-01-16T14:14:28.177

I want value of function in point 2, I need f[2], but I got the function – Pipe – 2012-01-16T15:00:39.757

Answers

0

Use Set instead of SetDelayed, like this:

a = x
b = 2*x

f[x_] = a + b
f[2]

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

Szabolcs

Posted 2012-01-16T13:29:21.200

Reputation: 2 248

@Szabolics Thanks, I will. I must put stronger question because of negative points. – Pipe – 2012-01-16T15:50:28.880