# optim.coder.infbound

Infinite bound support for code generation

Since R2022b

## Syntax

``bnd = optim.coder.infbound``
``bnd = optim.coder.infbound(sz)``
``bnd = optim.coder.infbound(n1,n2,...,nt)``
``bnd = optim.coder.infbound(___,typename)``
``bnd = optim.coder.infbound(___,"like",p)``

## Description

````bnd = optim.coder.infbound` creates an infinite bound for use in code generation. `bnd` represents an infinite bound for code generation targets that do not support `Inf`.```

example

````bnd = optim.coder.infbound(sz)` returns an infinite bound array of the same size as the argument `sz`. If `sz` is a scalar, the size of the returned array is `sz`-by-`sz`.```

example

````bnd = optim.coder.infbound(n1,n2,...,nt)` returns an infinite bound array of size `n1`-by-`n2`-by-...-by-`nt` for the scalar values `n1`, `n2`,…,`nt`.```

example

````bnd = optim.coder.infbound(___,typename)` specifies the data type (class) of `bnd` for any of the previous syntaxes.```

example

````bnd = optim.coder.infbound(___,"like",p)` specifies that `bnd` has the same as the data type as the numeric variable `p`.```

## Examples

collapse all

Target hardware for code generation does not always accept `Inf` or –`Inf` as a bound. In this case, use `optim.coder.infbound` to represent the infinite bounds.

For example, suppose your problem has upper bounds of `[Inf,1,10]`, meaning `x(2) <= 1` and `x(3) <= 10`, and no upper bound on `x(1)`. The problem also has lower bounds of `[0,``Inf,0]`, meaning `x(1) >= 0` and `x(3) >= 0`, and no lower bound on `x(2)`. You can represent these bounds in several ways.

`ub1 = [optim.coder.infbound 1 10]`
```ub1 = 1×3 Inf 1 10 ```
`lb1 = [0 -optim.coder.infbound 0]`
```lb1 = 1×3 0 -Inf 0 ```
```% Or ub = optim.coder.infbound(1,3); ub(2) = 1; ub(3) = 10```
```ub = 1×3 Inf 1 10 ```
```lb = -optim.coder.infbound([1,3]); lb(1) = 0; lb(3) = 0```
```lb = 1×3 0 -Inf 0 ```

Some target hardware supports only `"single"` data. Use the `typename` or `"like"` syntaxes to generate appropriate bounds.

`ub2 = [optim.coder.infbound("single") single(1) single(10)]`
```ub2 = 1x3 single row vector Inf 1 10 ```
```s0 = single(0); lb2 = [s0 -optim.coder.infbound("like",s0) s0]```
```lb2 = 1x3 single row vector 0 -Inf 0 ```

These results are produced from running the code in MATLAB®, and show the MATLAB `Inf` output. When you run `optim.coder.infbound` for code generation, the resulting bounds are appropriate for the target hardware.

## Input Arguments

collapse all

Size of the returned `Inf` array, specified as a vector of nonnegative integers. Generally, the size of the returned array is `sz(1)`-by-`sz(2)`-by-...-by-`sz(t)`, where `t` is the number of components of `sz`. However, if `sz` is a scalar, the size of the returned array is `sz`-by-`sz`.

If any entry in `sz` is zero, the returned array is empty.

Example: `[2,3,1,4]`

Data Types: `double`

Size of an `Inf` array component, specified as a nonnegative integer. If `n` is 0, the returned array is empty.

Example: `2`

Data Types: `double`

Output data type, specified as `"double"` or `"single"`. If you Disable Support for Nonfinite Numbers (MATLAB Coder) (for example, by setting `NonFiniteSupport` to `false` in the associated code generation configuration object), the output entries are `realmax(typename)`.

You cannot specify both `typename` and `"like",p`.

Currently, only `fmincon` supports single-precision code generation.

Data Types: `char` | `string`

Output data prototype, specified as a numeric variable of class `"double"` or `"single"`. If you Disable Support for Nonfinite Numbers (MATLAB Coder) (for example, by setting `NonFiniteSupport` to `false` in the associated code generation configuration object), the output entries are `realmax(class(p))`.

You cannot specify both `typename` and `"like",p`.

Currently, only `fmincon` supports single-precision code generation.

Data Types: `char` | `string`

## Version History

Introduced in R2022b

expand all