Created
May 2, 2015 03:29
-
-
Save adeekshith/5408686eb9b37e2b9817 to your computer and use it in GitHub Desktop.
Example for function overloading in Mathematica
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* 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