File: utils-Heaviside.R

package info (click to toggle)
fbasics 4041.97-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,016 kB
  • sloc: ansic: 740; makefile: 14
file content (174 lines) | stat: -rw-r--r-- 4,112 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174

# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
# GNU Library General Public License for more details.
#
# You should have received a copy of the GNU Library General 
# Public License along with this library; if not, write to the 
# Free Foundation, Inc., 59 Temple Place, Suite 330, Boston, 
# MA  02111-1307  USA


################################################################################
# FUNCTION:                 HEAVISIDE AND RELATED FUNCTIONS:
#  Heaviside                 Computes Heaviside unit step function
#  Sign                      Another signum function
#  Delta                     Computes delta function
#  Boxcar                    Computes boxcar function
#  Ramp                      Computes ramp function
################################################################################


Heaviside <- 
function(x, a = 0) 
{   
    # A function implemented by Diethelm Wuertz

    # Description:
    #   Computes the Heaviside or unit step function.
    
    # Arguments:
    #   x - a numeric vector.
    #   a - the location of the break.
    
    # Details:
    #   The Heaviside step function is 1 for x>a, 1/2 for x=a,
    #   and 0 for x<a.
    
    # Notes:
    #   Heaviside Unit Step Function and Related Functions
    #   See:  http://mathworld.wolfram.com/HeavisideStepFunction.html
    #   Note: sign(x) is part of R's base package
       
    # FUNCTION:
    
    # Compute H:
    result = (sign(x-a) + 1)/2
    
    # Return Value:
    result
}


# ------------------------------------------------------------------------------


Sign <- 
function(x, a = 0) 
{   
    # A function implemented by Diethelm Wuertz

    # Description:
    #   Computes the (modofied) Sign function.
    
    # Arguments:
    #   x - a numeric vector.
    #   a - the location of the break.
    
    # Details:
    #   The Sign function is 1 for x>a, 0 for x=a,
    #   and -1 for x<a.
     
    # FUNCTION:
    
    # Compute Sign:
    result = sign(x-a)
    
    # Return Value:
    result
}


# ------------------------------------------------------------------------------


Delta <- 
function(x, a = 0) 
{   
    # A function implemented by Diethelm Wuertz

    # Description:
    #   Computes the delta function.
    
    # Arguments:
    #   x - a numeric vector.
    #   a - the location of the break.
    
    # Details:
    #   The delta function is defined as: delta(x) = d/dx Heaviside(x-a)

    # FUNCTION:
    
    # Compute delta:
    result = 1/sign(abs(x-a))-1
    
    # Return Value:
    result
}


# ------------------------------------------------------------------------------


Boxcar <- 
function(x, a = 0.5) 
{   
    # A function implemented by Diethelm Wuertz

    # Description:
    #   Computes the boxcar function.
    
    # Arguments:
    #   x - a numeric vector.
    #   a - the location of the break.
    
    # Details:
    #   The boxcar function is defined as: 
    #       Pi(x) = Heaviside(x+a) - Heaviside(x-a)

    # FUNCTION:
    
    # Compute boxcar:
    result = Heaviside(x-a) - Heaviside(x+a)
    
    # Return Value:
    result
}


# ------------------------------------------------------------------------------


Ramp <- 
function(x, a = 0) 
{   
    # A function implemented by Diethelm Wuertz

    # Description:
    #   Computes the ramp function.
    
    # Arguments:
    #   x - a numeric vector.
    #   a - the location of the break.
    
    # Details:
    #   The ramp function is defined as: R(x)= (x-a)*Heaviside(x-a)

    # FUNCTION:
    
    # Compute ramp:
    result = (x-a) * Heaviside(x-a)
    
    # Return Value:
    result
}


################################################################################