Truss Optimization in Matlab: Part 1 Calculating the Cost of an Arbitrary Truss Instance

Total Page:16

File Type:pdf, Size:1020Kb

Truss Optimization in Matlab: Part 1 Calculating the Cost of an Arbitrary Truss Instance

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 We will define connectivity these and enter them initially by define joint hand. locations

We will create a Calculate distance program distances to calculated member lengths

We will modify your previous truss Calculate program to calculate forces forces.

Loop through each bar We will create a cost program that does all Tension or this. compression?

Size for Size for compression 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 x3,y3 Row 2 x2,y2 Row 3 x3,y3 Row …,… 2 Row N xN,yN x2,y2

1 To do this in matlab begin typing what is below into a matlab editor x1= y1= x1,y1 x2= … pos=[x1,y1,x2…,xn,yn}

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 % this function calculates the distances %between all members in your truss. You must calculate the distances between each %You must pass it the x-y positions joint as well. To do this, we will use the %in 'pos' in the format distance formula. The command for square root % [x1,y1;x2,y2;c3,y3; ... ] is sqrt. We will define these and assign them to %You must also pass it the connectivity variables in the following manner: %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 nmem=length(con); save as and name the file distance. We will for i=1: nmem define a function that calculates the distance x1 = xy(con(i,1),1); between all the members of your truss. x2 = xy(con(i,2),1); y1 = xy(con(i,1),2); Use the (somewhat sneaky) mat lab commands y2 = xy(con(i,2),2); to the right. Test your code by typing memlength(i)=sqrt((x1-x2)^2+(y1-y2)^2); end memlengths=distance(pos,con) end at the command line. How does the code work? Calculating the Forces For this section we will modify your previous program. To keep things simple the new program will NOT use the function [forces] = arbtruss1(xy, ft) results of the distance function we just created. We will %------pass it the xy positions, xy and the tension, ft, and it will %positions return the forces in all members, forces, as before. x1 = y1 = x2 = Open your previous truss program and edit the first line as y2 = shown in the box at right. You, however, must enter the x3 = definitions of x1,y1 …, xt, yt, by using the variable xy. y3 = Look back to how we defined our points on the previous xt = page and think xy(row, col). 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.

Recommended publications