Mathematica help

  • Thread starter Qyzren
  • Start date
  • #1
44
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:

Answers and Replies

  • #2
Cyosis
Homework Helper
1,495
0
You can make use of the If statement.

f[x_]:=If[x>0,x,2x]
 
Last edited:

Related Threads on Mathematica help

  • Last Post
Replies
1
Views
2K
  • Last Post
Replies
6
Views
1K
Replies
3
Views
785
Replies
1
Views
1K
Replies
7
Views
5K
  • Last Post
Replies
7
Views
885
  • Last Post
Replies
6
Views
1K
  • Last Post
Replies
1
Views
1K
  • Last Post
Replies
4
Views
2K
  • Last Post
Replies
0
Views
889
Top