# Objective function

## Introduction

In the field **Objective function to optimize**, an operation to apply on the
objective function must be choosed, it can be defined on the available short list of
**Predefined Operation**, or with a custom function defined with
**Compose**.

The table bellow section summarizes all the predefined operations.

## Predefined Operations

Function | Formula |
---|---|

Design responses (global optimization of the arguments) | |

Average of responses (AVG) | $AVG\left(y1,y2,\dots ,yn\right)=\frac{{\sum}_{i=1}^{n}{y}_{i}}{n}$ |

Average of absolute value of responses (AVGABS) | $AVGABS\left(y1,y2,\dots ,yn\right)=\frac{{\sum}_{i=1}^{n}\left|{y}_{i}\right|}{n}$ |

Maximum of responses (MAX) | |

Maximum of absolute responses (MAXABS) | |

Minimu of responses (MIN) | |

Minimum of absolute responses (MINABS) | |

Root mean square value of responses (RMS) | $RMS\left(y1,y2,\dots ,yn\right)=\sqrt{\frac{{\sum}_{i=1}^{n}{y}_{i}^{2}}{n}}$ |

Square root of sum of squares of responses (RSS) | $RSS\left(y1,y2,\dots ,yn\right)=\sqrt{{\sum}_{i=1}^{n}{y}_{i}^{2}}$ |

Sum of square responses (SSQ) | $SSQ\left(y1,y2,\dots ,yn\right)={\sum}_{i=1}^{n}{y}_{i}^{2}$ |

Sum of responses (SUM) | $SUM\left(y1,y2,\dots ,yn\right)={\sum}_{i=1}^{n}{y}_{i}$ |

Sum of absolute value of responses (SUMABS) | $SUMABS\left(y1,y2,\dots ,yn\right)={\sum}_{i=1}^{n}\left|{y}_{i}\right|$ |

## Compose function

A custom operation on the quantities may also be defined with a **Compose**
function, this function must return a scalar value. An example of this function is
given below:

```
%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Objective function %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%
function [rresp, dresp, udata] = Obj_Func(iparam, rparam, nparam, iresp, rresp, dresp, nresp, isens, udata)
% iparam - vector of ints
% rparam - vector of doubles
% nparam - size of input vector
% iresp - vector of ints
% rresp - output parameter (vector of ints)
% dresp - output parameter (matrix of MxN dimension)
% nresp - size of output vector
% isens - sensitivity flag
% udata - userdata
Torque = rparam(1:nparam); % This variable contains all the values of the reponses for all the time steps,
% In this function, it contains the torque for each time step over an electrical period
Tr = mean(Torque) % Custom function based on the response previouly defined in Flux, computation of the torque ripple
rresp(1) = Tr % The mean value of the torque is used as an objective function
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Constraint function %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Lower and upper bounds of the constraint function are setted Flux
function [rresp, dresp, udata] = Cons(iparam, rparam, nparam, iresp, rresp, dresp, nresp, isens, udata)
% iparam - vector of ints
% rparam - vector of doubles
% nparam - size of input vector
% iresp - vector of ints
% rresp - output parameter (vector of ints)
% dresp - output parameter (matrix of MxN dimension)
% nresp - size of output vector
% isens - sensitivity flag
% udata - userdata
Torque = rparam(1:nparam); % This variable contains all the values of the reponses for all the time steps,
% In this function, it contains the torque for each time step over an electrical period
Tr = ( ( max(Torque) - min(Torque) ) / mean(Torque) ) *100 % Custom function based on the response previouly defined in Flux, computation of the torque ripple rate
rresp(1) = Tr
end
```

**rparam**,

**rrpesp(1)**and the name of the function must not be changed.

The OML file must be in the same folder as the .FLU project.