triangularPulse

Triangular pulse function

Syntax

triangularPulse(a,b,c,x)
triangularPulse(a,c,x)
triangularPulse(x)

Description

triangularPulse(a,b,c,x) returns the triangular pulse function.

triangularPulse(a,c,x) is a shortcut for triangularPulse(a, (a + c)/2, c, x).

triangularPulse(x) is a shortcut for triangularPulse(-1, 0, 1, x).

Input Arguments

a

Number (including infinities and symbolic numbers), symbolic variable, or symbolic expression. This argument specifies the rising edge of the triangular pulse function.

Default: -1

b

Number (including infinities and symbolic numbers), symbolic variable, or symbolic expression. This argument specifies the peak of the triangular pulse function.

Default: If you specify a and c, then (a + c)/2. Otherwise, 0.

c

Number (including infinities and symbolic numbers), symbolic variable, or symbolic expression. This argument specifies the falling edge of the triangular pulse function.

Default: 1

x

Number (including infinities and symbolic numbers), symbolic variable, or symbolic expression.

Examples

Compute the triangular pulse function for these numbers. Because these numbers are not symbolic objects, you get floating-point results:

[triangularPulse(-2, 0, 2, -3)
triangularPulse(-2, 0, 2, -1/2)
triangularPulse(-2, 0, 2, 0)
triangularPulse(-2, 0, 2, 3/2)
triangularPulse(-2, 0, 2, 3)]
ans =
         0
    0.7500
    1.0000
    0.2500
         0

Compute the triangular pulse function for the numbers converted to symbolic objects:

[triangularPulse(sym(-2), 0, 2, -3)
triangularPulse(-2, 0, 2, sym(-1/2))
triangularPulse(-2, sym(0), 2, 0)
triangularPulse(-2, 0, 2, sym(3/2))
triangularPulse(-2, 0, sym(2), 3)]
ans =
   0
 3/4
   1
 1/4
   0

Compute the triangular pulse function for a < x < b:

syms a b c x
assume(a < x < b)
triangularPulse(a, b, c, x)
ans =
(a - x)/(a - b)

For further computations, remove the assumption:

syms a b x clear

Compute the triangular pulse function for b < x < c:

assume(b < x < c)
triangularPulse(a, b, c, x)
ans =
-(c - x)/(b - c)

For further computations, remove the assumption:

syms b c x clear

Compute the triangular pulse function for a = b:

syms a b c x
assume(b < c)
triangularPulse(b, b, c, x)
ans =
-((c - x)*rectangularPulse(b, c, x))/(b - c)

Compute the triangular pulse function for c = b:

assume(a < b)
triangularPulse(a, b, b, x)
ans =
((a - x)*rectangularPulse(a, b, x))/(a - b)

For further computations, remove all assumptions on a, b, and c:

syms a b c clear

Use triangularPulse with one input argument as a shortcut for computing triangularPulse(-1, 0, 1, x):

syms x
triangularPulse(x)
ans =
triangularPulse(-1, 0, 1, x)
[triangularPulse(sym(-10))
triangularPulse(sym(-3/4))
triangularPulse(sym(0))
triangularPulse(sym(2/3))
triangularPulse(sym(1))]
ans =
   0
 1/4
   1
 1/3
   0

Use triangularPulse with three input arguments as a shortcut for computing triangularPulse(a, (a + c)/2, c, x):

syms a c x
triangularPulse(a, c, x)
ans =
triangularPulse(a, a/2 + c/2, c, x)
[triangularPulse(sym(-10), 10, 3)
triangularPulse(sym(-1/2), -1/4, -2/3)
triangularPulse(sym(2), 4, 3)
triangularPulse(sym(2), 4, 6)
triangularPulse(sym(-1), 4, 0)]
ans =
 7/10
    0
    1
    0
  2/5

Plot the triangular pulse function:

syms x
ezplot(triangularPulse(x), [-2, 2])

Call triangularPulse with infinities as its rising and falling edges:

syms x
triangularPulse(-1, 0, inf, x)
triangularPulse(-inf, 0, 1, x)
triangularPulse(-inf, 0, inf, x)
ans =
heaviside(x) + (x + 1)*rectangularPulse(-1, 0, x)
 
ans =
heaviside(-x) - (x - 1)*rectangularPulse(0, 1, x)
 
ans =
1

More About

expand all

Triangular Pulse Function

If a < x < b, then the triangular pulse function equals (x - a)/(b - a).

If b < x < c, then the triangular pulse function equals (c - x)/(c - b).

If x <= a or x >= c, then the triangular pulse function equals 0.

The triangular pulse function is also called the triangle function, hat function, tent function, or sawtooth function.

Tips

  • If a, b, and c are variables or expressions with variables, triangularPulse assumes that a <= b <= c. If a, b, and c are numerical values that do not satisfy this condition, triangularPulse throws an error.

  • If a = b = c, triangularPulse returns 0.

  • If a = b or b = c, the triangular function can be expressed in terms of the rectangular function.

Was this topic helpful?