1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Mathematica help

  1. Jul 3, 2009 #1
    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: Jul 3, 2009
  2. jcsd
  3. Jul 4, 2009 #2

    Cyosis

    User Avatar
    Homework Helper

    You can make use of the If statement.

    f[x_]:=If[x>0,x,2x]
     
    Last edited: Jul 4, 2009
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Mathematica help
  1. Mathematica Help (Replies: 1)

  2. Mathematica ODE help (Replies: 6)

Loading...