main content

exterior penalty value for a point with respect to a bounded region -凯发k8网页登录

exterior penalty value for a point with respect to a bounded region

since r2021b

description

example

p = exteriorpenalty(x,xmin,xmax,method) uses the specified method to calculate the nonnegative (exterior) penalty vector p for the point x with respect to the region bounded by xmin and xmax. p has the same dimension as x.

examples

this example shows how to use the exteriorpenalty function to calculate the exterior penalty for a given point, with respect to a bounded region.

calculate the penalty value for the point 0.1 within the interval [-2,2], using the step method.

exteriorpenalty(0.1,-2,2,"step")
ans = 0

calculate the penalty value for the point 4 outside the interval [-2,2], using the step method.

exteriorpenalty(4,-2,2,"step")
ans = 1

calculate the penalty value for the point 4 outside the interval [-2,2], using the quadratic method.

exteriorpenalty(4,-2,2,"quadratic")
ans = 4

calculate the penalty value for the point [-2,0,4] with respect to the box defined by the intervals [0,1], [-1,1], and [-2,2] along the x, y, and z dimensions, respectively, using the quadratic method.

exteriorpenalty([-2 0 4],[0 -1 -2],[1 1 2],"quadratic")
ans = 3×1
     4
     0
     4

visualize penalty values for an interval

create a vector of 1001 equidistant points distributed between -5 and 5.

x = -5:0.01:5;

calculate penalties for all the points in the vector, using the quadratic method.

p = exteriorpenalty(x,-2,2,"quadratic");

plot the points and add grid, labels, and title.

plot(x,p)
grid
xlabel("point position");
ylabel("penalty value");
title("penalty values over an interval");

figure contains an axes object. the axes object with title penalty values over an interval, xlabel point position, ylabel penalty value contains an object of type line.

input arguments

point for which the exterior penalty is calculated, specified as a numeric scalar, vector, or matrix.

example: [-0.1, 1.3]

lower bounds for x, specified as a numeric scalar, vector, or matrix. to use the same minimum value for all elements in x, specify xmin as a scalar.

example: -2

upper bounds for x, specified as a numeric scalar, vector, or matrix. to use the same maximum value for all elements in x, specify xmax as a scalar.

example: [5 10]

function used to calculate the penalty, specified either as 'step' or 'quadratic'. you can also use strings instead of character vectors.

example: "quadratic"

output arguments

penalty value, returned as a vector of nonnegative elements. with either of the two methods, each element pi is zero if the corresponding xi is within the region specified by xmini and xmaxi, and it is positive otherwise. penalty functions are typically used to generate negative rewards when constraints are violated, such as in generaterewardfunction.

extended capabilities

c/c code generation
generate c and c code using matlab® coder™.

version history

introduced in r2021b

网站地图