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.
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.
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]
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.
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?
Set (=)
andSetDelayed (:=)
are explained on their documentation pages and compared atImmediate and Delayed Definitions
$\endgroup$