{"id":2254,"date":"2017-04-10T03:43:43","date_gmt":"2017-04-10T08:43:43","guid":{"rendered":"https:\/\/blogs.mathworks.com\/loren\/?p=2254"},"modified":"2017-04-24T09:55:03","modified_gmt":"2017-04-24T14:55:03","slug":"optimizing-a-structural-design","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/loren\/2017\/04\/10\/optimizing-a-structural-design\/","title":{"rendered":"Optimizing a Structural Design"},"content":{"rendered":"<div class=\"content\"><!--introduction--><p>Today you'll see a new demonstration of applying optimization techniques. Today's guest is <a href=\"https:\/\/jp.mathworks.com\/matlabcentral\/profile\/authors\/1892029-takafumi\/\">Takafumi Ohbiraki<\/a>. This demonstration was part of the contents of the MATLAB EXPO which was held in Tokyo last year (2016).<\/p><!--\/introduction--><h3>Contents<\/h3><div><ul><li><a href=\"#a39069f6-0967-49d8-a503-7f0818e83373\">Design of an umbrella hook<\/a><\/li><li><a href=\"#93b609dd-6320-4db4-8948-5fad1ffe9a47\">FEM model (Using  Partial Differential Equation (PDE) Toolbox)<\/a><\/li><li><a href=\"#d6f2afa2-28d7-4f4d-9d3a-5595c918d4f8\">Process of Optimization<\/a><\/li><li><a href=\"#d6fcd575-d45e-4649-89ad-521e63ae29a3\">Design of Experiments (DOE) (Taguchi design)<\/a><\/li><li><a href=\"#3ec96909-4b13-430a-9d89-d0673847013c\">Calculation with setting parameters for L18<\/a><\/li><li><a href=\"#6f539ccd-5e59-40f5-98a1-52377df622ff\">Factor Effect Chart<\/a><\/li><li><a href=\"#662fa968-5828-4389-beb5-5e635181135b\">S\/N ratio<\/a><\/li><li><a href=\"#8dc573cc-68b9-4771-8af9-290b4af6e52a\">Output<\/a><\/li><li><a href=\"#9b6e3f0b-cec9-4b1b-ad7a-42293405bb51\">Optimization using patternsearch solver<\/a><\/li><li><a href=\"#37e24da4-71ed-4b90-b3c3-de3ae408cb10\">Optimization using ga solver<\/a><\/li><li><a href=\"#dfdcafec-0fe7-473b-b232-de4cb088ea5d\">Multi-objective optimization using the gamultiobj solver<\/a><\/li><li><a href=\"#b981f84e-7ab1-4424-bc06-6676e50716f1\">Conclusion<\/a><\/li><\/ul><\/div><p>Optimization is a universal topic in both engineering and data science. It is a technology with high needs. Speaking of optimization in engineering, parameter estimation is often performed on a model showing a physical phenomenon.<\/p><p>Generally, when expressing a physical phenomenon by a model, MATLAB has functions of ordinary differential equations and partial differential equations,and performs simulation. For example, since the problem of heat conduction can be represented by parabolic partial differential equations on the second floor, it is possible to simulate with the function <tt><a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/pdepe.html\">pdepe<\/a><\/tt>.<\/p><p>In reality, it is often difficult to convert a physical phenomenon into a closed-form mathematical formula. So it is common to utilize a modeling tool to convert the problem into a mathematical model for analysis.<\/p><p>At this time, we will introduce how to optimize the design by using <a href=\"https:\/\/www.mathworks.com\/products\/pde.html\">Partial Differential Equation Toolbox<\/a> and <a href=\"https:\/\/www.mathworks.com\/products\/optimization.html\">Optimization Toolbox<\/a> with an example of structural analysis.<\/p><h4>Design of an umbrella hook<a name=\"a39069f6-0967-49d8-a503-7f0818e83373\"><\/a><\/h4><p>A cool umbrella hook is always seen in Japanese public restrooms.<\/p><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/loren\/2017\/hook.png\" alt=\"\"> <\/p><p>As a designer of an umbrella hook, we will consider how to reduce the cost by reducing the materials used for an umbrella hook. However, in order to keep the functionality of the umbrella hook, it is necessary to for the hook not to bend.<\/p><p>First, we define the design specifications. We consider opening an elliptical cavity in the member. The material (A or B) of the member, the coordinates (X, Y) of the ellipse, the radius of the ellipse (RX, RY), and the rotation angle of the ellipse (theta) are design parameters. The number of parameters is seven.<\/p><p>We will set the downward load on the tightening portion at the upper right and the fixed end at the left end. We perform an optimization with the aim of minimizing the displacement amount of the lower right point.<\/p><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/loren\/2017\/hook_image.png\" alt=\"\"> <\/p><p>All parameters have the following constraints.<\/p><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/loren\/2017\/parameter.png\" alt=\"\"> <\/p><h4>FEM model (Using  Partial Differential Equation (PDE) Toolbox)<a name=\"93b609dd-6320-4db4-8948-5fad1ffe9a47\"><\/a><\/h4><p>We create a function <tt><a href=\"https:\/\/blogs.mathworks.com\/images\/loren\/2017\/pdesample.m\">pdesample<\/a><\/tt> to actually simulate with parameters using Partial Differential Equation Toolbox (PDE Toolbox).<\/p><p>input: [material x-position y-position x-radius y-radius stick theta] output : strain<\/p><pre class=\"codeinput\">in = [1 5,2,1.5,1.0,0.3,0];\r\nlh = pdesample\r\nout = lh{1}(in)\r\n<\/pre><pre class=\"codeoutput\">lh =\r\n  5&times;1 cell array\r\n    @pdesample_input       \r\n    @pdesample_input_doe_sn\r\n    @myobjfun              \r\n    @myobjfun2             \r\n    @mynoncon              \r\nout =\r\n      0.40131\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/loren\/2017\/optimizingDesignStructure_01.png\" alt=\"\"> <p>This is the initial condition.<\/p><p>Output is about 0.4013. We do not understand whether this result is good or bad. We will seek a good answer using optimization techniques.<\/p><h4>Process of Optimization<a name=\"d6f2afa2-28d7-4f4d-9d3a-5595c918d4f8\"><\/a><\/h4><p>To actually perform the optimization calculation, if there are too many parameters, it takes time to reach the optimum value. This time, we will utilize a two-step optimization method that is often used in quality engineering. According to the two-step design method, first, make efforts to reduce the number of variables to be optimized by utilizing the experimental design method. In this method, we adopt the Taguchi design. The orthogonal table is uploaded to the <a href=\"http:\/\/jp.mathworks.com\/matlabcentral\/fileexchange\/60769-orthogonalarray--l-name-varargin-\">File Exchange<\/a>. In variable selection, we paid attention to the signal to noise ratio (S\/N) ratio and the nominal-is-best response. In the second step, we use optimization algorithms to find good parameters.<\/p><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/loren\/2017\/optworkflow.png\" alt=\"\"> <\/p><h4>Design of Experiments (DOE) (Taguchi design)<a name=\"d6fcd575-d45e-4649-89ad-521e63ae29a3\"><\/a><\/h4><p>We will exploit which parameters should be reduced by utilizing the orthogonal array famous from the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Taguchi_methods\">Taguchi design<\/a>. In the orthogonal array of Taguchi design, there are 2 factors, 3 factors, and mixed orthogonal tables. We chose the famous L18 model for mixing both 2 factors and 3 factors.<\/p><p>L18 model : 18 experiments to make the combination of 8 variables efficient; one variable (material) is 2 levels , seven variables are 3 levels. The variable <tt>design<\/tt> created by my helper function <a href=\"http:\/\/jp.mathworks.com\/matlabcentral\/fileexchange\/60769-orthogonalarray--l-name-varargin-\"><tt>orthogonalarray<\/tt><\/a> is a MATLAB table.<\/p><pre class=\"codeinput\">design = orthogonalarray(<span class=\"string\">'L18'<\/span>,<span class=\"string\">'Bounds'<\/span>,[1 2;2.0 8.0;1.0 3.0;0.5 1.9;0.2 0.9;0.1 0.3;-pi\/12 pi\/12;0 0],<span class=\"keyword\">...<\/span>\r\n    <span class=\"string\">'VariableNames'<\/span>,{<span class=\"string\">'material'<\/span>,<span class=\"string\">'x'<\/span>,<span class=\"string\">'y'<\/span>,<span class=\"string\">'rx'<\/span>,<span class=\"string\">'ry'<\/span>,<span class=\"string\">'dh'<\/span>,<span class=\"string\">'theta'<\/span>,<span class=\"string\">'xxx'<\/span>})\r\n<\/pre><pre class=\"codeoutput\">design =\r\n  18&times;8 table\r\n    material    x    y    rx      ry     dh      theta     xxx\r\n    ________    _    _    ___    ____    ___    _______    ___\r\n    1           2    1    0.5     0.2    0.1    -0.2618    0  \r\n    1           2    2    1.2    0.55    0.2          0    0  \r\n    1           2    3    1.9     0.9    0.3     0.2618    0  \r\n    1           5    1    0.5    0.55    0.2     0.2618    0  \r\n    1           5    2    1.2     0.9    0.3    -0.2618    0  \r\n    1           5    3    1.9     0.2    0.1          0    0  \r\n    1           8    1    1.2     0.2    0.3          0    0  \r\n    1           8    2    1.9    0.55    0.1     0.2618    0  \r\n    1           8    3    0.5     0.9    0.2    -0.2618    0  \r\n    2           2    1    1.9     0.9    0.2          0    0  \r\n    2           2    2    0.5     0.2    0.3     0.2618    0  \r\n    2           2    3    1.2    0.55    0.1    -0.2618    0  \r\n    2           5    1    1.2     0.9    0.1     0.2618    0  \r\n    2           5    2    1.9     0.2    0.2    -0.2618    0  \r\n    2           5    3    0.5    0.55    0.3          0    0  \r\n    2           8    1    1.9    0.55    0.3    -0.2618    0  \r\n    2           8    2    0.5     0.9    0.1          0    0  \r\n    2           8    3    1.2     0.2    0.2     0.2618    0  \r\n<\/pre><h4>Calculation with setting parameters for L18<a name=\"3ec96909-4b13-430a-9d89-d0673847013c\"><\/a><\/h4><p>At experimental points, we calculate the outputs (strain) and S\/N ratios.<\/p><pre class=\"codeinput\">output = zeros(18,1);\r\nsn = zeros(18,1);\r\n\r\n<span class=\"keyword\">for<\/span> i = 1:18\r\n    output(i,1) = lh{1}(table2array(design(i,1:8)));\r\n    sn(i,1) = lh{2}(table2array(design(i,1:8)));\r\n<span class=\"keyword\">end<\/span>\r\n\r\nresults = [design table(output,sn)]\r\n<\/pre><pre class=\"codeoutput\">results =\r\n  18&times;10 table\r\n    material    x    y    rx      ry     dh      theta     xxx    output       sn  \r\n    ________    _    _    ___    ____    ___    _______    ___    _______    ______\r\n    1           2    1    0.5     0.2    0.1    -0.2618    0        0.346    108.16\r\n    1           2    2    1.2    0.55    0.2          0    0      0.36042    88.027\r\n    1           2    3    1.9     0.9    0.3     0.2618    0      0.42694    57.447\r\n    1           5    1    0.5    0.55    0.2     0.2618    0      0.35443    88.063\r\n    1           5    2    1.2     0.9    0.3    -0.2618    0      0.37875    78.837\r\n    1           5    3    1.9     0.2    0.1          0    0      0.36595    84.527\r\n    1           8    1    1.2     0.2    0.3          0    0      0.33836     121.1\r\n    1           8    2    1.9    0.55    0.1     0.2618    0      0.38466    59.585\r\n    1           8    3    0.5     0.9    0.2    -0.2618    0      0.34978    96.122\r\n    2           2    1    1.9     0.9    0.2          0    0       1.8659    32.802\r\n    2           2    2    0.5     0.2    0.3     0.2618    0      0.92894    132.08\r\n    2           2    3    1.2    0.55    0.1    -0.2618    0      0.97881    90.175\r\n    2           5    1    1.2     0.9    0.1     0.2618    0       1.2566    41.031\r\n    2           5    2    1.9     0.2    0.2    -0.2618    0       1.0356     78.99\r\n    2           5    3    0.5    0.55    0.3          0    0      0.94161       113\r\n    2           8    1    1.9    0.55    0.3    -0.2618    0        1.019     59.27\r\n    2           8    2    0.5     0.9    0.1          0    0      0.95126    106.67\r\n    2           8    3    1.2     0.2    0.2     0.2618    0      0.95404    88.904\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/loren\/2017\/optimizingDesignStructure_02.png\" alt=\"\"> <h4>Factor Effect Chart<a name=\"6f539ccd-5e59-40f5-98a1-52377df622ff\"><\/a><\/h4><p>The factor effect diagram is a graph expressing the effect of each factor, with the horizontal axis representing the level of the factor and the vertical axis representing the S \/ N ratio and the characteristic value. From this graph, find the condition with high S \/ N ratio and select the one with better characteristics.<\/p><p><a href=\"https:\/\/blogs.mathworks.com\/images\/loren\/2017\/factoreffectchart.m\"><tt>factoreffectchart<\/tt><\/a> is my helper function.<\/p><h4>S\/N ratio<a name=\"662fa968-5828-4389-beb5-5e635181135b\"><\/a><\/h4><p>According to this chart, the S\/N ratio is very good at both the 1st level of the 4th  and 5th parameters (or variables).<\/p><p>The 4th variable is the x radius and the 5th variables is the y radius.<\/p><pre class=\"codeinput\">d = orthogonalarray(<span class=\"string\">'L18'<\/span>);\r\nOsn = factoreffectchart(d,results.sn) <span class=\"comment\">% S\/N<\/span>\r\n<\/pre><pre class=\"codeoutput\">Osn =\r\n       86.873       82.546          NaN\r\n       84.781       80.741       88.608\r\n        75.07       90.698       88.362\r\n       107.35       84.679       62.103\r\n       102.29       83.019       68.818\r\n        81.69       78.818       93.621\r\n       85.258        91.02       77.851\r\n       80.213       83.509       90.407\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/loren\/2017\/optimizingDesignStructure_03.png\" alt=\"\"> <h4>Output<a name=\"8dc573cc-68b9-4771-8af9-290b4af6e52a\"><\/a><\/h4><p>To minimize the strain, the 1st level of the 1st variable is good.<\/p><p>The 1st variable is material.<\/p><p>We succeed at reducing the parameters from 7 variables to 4.<\/p><pre class=\"codeinput\">O = factoreffectchart(d,results.output) <span class=\"comment\">% Output<\/span>\r\n<\/pre><pre class=\"codeoutput\">O =\r\n      0.36726       1.1035          NaN\r\n      0.81783      0.72215      0.66618\r\n      0.86336      0.67327      0.66952\r\n      0.64534      0.71116      0.84967\r\n      0.66149      0.67315      0.87153\r\n      0.71387      0.82003      0.67226\r\n      0.68465      0.80391       0.7176\r\n      0.81182      0.71343       0.6809\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/loren\/2017\/optimizingDesignStructure_04.png\" alt=\"\"> <h4>Optimization using patternsearch solver<a name=\"9b6e3f0b-cec9-4b1b-ad7a-42293405bb51\"><\/a><\/h4><p>We will optimize 4 parameters using the <a href=\"https:\/\/mathworks.com\/help\/gads\/patternsearch.html\"><tt>patternsearch<\/tt><\/a> solver.<\/p><p>First of all, we are going to optimize the location of the hole that minimizes strain.<\/p><p>The objective function is the code from 192 to 197 lines in \"pdesample.m\".<\/p><pre class=\"codeinput\">dbtype <span class=\"string\">pdesample<\/span> <span class=\"string\">193:197<\/span>\r\n\r\nclose <span class=\"string\">all<\/span>\r\n<\/pre><pre class=\"codeoutput\">\r\n193   function out = myobjfun(in)\r\n194   \r\n195   out = pdesample_input([1 in(1) in(2) 0.5 0.2 in(3) in(4)]);\r\n196   \r\n197   end\r\n<\/pre><pre class=\"codeinput\">opt = optimoptions(<span class=\"string\">'patternsearch'<\/span>);\r\nopt.MeshTolerance = 0.001;\r\nopt.FunctionTolerance = 0.00001;\r\nopt.MaxIterations = 500;\r\nopt.TimeLimit = 10*60;\r\nopt.UseParallel = true;\r\nopt.Display = <span class=\"string\">'iter'<\/span>;\r\n[x,obj] = patternsearch(lh{3}, [7,3,0.2,0],[],[],[],[],[2.0,0.3,0.1,-pi\/4],[9.5,4.5,0.3,pi\/4],lh{5},opt)\r\n<\/pre><pre class=\"codeoutput\">\r\n                                      Max\r\n  Iter   Func-count       f(x)      Constraint   MeshSize      Method\r\n    0         1     0.338279            0            1    \r\n    1         6      0.33769            0     0.009772   Update multipliers\r\n    2       329     0.334631            0     0.000955   Update multipliers\r\nOptimization terminated: mesh size less than options.MeshTolerance\r\n and constraint violation is less than options.ConstraintTolerance.\r\nx =\r\n       9.3125       2.9688      0.14141         0.25\r\nobj =\r\n      0.33463\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/loren\/2017\/optimizingDesignStructure_05.png\" alt=\"\"> <h4>Optimization using ga solver<a name=\"37e24da4-71ed-4b90-b3c3-de3ae408cb10\"><\/a><\/h4><p>We will also optimize 4 parameters using the <tt>ga<\/tt>&gt; solver.<\/p><pre class=\"codeinput\">gaoptions = gaoptimset(@ga);\r\ngaoptions.CrossoverFcn = @crossoverintermediate;\r\ngaoptions.MutationFcn = @mutationadaptfeasible;\r\ngaoptions.CrossoverFraction = 0.5;\r\ngaoptions.TolFun = 0.00001;\r\ngaoptions.PopulationSize = 20; <span class=\"comment\">% population size<\/span>\r\n\r\ngaoptions.InitialPopulation = [7,3,0.2,0]; <span class=\"comment\">% initial population<\/span>\r\ngaoptions.Generations = 500; <span class=\"comment\">%<\/span>\r\ngaoptions.TimeLimit = 10*60;\r\ngaoptions.UseParallel = true;\r\ngaoptions.Display = <span class=\"string\">'iter'<\/span>;\r\n\r\n[x,fval]  = ga(lh{3},4,[],[],[],[],[2.0,0.3,0.1,-pi\/4],[9.5,4.5,0.3,pi\/4],lh{5},gaoptions)\r\n<\/pre><pre class=\"codeoutput\">\r\n                              Best       Max        Stall\r\nGeneration  Func-count        f(x)     Constraint  Generations\r\n    1           1078       0.33505            0      0\r\n    2           1598      0.334569    0.0008296      0\r\nOptimization terminated: average change in the fitness value less than options.FunctionTolerance\r\n and constraint violation is less than options.ConstraintTolerance.\r\nx =\r\n       9.3345       3.1148      0.19511      0.36912\r\nfval =\r\n      0.33457\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/loren\/2017\/optimizingDesignStructure_06.png\" alt=\"\"> <p>The values of the output by both the <tt>patternsearch<\/tt> and <tt>ga<\/tt> solvers are reduced from the inital conditions. Both results give especially similiar results for the x,y positions. We conclude that both results are good. However, the area of hole is the smallest possible because of considering the S\/N ratio. In order to lighten the weight, we will enlarge the area of hole.<\/p><h4>Multi-objective optimization using the gamultiobj solver<a name=\"dfdcafec-0fe7-473b-b232-de4cb088ea5d\"><\/a><\/h4><p>We would like to optimize both the size and location of the hole in order to minmize the strain and lighten the weight.<\/p><p>In the previous case, radius x and y are the minimum values. In order to increase the size of the hole, we will use a multi-objective optimization <a href=\"https:\/\/mathworks.com\/help\/gads\/gamultiobj.html\"> <tt>gamultiobj<\/tt><\/a> solver.<\/p><p>The relationship between the value of strain and the area of hole is inverse proportional and there is a trade-off.<\/p><p>The objective function is the code from 200 to 205 lines in \"pdesample.m\".<\/p><pre class=\"codeinput\">dbtype <span class=\"string\">pdesample<\/span> <span class=\"string\">200:205<\/span>\r\n<\/pre><pre class=\"codeoutput\">\r\n200   function out = myobjfun2(in)\r\n201   \r\n202   out(1) = pdesample_input([1 in 0.2 0*pi\/12]);\r\n203   out(2) = -pi*in(3)*in(4);\r\n204   \r\n205   end\r\n<\/pre><pre class=\"codeinput\">mulgaoptions = gaoptimset(@gamultiobj);\r\nmulgaoptions.CrossoverFraction = 0.5;\r\nmulgaoptions.TolFun = 0.001;\r\nmulgaoptions.PopulationSize = 100;\r\nmulgaoptions.Generations = 3000;\r\nmulgaoptions.InitialPopulation = [7 2.5 0.5 0.5];\r\nmulgaoptions.UseParallel = false;\r\nmulgaoptions.TimeLimit = 20*60;\r\n[x,fval,exitflag,output]  = gamultiobj(lh{4},4,[1 0 1 0;0 1 0 1;-1 0 1 0; 0 -1 0 1],[9.9;4.9;-0.2;-0.2],[],[],[2.0,0.3,0.2,0.2],[9.6,4.5,3,2.6],mulgaoptions);\r\n<\/pre><pre class=\"codeoutput\">Optimization terminated: time limit exceeded.\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/loren\/2017\/optimizingDesignStructure_07.png\" alt=\"\"> <p>Here is the biggest hole.<\/p><pre class=\"codeinput\">lh{4}(x(1,:))\r\n<\/pre><pre class=\"codeoutput\">ans =\r\n      0.33632     -0.62854\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/loren\/2017\/optimizingDesignStructure_08.png\" alt=\"\"> <p>In this next plot, we show the pareto frontier which is popular for design engineering. There you can see the trade-off between area and strain for making design decisions.<\/p><pre class=\"codeinput\">scatter(fval(:,1),50.4 + fval(:,2),<span class=\"string\">'m'<\/span>)\r\nset(gca,<span class=\"string\">'FontSize'<\/span>,16,<span class=\"string\">'FontName'<\/span>,<span class=\"string\">'Meiryo UI'<\/span>)\r\nxlabel(<span class=\"string\">'strain'<\/span>);ylabel(<span class=\"string\">'area'<\/span>);title(<span class=\"string\">'pareto frontier'<\/span>)\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/loren\/2017\/optimizingDesignStructure_09.png\" alt=\"\"> <p>Pareto frontier results.<\/p><pre class=\"codeinput\">T1 = array2table([fval(:,1) 50.4+fval(:,2) x],<span class=\"string\">'VariableNames'<\/span>,{<span class=\"string\">'Strain'<\/span>,<span class=\"string\">'Area'<\/span>,<span class=\"string\">'x'<\/span>,<span class=\"string\">'y'<\/span>,<span class=\"string\">'rx'<\/span>,<span class=\"string\">'ry'<\/span>})\r\n<\/pre><pre class=\"codeoutput\">T1 =\r\n  35&times;6 table\r\n    Strain      Area       x          y         rx         ry   \r\n    _______    ______    ______    _______    _______    _______\r\n    0.33632    49.771    8.4674    0.83566    0.54447    0.36746\r\n     2.9137    29.829    6.1874     2.4294     2.9804      2.197\r\n     0.8458    36.385    6.1587     2.0938     2.7957     1.5957\r\n     3.9636    29.123    6.1812      2.593     2.9923     2.2634\r\n      1.553    32.151     5.883     2.3126     2.9526     1.9674\r\n    0.83451    37.023    6.7695     2.1714     2.4951     1.7065\r\n    0.42155    44.452     7.107     2.1224     1.3364     1.4167\r\n     1.2357    33.732    6.0206     2.5458      2.879     1.8429\r\n    0.93663    35.477    6.1315     2.3105     2.9743     1.5971\r\n    0.75125    37.875    6.7413     2.0409     2.5471     1.5653\r\n     1.0758     34.69     6.385     2.4479     2.8222     1.7719\r\n      3.077    29.714    6.1778     2.4877     2.9777     2.2113\r\n     2.8688    29.875     6.022     2.4611     2.9817     2.1911\r\n    0.39498    45.353    7.3136     1.8261     1.4593     1.1008\r\n     1.1526    34.152    6.2626     2.1237     2.9141     1.7747\r\n    0.35257     47.25    8.2497     1.2095     1.0588    0.94702\r\n     3.4396    29.299    6.3585     2.4648          3     2.2389\r\n     1.4782    32.434    6.1279     2.4721     2.9814     1.9181\r\n     2.1484    30.683    5.9299     2.4064     2.9995     2.0924\r\n    0.50403    41.862    7.0168     2.0862     1.8298     1.4853\r\n     2.3041    30.529    5.9573     2.4324     2.9834     2.1201\r\n     1.6972    31.718    5.9601     2.4295     2.9809      1.995\r\n     3.2141    29.467    6.1923     2.4677          3      2.221\r\n    0.34045    48.795    8.1318     1.0284     0.8714    0.58627\r\n     1.0626    35.115    6.6304     2.3413     2.6315     1.8489\r\n     1.3309    33.168     6.023     2.5945     2.9801     1.8405\r\n    0.38738    45.534    7.4165     1.5702     1.5472     1.0012\r\n     1.4303    32.719    5.9897      2.279     2.8842     1.9514\r\n    0.55291    40.816    5.8008     1.8469      2.672     1.1418\r\n     1.8278    31.425    5.9551      2.491     2.9899     2.0201\r\n     0.3506    48.091    8.7273     1.5772    0.62704      1.172\r\n     1.9699     31.13    6.0712     2.4664       2.98     2.0583\r\n     3.7843    29.133    6.0624     2.4919     2.9961     2.2595\r\n     2.7137    30.065     6.191     2.4831     2.9761     2.1749\r\n     3.6181    29.252    5.7451     2.5008     2.9962     2.2467\r\n<\/pre><h4>Conclusion<a name=\"b981f84e-7ab1-4424-bc06-6676e50716f1\"><\/a><\/h4><p>We showed how to use FEM tools and Optimization Toolbox to perform structural design. What can you shape with these tools? Let us know your thoughts <a href=\"https:\/\/blogs.mathworks.com\/loren\/?p=2254#respond\">here<\/a>.<\/p><script language=\"JavaScript\"> <!-- \r\n    function grabCode_5bb03cb890fc45a3a8711b2a7ff7cb74() {\r\n        \/\/ Remember the title so we can use it in the new page\r\n        title = document.title;\r\n\r\n        \/\/ Break up these strings so that their presence\r\n        \/\/ in the Javascript doesn't mess up the search for\r\n        \/\/ the MATLAB code.\r\n        t1='5bb03cb890fc45a3a8711b2a7ff7cb74 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 5bb03cb890fc45a3a8711b2a7ff7cb74';\r\n    \r\n        b=document.getElementsByTagName('body')[0];\r\n        i1=b.innerHTML.indexOf(t1)+t1.length;\r\n        i2=b.innerHTML.indexOf(t2);\r\n \r\n        code_string = b.innerHTML.substring(i1, i2);\r\n        code_string = code_string.replace(\/REPLACE_WITH_DASH_DASH\/g,'--');\r\n\r\n        \/\/ Use \/x3C\/g instead of the less-than character to avoid errors \r\n        \/\/ in the XML parser.\r\n        \/\/ Use '\\x26#60;' instead of '<' so that the XML parser\r\n        \/\/ doesn't go ahead and substitute the less-than character. \r\n        code_string = code_string.replace(\/\\x3C\/g, '\\x26#60;');\r\n\r\n        copyright = 'Copyright 2017 The MathWorks, Inc.';\r\n\r\n        w = window.open();\r\n        d = w.document;\r\n        d.write('<pre>\\n');\r\n        d.write(code_string);\r\n\r\n        \/\/ Add copyright line at the bottom if specified.\r\n        if (copyright.length > 0) {\r\n            d.writeln('');\r\n            d.writeln('%%');\r\n            if (copyright.length > 0) {\r\n                d.writeln('% _' + copyright + '_');\r\n            }\r\n        }\r\n\r\n        d.write('<\/pre>\\n');\r\n\r\n        d.title = title + ' (MATLAB code)';\r\n        d.close();\r\n    }   \r\n     --> <\/script><p style=\"text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray\"><br><a href=\"javascript:grabCode_5bb03cb890fc45a3a8711b2a7ff7cb74()\"><span style=\"font-size: x-small;        font-style: italic;\">Get \r\n      the MATLAB code <noscript>(requires JavaScript)<\/noscript><\/span><\/a><br><br>\r\n      Published with MATLAB&reg; R2017a<br><\/p><\/div><!--\r\n5bb03cb890fc45a3a8711b2a7ff7cb74 ##### SOURCE BEGIN #####\r\n%% Optimizating a Structural Design\r\n% Today you'll see a new demonstration of applying optimization techniques.\r\n% Today's guest is\r\n% <https:\/\/jp.mathworks.com\/matlabcentral\/profile\/authors\/1892029-takafumi\/\r\n% Takafumi Ohbiraki>. This demonstration was part of the contents of the\r\n% MATLAB EXPO which was held in Tokyo last year (2016).\r\n%\r\n%%\r\n% Optimization is a universal topic in both engineering and data science.\r\n% It is a technology with high needs. Speaking of optimization in\r\n% engineering, parameter estimation is often performed on a model showing a\r\n% physical phenomenon.\r\n% \r\n% Generally, when expressing a physical phenomenon by a model, MATLAB has\r\n% functions of ordinary differential equations and partial differential\r\n% equations,and performs simulation. For example, since the problem of heat\r\n% conduction can be represented by parabolic partial differential equations\r\n% on the second floor, it is possible to simulate with the function \r\n%|<https:\/\/www.mathworks.com\/help\/matlab\/ref\/pdepe.html pdepe>|.\r\n%\r\n% In reality, it is often difficult to convert a physical phenomenon into a\r\n% closed-form mathematical formula. So it is common to utilize a modeling\r\n% tool to convert the problem into a mathematical model for analysis.\r\n% \r\n% At this time, we will introduce how to optimize the design by using\r\n% <https:\/\/www.mathworks.com\/products\/pde.html Partial Differential\r\n% Equation Toolbox> and\r\n% <https:\/\/www.mathworks.com\/products\/optimization.html Optimization\r\n% Toolbox> with an example of structural analysis.\r\n%\r\n%% Design of an umbrella hook\r\n% A cool umbrella hook is always seen in Japanese public restrooms.\r\n% \r\n% <<hook.png>>\r\n% \r\n% As a designer of an umbrella hook, we will consider how to reduce the\r\n% cost by reducing the materials used for an umbrella hook. However, in\r\n% order to keep the functionality of the umbrella hook, it is necessary to\r\n% for the hook not to bend.\r\n% \r\n% \r\n% First, we define the design specifications. We consider opening an\r\n% elliptical cavity in the member. The material (A or B) of the member, the\r\n% coordinates (X, Y) of the ellipse, the radius of the ellipse (RX, RY),\r\n% and the rotation angle of the ellipse (theta) are design parameters. The\r\n% number of parameters is seven.\r\n% \r\n% We will set the downward load on the tightening portion at the upper\r\n% right and the fixed end at the left end. We perform an optimization\r\n% with the aim of minimizing the displacement amount of the lower right\r\n% point.\r\n%\r\n%\r\n% <<hook_image.png>>\r\n% \r\n%\r\n% All parameters have the following constraints.\r\n%\r\n%\r\n% <<parameter.png>>\r\n%\r\n%% FEM model (Using  Partial Differential Equation (PDE) Toolbox)\r\n% We create a function\r\n% |<https:\/\/blogs.mathworks.com\/images\/loren\/2017\/pdesample.m pdesample>| to\r\n% actually simulate with parameters using Partial Differential Equation\r\n% Toolbox (PDE Toolbox).\r\n%\r\n% input: [material x-position y-position x-radius y-radius stick theta]\r\n% output : strain\r\n% \r\n\r\nin = [1 5,2,1.5,1.0,0.3,0];\r\nlh = pdesample\r\nout = lh{1}(in)\r\n\r\n%% \r\n% \r\n% This is the initial condition.\r\n%\r\n% Output is about 0.4013. We do not understand whether this result is good\r\n% or bad. We will seek a good answer using optimization techniques.\r\n%% Process of Optimization\r\n% To actually perform the optimization calculation, if there are too many\r\n% parameters, it takes time to reach the optimum value. This time, we will\r\n% utilize a two-step optimization method that is often used in quality\r\n% engineering. According to the two-step design method, first, make efforts\r\n% to reduce the number of variables to be optimized by utilizing the\r\n% experimental design method. In this method, we adopt the Taguchi design.\r\n% The orthogonal table is uploaded to the\r\n% <http:\/\/jp.mathworks.com\/matlabcentral\/fileexchange\/60769-orthogonalarrayREPLACE_WITH_DASH_DASHl-name-varargin-\r\n% File Exchange>. In variable selection, we paid attention to the signal to\r\n% noise ratio (S\/N) ratio and the nominal-is-best response. In the second\r\n% step, we use optimization algorithms to find good parameters.\r\n%\r\n% <<optworkflow.png>>\r\n%\r\n%% Design of Experiments (DOE) (Taguchi design)\r\n% We will exploit which parameters should be reduced by utilizing the\r\n% orthogonal array famous from the\r\n% <https:\/\/en.wikipedia.org\/wiki\/Taguchi_methods Taguchi design>. In the\r\n% orthogonal array of Taguchi design, there are 2 factors, 3 factors, and\r\n% mixed orthogonal tables. We chose the famous L18 model for mixing both 2\r\n% factors and 3 factors.\r\n%\r\n% L18 model : 18 experiments to make the combination of 8 variables\r\n% efficient; one variable (material) is 2 levels , seven variables are 3\r\n% levels. The variable |design| created by my helper function\r\n% <http:\/\/jp.mathworks.com\/matlabcentral\/fileexchange\/60769-orthogonalarrayREPLACE_WITH_DASH_DASHl-name-varargin-\r\n% |orthogonalarray|> is a MATLAB table.\r\n\r\ndesign = orthogonalarray('L18','Bounds',[1 2;2.0 8.0;1.0 3.0;0.5 1.9;0.2 0.9;0.1 0.3;-pi\/12 pi\/12;0 0],...\r\n    'VariableNames',{'material','x','y','rx','ry','dh','theta','xxx'})\r\n%% Calculation with setting parameters for L18\r\n% At experimental points, we calculate the outputs (strain) and S\/N ratios.\r\noutput = zeros(18,1);\r\nsn = zeros(18,1);\r\n\r\nfor i = 1:18\r\n    output(i,1) = lh{1}(table2array(design(i,1:8)));\r\n    sn(i,1) = lh{2}(table2array(design(i,1:8))); \r\nend\r\n\r\nresults = [design table(output,sn)]\r\n    \r\n%% Factor Effect Chart\r\n% The factor effect diagram is a graph expressing the effect of each\r\n% factor, with the horizontal axis representing the level of the factor and\r\n% the vertical axis representing the S \/ N ratio and the characteristic\r\n% value. From this graph, find the condition with high S \/ N ratio and\r\n% select the one with better characteristics.\r\n% \r\n% <https:\/\/blogs.mathworks.com\/images\/loren\/2017\/factoreffectchart.m\r\n% |factoreffectchart|> is my helper function.\r\n%% S\/N ratio\r\n% According to this chart, the S\/N ratio is very good at both the\r\n% 1st level of the 4th  and 5th parameters (or variables).\r\n% \r\n% The 4th variable is the x radius and the 5th variables is the y radius.\r\n\r\nd = orthogonalarray('L18');\r\nOsn = factoreffectchart(d,results.sn) % S\/N\r\n%% Output\r\n% To minimize the strain, the 1st level of the 1st variable is good.\r\n% \r\n% The 1st variable is material.\r\n% \r\n% We succeed at reducing the parameters from 7 variables to 4.\r\n\r\nO = factoreffectchart(d,results.output) % Output\r\n%% Optimization using patternsearch solver\r\n% We will optimize 4 parameters using the\r\n% <https:\/\/mathworks.com\/help\/gads\/patternsearch.html |patternsearch|>\r\n% solver.\r\n% \r\n% First of all, we are going to optimize the location of the hole that\r\n% minimizes strain.\r\n%\r\n% The objective function is the code from 192 to 197 lines in\r\n% \"pdesample.m\".\r\ndbtype pdesample 193:197\r\n\r\nclose all\r\n%% \r\nopt = optimoptions('patternsearch');\r\nopt.MeshTolerance = 0.001;\r\nopt.FunctionTolerance = 0.00001;\r\nopt.MaxIterations = 500;\r\nopt.TimeLimit = 10*60;\r\nopt.UseParallel = true;\r\nopt.Display = 'iter';\r\n[x,obj] = patternsearch(lh{3}, [7,3,0.2,0],[],[],[],[],[2.0,0.3,0.1,-pi\/4],[9.5,4.5,0.3,pi\/4],lh{5},opt)\r\n\r\n%% Optimization using ga solver\r\n% We will also optimize 4 parameters using the |ga|> solver.\r\n\r\ngaoptions = gaoptimset(@ga);\r\ngaoptions.CrossoverFcn = @crossoverintermediate;\r\ngaoptions.MutationFcn = @mutationadaptfeasible;\r\ngaoptions.CrossoverFraction = 0.5;\r\ngaoptions.TolFun = 0.00001;\r\ngaoptions.PopulationSize = 20; % population size\r\n\r\ngaoptions.InitialPopulation = [7,3,0.2,0]; % initial population\r\ngaoptions.Generations = 500; %\r\ngaoptions.TimeLimit = 10*60; \r\ngaoptions.UseParallel = true;\r\ngaoptions.Display = 'iter';\r\n\r\n[x,fval]  = ga(lh{3},4,[],[],[],[],[2.0,0.3,0.1,-pi\/4],[9.5,4.5,0.3,pi\/4],lh{5},gaoptions)\r\n\r\n%%\r\n% The values of the output by both the |patternsearch| and |ga| solvers are\r\n% reduced from the inital conditions. Both results give especially similiar\r\n% results for the x,y positions. We conclude that both results are good.\r\n% However, the area of hole is the smallest possible because of considering\r\n% the S\/N ratio. In order to lighten the weight, we will enlarge the area\r\n% of hole.\r\n%% Multi-objective optimization using the gamultiobj solver\r\n% We would like to optimize both the size and location of the hole in order\r\n% to minmize the strain and lighten the weight.\r\n% \r\n% In the previous case, radius x and y are the minimum values. In order to\r\n% increase the size of the hole, we will use a multi-objective optimization\r\n% <https:\/\/mathworks.com\/help\/gads\/gamultiobj.html  |gamultiobj|> solver.\r\n% \r\n% The relationship between the value of strain and the area of hole is\r\n% inverse proportional and there is a trade-off.\r\n%\r\n% The objective function is the code from 200 to 205 lines in\r\n% \"pdesample.m\".\r\ndbtype pdesample 200:205\r\n%% \r\nmulgaoptions = gaoptimset(@gamultiobj);\r\nmulgaoptions.CrossoverFraction = 0.5;\r\nmulgaoptions.TolFun = 0.001;\r\nmulgaoptions.PopulationSize = 100;\r\nmulgaoptions.Generations = 3000;\r\nmulgaoptions.InitialPopulation = [7 2.5 0.5 0.5];\r\nmulgaoptions.UseParallel = false;\r\nmulgaoptions.TimeLimit = 20*60;\r\n[x,fval,exitflag,output]  = gamultiobj(lh{4},4,[1 0 1 0;0 1 0 1;-1 0 1 0; 0 -1 0 1],[9.9;4.9;-0.2;-0.2],[],[],[2.0,0.3,0.2,0.2],[9.6,4.5,3,2.6],mulgaoptions);\r\n%% \r\n% Here is the biggest hole.\r\n\r\nlh{4}(x(1,:))\r\n\r\n%% \r\n% In this next plot, we show the pareto frontier which is popular for\r\n% design engineering. There you can see the trade-off between area and\r\n% strain for making design decisions.\r\n\r\nscatter(fval(:,1),50.4 + fval(:,2),'m')\r\nset(gca,'FontSize',16,'FontName','Meiryo UI')\r\nxlabel('strain');ylabel('area');title('pareto frontier')\r\n%% \r\n% Pareto frontier results.\r\n\r\nT1 = array2table([fval(:,1) 50.4+fval(:,2) x],'VariableNames',{'Strain','Area','x','y','rx','ry'})\r\n\r\n%% Conclusion\r\n% We showed how to use FEM tools and Optimization Toolbox to perform\r\n% structural design. What can you shape with these tools? Let us know your\r\n% thoughts <https:\/\/blogs.mathworks.com\/loren\/?p=2254#respond here>.\r\n\r\n\r\n\r\n##### SOURCE END ##### 5bb03cb890fc45a3a8711b2a7ff7cb74\r\n-->","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"https:\/\/blogs.mathworks.com\/images\/loren\/2017\/optimizingDesignStructure_09.png\" onError=\"this.style.display ='none';\" \/><\/div><!--introduction--><p>Today you'll see a new demonstration of applying optimization techniques. Today's guest is <a href=\"https:\/\/jp.mathworks.com\/matlabcentral\/profile\/authors\/1892029-takafumi\/\">Takafumi Ohbiraki<\/a>. This demonstration was part of the contents of the MATLAB EXPO which was held in Tokyo last year (2016).... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/loren\/2017\/04\/10\/optimizing-a-structural-design\/\">read more >><\/a><\/p>","protected":false},"author":39,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[33,60,34,68],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/posts\/2254"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/users\/39"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/comments?post=2254"}],"version-history":[{"count":7,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/posts\/2254\/revisions"}],"predecessor-version":[{"id":2310,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/posts\/2254\/revisions\/2310"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/media?parent=2254"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/categories?post=2254"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/tags?post=2254"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}