use a requirements table block to create formal requirements -凯发k8网页登录

main content

use a requirements table block to create formal requirements

since r2022a

use the block to model formal requirements. you establish formal requirements by using boolean formulas that check whether the required model behavior occurs during simulation. when you create a requirement in a requirements table block, you also create an equivalent requirement in the requirements editor. see .

define formal requirements

formal requirements are a set of unambiguous specifications that you express mathematically and execute through simulation. each formal requirement executes if at least one condition is true for a specified duration. when the requirement executes, the block verifies specified simulation behavior and produces additional simulation data.

to define formal requirements, add a requirements table block to your model.

this is the appearance of the requirements table block.

opening a new requirements table block displays a blank requirement. by default, the block opens on the requirements tab. each row of the table represents a requirement. the columns specify information used to evaluate each requirement. the columns are:

  • index — a unique identifier for each requirement. this column is read-only.

  • summary — a text-based summary of the requirement. entries in this column do not affect the block behavior. this column is optional.

  • precondition — a boolean expression that must be true for a specified duration before evaluating the rest of the requirement.

  • duration — the time, in seconds, during which the precondition must be true before evaluating the rest of the requirement. this column is optional. if left blank, the requirement does not have a duration. you must specify a precondition to use this column. see .

  • postcondition — a boolean expression that must be true if the associated precondition is true for the specified duration. if you do not include a precondition, the block checks the postcondition at each time step.

  • action — an action performed by the block if the associated precondition is true for the specified duration. you can use actions to define a block output or call a function. if you do not include a precondition, the block executes the action at each time step.

this shows the inside of a new requirements table block. it contains one blank requirement.

you can create multiple requirements, preconditions, postconditions, and actions. to manage columns and requirements, use options available in the table tab. you can also access additional options with the context menu by right-clicking the requirement index or column header cell.

you can also specify assumptions that define physical constraints of the system in the assumptions tab. see .

create expressions for formal requirements

you define preconditions, postconditions, and actions with expressions. use boolean expressions for preconditions and postconditions, and use a single equal sign = to define actions. the expressions in each precondition and postcondition cell must evaluate to a scalar logical.

use data in your expressions to manage information, such as signal values, workspace variables, or constant values. expressions can also include numerical values and functions. for example, the precondition u >= 0 checks if the data u is greater than or equal to 0, and the action y = 0 sets the data y equal to 0.

you can define preconditions, postconditions, and actions by explicitly listing each full expression in the requirement cells or by listing the left-hand side of the expression in the column header and defining the right-hand side of the expression in the requirement. to write boolean expressions that use headers in precondition and postcondition columns, use the boolean relational operator of interest, leave the left side blank, and enter the value of interest. to write actions that use headers, enter the value of the action into the cell.

for example, in this table the first postcondition specifies the data y1 in the header, the second specifies y2 in the requirement cell, and the action sets y3 equal to a vector of values.

this image shows a requirements table block that uses both header and non header syntaxes. the expressions evaluate the same content.

you can also check if a scalar header equals a single value, multiple values, or a range of values in the precondition and postcondition columns. use these syntaxes to specify the checked values:

syntaxdescription
valuechecks if the header data equals value.
value1,value2,value3,...,valuenchecks if the header data equals one of the comma-separated values.
[value1,value2]checks if the header data is greater than or equal to value1 and is less than or equal to value2.
(value1,value2)checks if the header data is greater than value1 and is less than value2.
[value1,value2)checks if the header data is greater than or equal to value1 and is less than value2.
(value1,value2]checks if the header data is greater than value1 and is less than or equal to value2.

in this table, the precondition checks if u is equal to 1, 2, or 3. the postcondition evaluates the data y1 and y2 by using the same boolean expression but with different notation. the first postcondition uses header data with interval notation and the second postcondition uses explicit boolean operators without header data.

this image shows a requirements table that uses both header and non header syntaxes with interval notation. the expressions evaluate the same expression using different notation.

to evaluate header data against multiple intervals, combine them with the logical or operator. for example, [0.3, 0.5] || (0.1, 0.2) is valid. in addition to real numbers, you can also use inf in an interval to evaluate a bound that goes to infinity. intervals including inf must be preceded or followed by a parenthesis. intervals including inf can be simplified if the cell contains only one interval. for example, (0.3, inf) is equivalent to > 0.3.

to specify that the header data should not equal an expression, use the logical not operator by entering ~= or ~ to the left of the cell values. you can apply this operator to single values, comma-separated values, or intervals. for example, if you did not want the header data u to fall within the interval [0.3, 0.5], enter ~[0.3, 0.5] or ~=[0.3, 0.5]. for comma-separated values, use only ~.

if your requirement cells contain a lot of content, the cell size can obstruct the expression. to view all of the content, you can adjust the size of the cell or add a new line. to add a new line, finish the first line with ... and then press alt enter.

