Mathematica : Pulling inputs from a function; methodology question.

  • Context: Mathematica 
  • Thread starter Thread starter Hepth
  • Start date Start date
  • Tags Tags
    Function Mathematica
Click For Summary

Discussion Overview

The discussion revolves around the implementation of a custom Heaviside function in Mathematica, specifically focusing on how to replace the function with conditional statements based on its inputs. The scope includes technical explanations and methodology questions related to programming in Mathematica.

Discussion Character

  • Technical explanation, Methodology question

Main Points Raised

  • One participant introduces a Heaviside function with arbitrary inputs and seeks a way to create conditional statements based on those inputs.
  • Another participant suggests improving the readability of the initial post, indicating that clarity is important for technical discussions.
  • A later reply provides a solution involving the use of sequences within brackets to create an array, which allows for the desired conditional replacements to be made effectively.

Areas of Agreement / Disagreement

The discussion does not present any explicit areas of agreement or disagreement, but it includes a progression from a question to a proposed solution without any contention.

Contextual Notes

There may be limitations in the initial approach due to the handling of sequences and arrays in Mathematica, which are not fully resolved in the discussion.

Who May Find This Useful

Participants interested in Mathematica programming, particularly those dealing with conditional functions and replacements in their code.

Hepth
Science Advisor
Gold Member
Messages
458
Reaction score
40
I have a heaviside function:

Code:
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:
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:
F[x,y]/.{HeavisideTheta[a__]:> Product[If[a[[i]]>0,1,0],{i,1,Length[a]}]
(though that obviously won't work)Any suggestions?
 
Last edited:
Physics news on Phys.org
Hepth said:
Any suggestions?

You could tidy up your post so that it's readable!
 
PeroK said:
You could tidy up your post so that it's readable!

Is that any better?
 
I solved it, you use the sequence inside of a bracket to make it an array:

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

Similar threads

  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 5 ·
Replies
5
Views
5K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
7K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 14 ·
Replies
14
Views
8K
  • · Replies 15 ·
Replies
15
Views
2K