Hello all,(adsbygoogle = window.adsbygoogle || []).push({});

It's quite a mouthful but I need help writing a function that will behave as follows:

1.if called with an argument which is an integer, it will return the absolute value of the input

2. if called with a real argument, it will return the number rounded to the nearest integer if the argument is positive, zero if the argument is negative.

3. if called with a complex argument, it will round the real part and the imaginary part to the nearest integer and return the modulus of the result.

I starting with something like this.

rr = {a_integer -> Abs[a], a_real -> If[a_real < 0, 0, Integer[a]],

a_complex ->

Then I found the 'which' function

ff[a_] = Which[integer[a], Abs[a], a_Real,

If[a_real < 0, 0, Integer[a]],

a_Complex, {Real[a] & Im[a] -> Mod[integer[a]] }]

However I don't think I'm inputting things correctly.

Any tips would be appreciated

Thanks

**Physics Forums - The Fusion of Science and Community**

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Mathematica function writing

Loading...

Similar Threads - Mathematica function writing | Date |
---|---|

Mathematica Cannot do the integral of the Hyper-geometric function? | Mar 11, 2018 |

Mathematica Cannot Plot This Function in Mathematica | Feb 26, 2018 |

Mathematica How to append functions to a list of functions? | Oct 8, 2017 |

Help! Need to write a Mathematica function | Mar 26, 2011 |

Can someone please explain how to write functions in Wolfram Mathematica ? | Jan 6, 2010 |

**Physics Forums - The Fusion of Science and Community**