Skip to content

Instantly share code, notes, and snippets.

@adeekshith
Created May 2, 2015 03:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adeekshith/5408686eb9b37e2b9817 to your computer and use it in GitHub Desktop.
Save adeekshith/5408686eb9b37e2b9817 to your computer and use it in GitHub Desktop.
Example for function overloading in Mathematica
(* Function overloading in Mathematica *)
SumMultiply[x_?NumericQ, y_Real] :=
Module[
{sum, mul},
sum = x + y;
mul = x y;
{sum, mul}
]
SumMultiply[x_Integer, y_Real] :=
Module[
{sum, mul},
sum = x + y;
mul = x y/(x + y);
{sum, mul}
]
SumMultiply[x_Integer, y_Integer] :=
Module[
{sum, mul},
sum = x + y;
mul = x y/(x + y);
{sum, mul}
]
SumMultiply[10, 4.5]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment