# Define a function with the condition that it must be positive

I have a function f(x) and I want to define a new function g(x) that is equal to f(x) only when f(x) is positive.

What is the right way to do that?

Sorry for this silly question, but I cannot find the proper way to accomplish this simple task in Mathematica.

-
Maybe g[x_]:=Max[f[x],0] ? (Provided I correctly remember the syntax of Max). But what should be the value of your new function when f is not positive? Is the zero value important? –  Peltio Nov 9 '13 at 18:17
@Peltio That sounds like an answer to me. –  Szabolcs Nov 9 '13 at 18:24
@Peltio it's reasonable, but I'd like that the function g(x) was undefined when f(x) was negative. –  Fabrizio Nov 9 '13 at 18:27
Try Piecewise function, if it's works for you. –  Hinstein Nov 9 '13 at 18:32
@s.s.o In this way g(x) is defined only for positive x, instead I want that it is defined only when f(x) is positive. –  Fabrizio Nov 9 '13 at 18:54

You can check the Mathematica documentation about Condition /;

here is a simple example :

f[x_] := x + 5;
g[x_] := f[x] /; f[x] > 0

g[5]


10

g[-9]


g[-9]

-
@Szabolcs, in fact it was what I suggested as comment but it was not what OP asked for. –  s.s.o Nov 10 '13 at 19:39