Before starting this tutorial, some prerequisites are required and you should check the following tutorials:

- The Tutorial Electromagnetic and vibro-acoustic simulation of squirrel-cage induction machines
- And the series of How-Tos on “How to use MANATEE to optimize an external function?”

In this tutorial, we will assume that the file structure of an optimization project and the basic commands to run the optimization project in MANATEE are known.

### Optimization Problem

This tutorial will focus on the optimization of the default machine which is a squirrel-cage induction machine. On this tutorial, the objective will be to find the best slot opening in the stator (**W0s**) and the best number of slots in the rotor (**Zr**) to minimize the sound level generated by the machine (**Output.Acoustics.LwrA**) and maximize the torque delivered by the machine (**Ouput.Electrical.Cout**).

### Project File

The full project is in the *demo_optim.m* file. If you open it, you will see it corresponds to the default project with a few more parameters to allow the optimization. This file can be used as a template for all your future optimization problems in MANATEE.

The parameters important for the optimization case start at line 62. First, you have to set your optimization variables by writing their names used in MANATEE. If you need to verify the input variables names you can check them in Doc/MANATEE_Input_variables.xls. Here the two parameters are the slot opening in the stator (W0s) and the number of slots in the rotor (Zr). Thus, the code in the project will be:

`Input.Simu.names_var={'W0s';'Zr'};`

Here, we have two kinds of variables. The slot opening is a continuous variable and the number of slots is a discrete variable. We will also use an interval to define the width and set values for the discrete variable:

`Input.Simu.types_var=[0 1]; `

Input.Simu.types_val=[0 1];

The next step is to input the boundaries of the parameters.

`Input.Simu.bds_contvar={[5e-3 20e-3];[]};`

Here, the first parameter **W0s** will vary from 5mm to 20mm. As the second parameter **Zr** use "set" values, its vector is empty. The following line defines its different values:

`Input.Simu.set_discvar={[20:2:60]};`

Here, **Zr** will vary from 20 to 60 with only an even number of slots.

The different objectives can be set now. The objectives are variables from the output structures. The algorithm will always try to minimize them. Here, we want to minimize the sound power level so the first objective is ’**Output.Acoustics.LwrA**’. We want also to maximize the output torque. In optimization, maximizing an objective is equivalent to minimize its opposite. The second objective is then ’**-1*Output.Electrical.Cout**’.

`Input.Simu.names_resp={'Output.Acoustics.LwrA';'-1*Output.Electrical.Cout'};`

In this example, the OIF (Optimization Inputs File) is the default one: ’default_opt’. For details on how this file works, you can check here. The only difference is the objective function. When you optimize directly a MANATEE machine, the objective function is automatically built and a file generated. Its name is in the field **fileobjname**.

The last important parameter in the file is the line defining the constraint function.

`Input.Simu.const_name='demo_constfunc';`

Here, the constraints will be calculated using the file demo_constfunc. This file is built as the objective function file for an external problem. Its inputs are the two main structures of MANATEE: Input and Ouput. And then, a constraint vector is built. To respect the constraints each element must be under 0. In *demo_constfunc*, the vector is:

`const_vect=[15e-3-wrtav;];`

It means that wrtav (the average width of rotor teeth) must be above 15mm. More constraints can be added by adding more lines to the vector. The geometrical constraints of the machine are automatically added to the project.

You can now, run the simulation.