## 3 Matlab Implementation
### Iterative Solution (Lines 54-137)
The compliances of the optimized structure with two materials and the optimized structure with three materials are almost comparable, and the structure with five materials has a smaller compliance value. This is a strong demonstration of the advantages of multiple materials in increasing the stiffness of optimized structures from a three-dimensional perspective. Figure 6: The design domain and boundary conditions of the 3D cantilever beam. #### 5.2.2 Example 2: Different Filter Radii

The topology optimization of the cantilever beam with three materials is taken to test the performance of the code by considering different filter radii to further illustrate the performance of the 3D Matlab code. The filter radii are set as follows:

Figure 2.0 The optimized structure and converge history for topology optimization of multi-materials with 3D cantilever beam. (**a**) For two materials, the compliance is 432.94, where red and blue are materials with E = 1 and E = 5, respectively. (**b**) For three materials, the compliance is 433.05, where red, blue, and green are materials with E = 1, E = 2, and E = 5, respectively. (**c**) For five materials, the compliance is 400.24, where red, blue, cyan, yellow, and green are materials with E = 1, E = 2, E = 3, E = 4, and E = 5, respectively. Case 1: rmin = 2 Case 2: rmin = 5 Case 3: rmin = 8 The Young's moduli are set as par.E(1) = 1; par.E(2) = 2; par.E(3) = 5. The volume constraint is set to 0.5/3 for each material. Other parameters are the same as those in Section 5.2.1. The optimized structures are shown in Figure 2.1 The results show that the code performs well for feature size control of the optimized structure for topology optimization. Similarly, the topology and the objective function of the optimized structures are changed at different filter radii. As the filter radius is reduced, the advantage of multi-materials is fully utilized with smaller compliance values so that small features can be constructed to get a better local minimum. ## 6 Conclusions

In this paper, simple and efficient 2D and 3D Matlab codes are proposed simultaneously to reduce the barrier of the implementation of multi-material topology optimization. Multi-material topology optimization with the map-based interpolation function proposed by [PERSON] [16] et al. is implemented. The density filter is used to resolve the issues of mesh-dependent and checker-board problems. The projection function is used to ensure a 0-1 solution. The MMA algorithm is used to solve the minimum compliance problem under volume constraints. The algorithm is an extension of the 88-line code for the SIMP-based topology optimization of single materials, and we hope it can provide an educational instrument for newcomers to the field of multi-material topology optimization. Numerical examples of 2D structures with different materials and P-norm parameter \(p\) and 3D structures with different materials and filter radii are given to prove the effectiveness of the code. Conceptualization, B.Y. ; software, R.Z. ; validation, X.P. and G.-H.Y. ; writing--original draft preparation, R.Z. ; writing--review and editing, B.Y. ; visualization, X.P. and G.-H.Y. All authors have read and agreed to the published version of the manuscript. This work was funded by the Natural Science Foundation of China (No. 51975589) and the Fundamental Research Funds for the Central Universities of Central South University (No. CX20230110). Not applicable. The data presented in this study are available in the article. The authors thank [PERSON] from China Construction Fifth Engineering Division Corp., Ltd. for the discussion of this work. The authors declare no conflicts of interest. Figure 2.2 The optimized structure with different filter radii, where red, blue, and green are materials with E = 1, E = 2, and E = 5, respectively. (**a**) For rmin = 2, the compliance is 382.46. (**b**) For rmin = 5, the compliance is 433.05. (**c**) For rmin = 8, the compliance is 539.28.