How can I define this function

Rijy=RijCos theta if i<j and -RijCos theta if i>j

Thanks buddies!

Erivaldo, look at the documentation for Condition (usually written “/;”). Not sure what your experience with Mathematica is, so I’ll also mention that functions are typically defined using SetDelayed (“:=”).

A conditional function definition might look like this:

In[1]:= func[i_, j_] := 2 i + j /; i < j

In[2]:= func[i_, j_] := i + 3 j

In[3]:= func[1, 2]

Out[3]= 4

In[4]:= func[2, 1]

Out[4]= 5

thanks buddy!

I like to do it this way:

In[1]:= func[i_, j_] := If[i < j, 2 i + j, i + 3 j]

In[2]:= func[1, 2]

Out[2]= 4

In[3]:= func[2, 1]

Out[3]= 5

More directly, something like

In[9]:= f[i_, j_, \[Theta]_] := R[i, j] Cos[\[Theta]] Sign[j - i]

In[10]:= f[1, 2, \[Theta]]

Out[10]= Cos[\[Theta]] R[1, 2]

In[11]:= f[2, 1, \[Theta]]

Out[11]= -Cos[\[Theta]] R[2, 1]

Thanks buddy!

Thanks buddy!