Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Mathematica : Pulling inputs from a function; methodology question.

Tags:
  1. Jan 3, 2014 #1

    Hepth

    User Avatar
    Gold Member

    I have a heaviside function:

    Code (Text):
    HeavisideTheta[a,b,c,d,e,...]
    where the letters correspond to functions, and the number of functions is arbitrary.

    I want to make a replacement so that
    Code (Text):

    HeavisideTheta[a_]:> If[a>0,1,0]
    HeavisideTheta[a_,b_]:>If[a>0,1,0] If[b>0,1,0]
     

    or something similar.
    I wish to take the inputs to the heaviside function, and create an "If" statement out of them.

    So if I have a function that contains this HeavisideTheta, I can do a replacement as:

    Code (Text):

    F[x,y]/.{HeavisideTheta[a__]:> Product[If[a[[i]]>0,1,0],{i,1,Length[a]}]
     
    (though that obviously wont work)


    Any suggestions?
     
    Last edited: Jan 3, 2014
  2. jcsd
  3. Jan 3, 2014 #2

    PeroK

    User Avatar
    Science Advisor
    Homework Helper
    Gold Member

    You could tidy up your post so that it's readable!
     
  4. Jan 3, 2014 #3

    Hepth

    User Avatar
    Gold Member

    Is that any better?
     
  5. Jan 3, 2014 #4

    Hepth

    User Avatar
    Gold Member

    I solved it, you use the sequence inside of a bracket to make it an array:

    Code (Text):

    HeavisideTheta[a, b, c] /. {HeavisideTheta[a__] :> Product[If[{a}[[i]] > 0, 1, 0], {i, 1, Length[{a}]}]}
     
    gives
    Code (Text):

    If[a > 0, 1, 0] If[b > 0, 1, 0] If[c > 0, 1, 0]
     
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Mathematica : Pulling inputs from a function; methodology question.
Loading...