Message Boards Message Boards

0
|
11513 Views
|
6 Replies
|
3 Total Likes
View groups...
Share
Share this post:

How can I define this function

Posted 9 years ago

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

Thanks buddies!

POSTED BY: erivaldo nunes
6 Replies

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]
POSTED BY: S M Blinder
Posted 9 years ago

Thanks buddy!

POSTED BY: erivaldo nunes

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
POSTED BY: Kay Herbert
Posted 9 years ago

Thanks buddy!

POSTED BY: erivaldo nunes
Posted 9 years ago

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
POSTED BY: Eric Rimbey
Posted 9 years ago

thanks buddy!

POSTED BY: erivaldo nunes
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract