# PWAG

Piece-Wise Affine Generic function object

## Contents

Class of MOBY-DIC TOOLBOX.

## Description

The pwag object describes a Piece-Wise Affine Generic function, i.e. a PWA function defined on a domain partitioned into irregular regions (polytopes). The generic j-th polytope is represented by an inequality in the form and, for all in the function assumes the value . The pwag object is derived from pwaFunction object.

## Syntax

**object = pwag()**

Builds an empty pwag object.

**object = pwag(regions,[D])**

Builds a pwag object given the edges of each polytope and the matrices representing the affine function defined over each polytope. regions is an array of structures (one for each polytope) with the following fields: H, K, F, G (see description above). D is a matrix representing the domain of the function, in the form . Optional argument.

**object = pwag(HybridToolboxController,[D])**

Builds an array of pwag objects starting from an MPC controller of class lincon or expcon (see Hybrid Toolbox). If the object is of class lincon (implicit MPC) it is converted into an expcon object (explicit MPC). The expcon object contains control functions for several (N) time istants (receding horizon), for each of these functions a pwag object is created. If soft constraints are enabled in expcon object, the last entry of the pwag array is the slack variable epsilon used to soften the constraints. D is the domain of the function (see above). Optional argument.

**object = pwag(MPTController,[D])**

Builds an array of pwag objects starting from an explicit MPC controller of class mptctrl (see MPT toolbox). The mptctrl object contains control functions for several (N) time istants (receding horizon), for each of these functions a pwag object is created. D is the domain of the function (see above). Optional argument.

## Properties

- nr - number of regions of the domain.
- edges - structure with fields H, K. H and K are the matrices defining the edges of the regions, in the form . H and K are "big" matrices containing all the edges without repetitions (if two polytopes have a common edge, it is not repeated). The edges of a particular polytope are accessed with addresses to these matrices.
- functions - structure with fields F,G. F and G are the matrices defining the coefficients of the affine functions on each polytope in the form . As for edges, F and G are "big" matrices containing all the coefficients without repetitions (if two polytopes have the same function, it is not repeated). The coefficients of a particular polytope are accessed with addresses to these matrices.
- regions - array of structures defining the polytopes of the partition. Each element of regions has the following fields: "Iedges": array whose k-th row contains, in the first column, the index of the row in matrices H and K corresponding to the k-th edge of the current region and, in the second column, a flag ('1' or '-1') indicating the sign of the inequality. '1' means , '-1' means , i.e. . "Ifunctions": array which contains the indexes of the rows in matrices F and G corresponding to the nf affine functions defined over the current region.
- tree - binary search tree associated to the domain partition, for the computation of the pwag function and for its digital implementation.

## Methods

- computeTree - computes the binary search tree associated to the domain partition.
- disp - displays some information about the pwag object.
- eval - evaluates the pwag function.
- findRegion - finds the polytope containing a given point.
- generateSimulinkModel - generates a Simulink model for the simulation of the closed-loop system
- getCircuitPerformances - gets the performances of the circuits implementing the pwag function
- getClosedLoop - gets the pwag function defining the closed loop system
- getEdges - gets the edges of a region.
- getFunctions - gets the coefficients of the affine function defined over a region.
- getNumberOfEdges - gets the number of different edges of the domain partition.
- getNumberOfRegions - gets the number of polytopes of the domain partition.
- getRegions - gets information about the requested polytope(s).
- plot - plots the pwag function
- plotTree - plots the binary search tree associated to the domain partition.
- synthesize - generates the VHDL files describing the digital circuit which implements the pwag function.
- vertices - gets the vertices of the polytopes of the domain partition.

## Private methods

- evalmex - Evaluates the pwag function
- generateMemory - Generates the memory matrix in binary form for the circuit implementation
- treeExplore - Retrieves information from the binary search tree
- treeStepPlot - Finds the polytope containing a given point.
- quantizeData -Quantize the coefficients of the PWAG function
- writeFSM - Writes the VHDL code implementing block FSM in pwag circuit
- writeInterface - Writes the VHDL code implementing block pwag_ser_interface or block pwag_par_interface in pwag circuit
- writeMemory - Writes the VHDL code implementing block Memory in pwag circuit
- writePackage - Writes the VHDL code implementing block pwag_ser_package or block pwag_par_package in pwag circuit
- writeTest - Writes the VHDL code implementing block test_pwag_ser_interface or block test_pwag_par_interface in pwag circuit

## Acknowledgements

Contributors:

- Alberto Oliveri (alberto.oliveri@unige.it)

Copyright is with:

- Copyright (C) 2011 University of Genoa, Italy.