Truss Optimization in Matlab: Part 1 – Calculating the Cost of an Arbitrary Truss Instance Over the past weeks you have come up with truss designs, written equilibrium equations at each joint by hand, and solved the system using matlab (and hand calculations?). Last week you were tasked with generating a parametric model of your truss. This week you will begin to learn how to use matlab to analyze the entire truss family described by your model. You will have matlab solve for the member forces, size the members for tension or compression, and calculate the cost for multiple instances within the family you defined. After today you should be on your way to finding the optimum truss for your entire family of trusses quickly. define truss connectivity define joint locations Calculate distances Calculate forces We will define these and enter them initially by hand. We will create a distance program to calculated member lengths We will modify your previous truss program to calculate forces. Loop through each bar We will create a cost program that does all this. Tension or compression? Size for compression Size for tension Calculate cost Add to running cost total End Report Setting Up Your Points x4,y4 You must define the locations of all N points in a 2xN matrix that has the structure Row 1 x1,y1 Row 2 x2,y2 Row 3 x3,y3 Row …,… Row N xN,yN To do this in matlab begin typing what is below into a matlab editor x1= y1= x2= … pos=[x1,y1,x2…,xn,yn} x3,y3 2 x2,y2 1 x1,y1 You must also define the connectivity of your truss. This takes the form of a 2 x (number of members) matrix that show which joints are connected to each other. Begin by typing what is below into a matlab editor con = [p1A,p1B;p2A,p2B; …;pNA,pNB] where p1A,p1B are the numbers of the pins at the ends of member 1. Copy the results into the command window (or run them from the editor) and check your results. Save your program as truss_setup. Calculating the Distances You must calculate the distances between each joint as well. To do this, we will use the distance formula. The command for square root is sqrt. We will define these and assign them to variables in the following manner: % this function calculates the distances %between all members in your truss. %You must pass it the x-y positions %in 'pos' in the format % [x1,y1;x2,y2;c3,y3; ... ] %You must also pass it the connectivity %of the truss in 'con' % [mem1-pt1, mem1-pt2; mem2-p1, mem2-pt2;...] d12 = sqrt((x1-x2)^2+(y1-y2)^2) function [memlength] = distance(xy,con) In matlab, open a new file in the editor. Use save as and name the file distance. We will define a function that calculates the distance between all the members of your truss. Use the (somewhat sneaky) mat lab commands to the right. Test your code by typing memlengths=distance(pos,con) at the command line. How does the code work? nmem=length(con); for i=1: x1 = x2 = y1 = y2 = nmem xy(con(i,1),1); xy(con(i,2),1); xy(con(i,1),2); xy(con(i,2),2); memlength(i)=sqrt((x1-x2)^2+(y1-y2)^2); end end Calculating the Forces For this section we will modify your previous program. To keep things simple the new program will NOT use the results of the distance function we just created. We will pass it the xy positions, xy and the tension, ft, and it will return the forces in all members, forces, as before. Open your previous truss program and edit the first line as shown in the box at right. You, however, must enter the definitions of x1,y1 …, xt, yt, by using the variable xy. Look back to how we defined our points on the previous page and think xy(row, col). function [forces] = arbtruss1(xy, ft) %------------------------------%positions x1 = y1 = x2 = y2 = x3 = y3 = xt = yt = Use Save As to give your file the same name as the new function, arbtruss1. Test your new program by typing the line below at the command prompt. forces=arbtruss1(pos,1) If your program is working you are almost done. NOTE: The distances and trig function calculations are hard-wired into this function therefore it will only solve trusses within this family for you. A new family would require you to define new distances, new trig functions, a new A matrix and a new F matrix. Sizing the Member and Generating the Cost To size the members and find the cost of the truss we must go back to our failure analysis calculations. If the member is in tension, we find the width to prevent yielding. If the member is in compression, we find the width to prevent buckling. The cost is just the product of the width, the thickness (1/4”), the length, the density, and the cost/weight. Before beginning to write code for this section, work with your group to develop a flow chart of how the program should operate. Show this to the instructor before you beginning writing matlab code.