## 3 Matlab Implementation
### Iterative Solution (Lines 54-137)
```
138%%PLOTENSITIES
139 xx=post_x(:,:,1);
140 fori=2:NMaterial
141 xx=xx+i*post_x(:,:,i);
142 end
143 imagesc(xx);axisequal;axisoff;colorbar;holdon;
144 plot([0 nelnxlex00]+0.5,[00 nelynely0]+0.5,'k');axis([-1 nelx+1-1 nely+i])
145 saveas(figure(1),'result.png');
```
### Visualization of the Optimization Procedure

To demonstrate the usability of the code, Figure 1 shows the final design result as well as the iteration details by calling the code in Appendix A. It can be found that the algorithm can converge stably and quickly to a clear result. To obtain the results of these intermediate optimization procedures, the code in Box 4 should be inserted after line 132 of the code in Appendix A. The code divides the figure into four sections, with the first three sections showing the density distributions for each of the three materials and the last section showing the results of the current optimized layout of multi-materials. Figure 1: The iteration details of the half MBB beam with three materials. ## 4 Numerical Examples

Several numerical examples of the minimum compliance problem are used to illustrate the running results of the Matlab code. The parameters of the above method will affect the final solution similar to conventional methods for topology optimization of continuum structure, and the effect of the parameters is also discussed in this section. The following cases are conducted by using Matlab R2018a on a desktop computer with an Intel CPU 2.8 GHz and 8.0 GB of RAM (Manufacturer: HP, Beijing, China). ### Example 1: The Number of Materials

The half MMB beam is taken as an example for the topology optimization of a continuum structure with two, three, and five materials, respectively. The design domain and boundary conditions of the half MBB beam are shown in Figure 2. A load \(F=-1\) is applied at the left upper side of the design domain, and it is simply supported at the bottom corners. The design domain is discretized with 200 \(\times\) 100 regular elements with Poisson's ratio \(\mu=0.3\). The initial density of each material is set to 0.5. The maximum number of iterations is set as NumIter = 300, the penalty factor is set as penal = 3, the filter radius is set as rmin = 5, and the P-norm parameter \(p\) is set as \(p=6\). The parameter for the projection function starts with beta = 1 and doubles its value after 50 iterations. The volume constraints of two, three, and five materials are set to 0.5/2, 0.5/3, and 0.5/5 for each material, respectively. The Young's modulus of each material for the three cases is set



little with the number of materials used for optimization, and they converge rapidly in the first 50 iterations. The material volumes also converge rapidly with about 10 iterations. The compliances of the optimized structures for all the cases are almost comparable, and the one with five materials is better than the others, which means that the appropriate layout of multiple materials can improve the stiffness of the optimized structure. ### Example 2: Different Values of Parameter \(p\) for the P-Norm

In order to show the influence of the parameter \(p\) on the interpolation function of [PERSON]'s modulus, a diagram of the interpolated Young's modulus \(\mathrm{E}\left(\overline{\pi}_{1}^{\alpha},\overline{\kappa}_{2}^{\alpha}, \cdots,\overline{\kappa}_{NM}^{\alpha}\right)\) as a function of parameter \(p\) is shown in Figure 4. Here it is assumed that \(\mathrm{NM}=2\). The Young's modulus of each material is set as \(E_{1}=1,E_{2}=5\), with penalty factor \(n=3\). It can be found that it cannot work well when parameter \(p\) is small. As parameter \(p\) increases, the interpolated Young's modulus decreases rapidly at the correct part with both design

Figure 3: The optimized structure and converge history for topology optimization of different numbers of materials. **(a)** For two materials, the compliance is 0.249, where cyan and yellow are the materials with \(\mathrm{E}=1\) and \(\mathrm{E}=5\), respectively.