use the x placeholder

when you enter expressions in a header, do not reuse the header expression in the cells of that column. for example, if a header contains the data u, do not enter the expression u >= 0.5 && u <= 0.3 in an associated column cell. instead, use x as a placeholder for the header. for example, the expression x >= 0.5 && x <= 0.3 in a precondition with u in the header is equivalent to u >= 0.5 && u <= 0.3 without u in the header.

this image shows a requirement with header data u and the placeholder x in the expression.

using the x placeholder can improve readability when the header is long.

check array data in preconditions and postconditions

if you use array data in preconditions and postconditions, the block checks if each element of the data satisfies the logical expression and produces a logical array. to check if a precondition or postcondition satisfies an array of values, use functions that evaluate to a scalar logical, such as the isequal or functions. for example, if y1 is a 1-by-4 array, and you want to check that it equals [1 2 3 4], enter isequal(y1,[1 2 3 4]) or all(y1 == [1 2 3 4]) into the cell.

use functions in requirements table blocks

you can use functions and operators in requirements table blocks in the requirement cells or column headers. enter data as arguments to the function or operator like you do with variables in matlab®. in this table, the cell u1 u2 == 2 and the cell below the header u3 u4 both check if the sum of the two input data equals 2.

this image shows a requirement that checks if the sum of the data is greater than 0 using the header and non-header notations.

the requirements table block does not support functions in headers that write to global variables or an internal state. for example, you cannot use the function in a header because rand writes to an internal state each time it generates a number.

define block data

in order to use data in the block, you must enter them in your requirements and define them in the symbols pane. to open the symbols pane, open a requirements table block. in the modeling tab, in the design data section, click symbols pane.

in the symbols pane, the icon in the type column indicates the scope of your data. you can set the data scope to be input, output, local, constant, or parameter. you can also change the name, the initial data value, and the port number. to modify additional properties, right-click the data name and select inspect to open the property inspector. for more information, see .

this image shows the symbols pane with the name of an input data u and an output data y, along with the data names, data types, and port numbers.

as you edit your requirements, the requirements table block detects undefined data and marks them in the symbols pane with the undefined symbol icon . unresolved data can cause errors during compilation. to resolve data, click the resolve undefined symbols button .

observe or generate model behavior

you can use the requirements table block to check model requirements by observing the model behavior, or by generating behavior that can be compared to the model behavior.

observe model behavior

you can use the requirements table block to observe the model behavior without executing actions. if the model behavior does not satisfy a precondition, the block does not check the associated postcondition. if the model behavior does not satisfy the postcondition for a requirement when the precondition is satisfied, the requirements table block produces a warning in the diagnostic viewer. to use the requirements table block to observe requirements, use the preconditions to specify model input behavior, and use the postconditions to specify model output behavior. to differentiate between the model inputs and outputs, enable the treat as design model output for analysis property in the property inspector for the data specified in the postconditions.

this model contains a requirements table block that tests a basic subsystem that has two inputs and outputs two values. the requirements table block checks whether the inputs and outputs of the subsystem meet the specified requirements by using logical definitions for the preconditions and postconditions.

open the requirements table block to see the requirements specified for the inputs and outputs of the subsystem. the requirements specify logical constraints on the subsystem outputs for each subsystem input. the requirements table block captures the subsystem inputs with the data u1 and u2, and captures the subsystem outputs with the data y1 and y2. the block defines the data as input data, which allows the block to capture the subsystem signals as block inputs.

when you run the model, the requirements table block checks if the subsystem block inputs satisfy the preconditions. if the preconditions are met, the requirements table block checks if the subsystem block outputs satisfy the postconditions.

this example subsystem block satisfies the preconditions and postconditions. to generate a warning, set the postcondition of the first requirement to y1 < 0 and run the simulation again. the diagnostic viewer displays a warning message.

generate model behavior

you can also use the requirements table block to execute actions when the model meets corresponding preconditions. you specify the action for each requirement by using the action column.

this model contains a requirements table block that tests a subsystem that takes two inputs and creates two outputs. the requirements table block takes the subsystem inputs and outputs a set of values if the preconditions are met. each requirements table block output corresponds to one of the outputs from the subsystem. if the output of the subsystem does not equal the corresponding output signal from the requirements table block, the assertion blocks stop the simulation and produce an error.

open the requirements table block to see the two requirements specified for the inputs of the subsystem. the requirements specify logical constraints on the inputs. the block defines the data u1 and u2 as input data, which allows the block to capture the subsystem inputs as block inputs. the block defines the data y1 and y2 as output data.

when you run the model, the requirements table block checks whether the subsystem block inputs meets the preconditions, and assigns the output signals to the values specified in the action column. the model then compares the outputs from the subsystem block with the output signals from the requirements table block. in this example, the outputs are equal and the assertions pass.

see also

related topics

    网站地图