Get Help with Defining Functions in Mathematica

  • Thread starter Thread starter Qyzren
  • Start date Start date
  • Tags Tags
    Mathematica
Qyzren
Messages
41
Reaction score
0
Hi, not sure where to put this, so i'll just put it here.
i was wondering if there is a way to define functions of this sort in mathematica.
For example.
f(x)=x if x>0 and f(x)=2x if x<=0.

I know you can break it up into 2 functions and go something like
g[x_]:=x;
h[x_]:=2x;
but those are 2 different functions with different domain ranges (0,Inf), (-Inf,0].
what i want is just 1 function in mathematica with domain (-Inf, Inf) that knows to use g if x>0, and h if x<=0 in my example.

Thank you.

*edit i figured it out,
PS how do i delete my post?
 
Last edited:
Physics news on Phys.org
You can make use of the If statement.

f[x_]:=If[x>0,x,2x]
 
Last edited:
Prove $$\int\limits_0^{\sqrt2/4}\frac{1}{\sqrt{x-x^2}}\arcsin\sqrt{\frac{(x-1)\left(x-1+x\sqrt{9-16x}\right)}{1-2x}} \, \mathrm dx = \frac{\pi^2}{8}.$$ Let $$I = \int\limits_0^{\sqrt 2 / 4}\frac{1}{\sqrt{x-x^2}}\arcsin\sqrt{\frac{(x-1)\left(x-1+x\sqrt{9-16x}\right)}{1-2x}} \, \mathrm dx. \tag{1}$$ The representation integral of ##\arcsin## is $$\arcsin u = \int\limits_{0}^{1} \frac{\mathrm dt}{\sqrt{1-t^2}}, \qquad 0 \leqslant u \leqslant 1.$$ Plugging identity above into ##(1)## with ##u...
Back
Top