12
$\begingroup$

I wanted to know the difference between two operators:

= and :=

I couldn't find the ":=" operator on the list at https://reference.wolfram.com/language/tutorial/Operators.html

Can someone help?

Thanks.

$\endgroup$
2

1 Answer 1

7
$\begingroup$

You need to understand the difference of "Set" and "Set Delay" :

Let's make an example which illustrates this clearly. I have a function:

f[x1_,x2_]:= x1+x1*x2

and I want to find it's derivative according to x2 at specific locations of x1 and x2.

m[x1_,x2_] = D[f[x1,x2],x2]
  1. If you use use ":" before the "=", (Set Delay), it evaluates the function when it is needed, hence it will evaluate the function only when values for x1 and x2 are given.

  2. The function definition without ":" before the "=" (Set) evaluates the function before it is used and the output is assigned to m[x1_,x2_], so if you input values in m[x1_,x2_] they are put into the already-differentiated equation.

If now, you would decide to put a ":" in front of the "=" for m[x1_,m2_],it will not work, since one cannot differentiate a function with respect to a numerical value (5 for example).

I hope that this helps you.

P.S. I encountered the same question once: How To First Evaluate A Differential Equation And Then To Input The Function Parameters?

$\endgroup$
2
  • $\begingroup$ Thank you very much for the quick response! $\endgroup$
    – André
    Commented Oct 30, 2016 at 15:57
  • $\begingroup$ Your welcome ! Glad I could help. :) $\endgroup$
    – henry
    Commented Oct 30, 2016 at 17:02

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