1

I need to define some functions with more than one variable, but the examples only list one variable cases, so I tried this:

f[x_, y_] = (y/x) + xy

f[1, 2]

Sadly, my output is (y/x)+xy, which is not what I'm looking for. Someone knows what should I do?

SOLVED: had to use Exit[]

Souler
  • 11
  • 1
  • 1
  • 3
  • 2
    use := instead of = and read about Set and SetDelayed – eldo Oct 18 '15 at 17:53
  • 3
    Note that if you do not include a space between x and y in xy, the latter will be considered as an independent variable of name xy. This being said, defining f[x_, y_] = (y/x) + x y and asking for f[1, 2] works fine for me and returns 4. Perhaps, exiting your session with Exit[] and evaluating your inputs again may solve your issue. In the general situation, it is however better to use := instead of = as mentionned by @eldo. –  Oct 18 '15 at 17:56
  • 1
    Looks like using Exit[] solved the issue, thanks a lot c: – Souler Oct 18 '15 at 18:07

1 Answers1

1

As mentioned in the comments read about:

Understand the difference between Set (or =) and SetDelayed (or :=)

Set and SetDelayed

Clear[f, x, y]
f[x_, y_] := (y/x) + x*y
f[1, 2]

4

And have a look at

How to | Create Definitions for Variables and Functions