Main Content

subplus

Calculate positive part of function

Description

example

xp = subplus(x) returns the positive part of x, (x)+, which is x if x is nonnegative, and 0 if x is negative. In other words, xp equals max(x,0). If x is an array, this operation is applied entry by entry.

Examples

collapse all

Compute the positive part of integers in the range from -2 to 2 by using the subplus function.

x = -2:2;
xp = subplus(x);

Plot the subplus function on the interval from -2 to 2.

plot(x,xp)
ylim([-0.5 2.5])

Create a hat function by creating an anonymous function hat that uses the subplus function.

hat = @(x) subplus(x) - 2*subplus(x-1) + subplus(x-2);

Plot the hat function on the interval from -0.5 to 2.5.

x = -0.5:0.5:2.5;
plot(x,hat(x))
xlim([-0.5 2.5])

You can also describe the hat function by using the spline spmak(0:2,1).

Input Arguments

collapse all

Function of which you want to calculate the positive part, specified as a scalar, vector, or matrix.

Data Types: single | double

Output Arguments

collapse all

Positive part of x, returned as a scalar, vector, or matrix.

Version History

Introduced in R2006b