Spring Programming Project #3 solution

$14.99

Category:

Description

Directions:

 

  1. Your m-files must be named ubitname_plot_forces.m and ubitname_force_sol.m as described in the tasks below, where ubitname is your UBITName. Your m-files must be uploaded to UBlearns before the due date & time. (Important: Do not ZIP, archive or compress any files!)

 

  1. You must write your own code and follow all instructions to get full credit. Except to test & verify your code, you are not allowed to use built-in MATLAB functions lu, mldivide (the \ operator), and inv (or similar), nor are you allowed to merely copy scripts & functions found on the Internet.

 

  1. For all functions, if a call to the function does not contain the proper number of input or output arguments (see functions nargin, nargout, narginchk, nargoutchk), then you must notify the user by throwing a suitable error message using MATLAB functions error or assert.

 

  1. Reference sections 2.11, 2.12 and 5.6 in Essentials of MATLAB Programming, 2nd Ed. by Stephen

Chapman and 2.6, 2.7 and 9.1 in Introduction to Linear Algebra, 4th Ed. by Gilbert Strang.

 

 

Problem Description

 

Consider the truss given in Figure 1. Such structures commonly occur in engineering design. In order to properly design the structure, the forces in the pins must be estimated. We will use a statics-based analysis to estimate the maximum forces in the members connecting the pins A, B, C and D.

 

 

0.5 m      1.0 m

 

B                       A

 

0.5 m

 

D

m

0.5 m

 

C

 

 

Figure 1: Truss structure

 

In a typical statics course, equations are written for the forces in each of the members and then the forces are determined individually. Here, we will use our newfound knowledge of linear algebra and MATLAB programming to make the computer do the “grunt” work for us. We do this by representing the collective statics equations for the structure as a linear  system of equations.  The unknowns of the system are the forces in the members. We will then write MATLAB functions to solve the linear system of equations.

 

To simplify the problem, we assume that the truss is not being accelerated (i.e. it is in static equilibrium). Then, according to Newton’s First Law of Motion, the sum of the forces at each of the pins must be equal to zero and the truss structure shown in Figure 1 produces the following system of equations with unknown forces:

 

 

 

−fAB −

√2

√2

fAC = 0

2

 

2

−    fAC − fm = 0

√2

 

−fBC −

 

 

fAB −

√2

2  fAC −

√2                        √2

fBD = 0

2

√2

fBD = 0

2

√2

2  fC D  = 0

 

2  fAC + fBC +

√2

2  fBD +

√2

2  fBD −

2  fC D  + fC y = 0

√2

2  fC D  + fDx = 0

√2

2  fC D  + fDy = 0

 

 

However, for this problem, we are interested only in the forces in the members, not in the wall or floor. (If you’ve taken a statics course, you may observe that C is on a frictionless roller on the floor and D is a hard-point on the wall.  If we were interested in the forces in the wall and floor, we would include all equations or we could simply add up the member forces at pins D and C, respectively, and “flip the signs” as per Newton’s Third Law of Motion.) In other words, we are not interested in the “reaction forces” fC y , fDx , and fDy at pins C and D, so we can simplify the problem further by ignoring the last three equations:

 

√2

 

−fAB −

√2

fAC = 0

2

 

2

−    fAC − fm = 0

√2

 

−fBC −

 

 

fAB −

√2

2  fAC −

fBD = 0

2

√2

fBD = 0

2

√2

2  fC D  = 0

 

 

There are five truss members, so there will be five unknown forces. We can now write the system in matrix- vector form (Ax = b), which will then allow us to leverage MATLAB to compute the unknown forces.

 

Assignment

 

In this assignment, you will use the analysis above to determine the A matrix and b vector for the structure in Figure 1. Using MATLAB, you will calculate the forces in each of the members in Figure 1 for a range of masses and plot the results. Please use SI Units!

 

 

Task 1 (20 pts)

 

In this task, you will write a MATLAB function named ubitname_plot_forces that solves for the forces in the members in Figure 1 by calling ubitname_force_sol (see Task 2) over a range of different masses, and plots the results. In this function, you will create the system’s A matrix and factor it into L, U and P using a call to the LU decomposition function that is specified in the second input argument. As such, it must accept two inputs: (1) a range of masses in a vector and (2) a function name or function handle of a function which computes L, U , and P from A. Thus, it must have a definition of the following form:

 

function [h] =  ubitname_plot_forces(m, lu_func)

 

where the following are input arguments:

 

  • m : A vector of mass values (e.g. m =  [0:50:500] kg).

 

  • lu_func : The function name or function handle of the LU decomposition function to use. This function must have the form of [L, U,  P] =  lu_func(A), which matches the call of the get_lu function you created in Programming Project #2 and the built-in MATLAB function lu.

 

The output argument is the following:

 

  • h : A figure object handle for the plot produced (see details below). Force versus mass for each member must be plotted on the same set of axes.

 

 

Notes:

 

The ubitname_plot_forces function will (1) form A, (2) compute L, U , and P  from A using the function indicated in lu_func, (3) iterate over the vector of masses, producing a new b and a solution of forces in each member for each mass and (4) produce a plot of the forces in each member as a function of mass.

 

Because the ubitname_plot_forces function takes another function as an input, it is called a “func- tion function.” As such, it must be able to accept either the get_lu function you created in Programming Project #2 or the MATLAB built-in function lu (see link below, noting that both functions have identical syntax). To create a “function function,” you may use one of two techniques: (1) use the name of the func- tion (as described in the lecture notes and section 5.6 of Essentials of MATLAB Programming, 2nd Ed. by Stephen Chapman) or (2) use a function handle described in the lecture notes and at the links below: http://www.mathworks.com/help/matlab/matlab_prog/pass-a-function-to-another-function.html http://www.mathworks.com/help/matlab/matlab_prog/creating-a-function-handle.html http://www.mathworks.com/help/matlab/ref/functions.html

http://www.mathworks.com/help/matlab/ref/lu.html

 

Lastly, your ubitname_plot_forces must plot the forces for each member on the same set of axes (i.e. the same figure), provide an appropriate title, properly label all axes, differentiate the curves (with style, marker and color) and include a legend to label the curves.  Your ubitname_plot_forces function must return a handle to the figure object. For more details about figure object handles (and other graphics object handles), see the links below:

http://www.mathworks.com/help/matlab/learn_matlab/understanding-handle-graphics-objects.html http://www.mathworks.com/help/matlab/creating_plots/access-and-modify-property-values.html http://www.mathworks.com/help/matlab/ref/figure.html

 

Task 2 (20 pts)

 

In this task, you will create a function named ubitname_force_sol that solves for the forces in each member for a single mass value.  This function will take as input L, U , P  and b, and it will return the resulting forces in a vector. Thus, it should have a function definition of the following form:

 

function [f]  =  ubitname_force_sol(L, U,   P, b)

 

where the following are input arguments:

 

  • L : The lower triangular factor of A.

 

  • U : The upper triangular factor of A.

 

  • P : The permutation matrix from the LU decomposition of A.

 

  • b : The right-hand-side (output) vector of the system. and the output argument is:
  • f : A column vector containing the force for each member, in order (e.g. [fAB, fAC, fBC , fBD , fC D ]T ).

 

 

Notes:

 

You should write ubitname_force_sol based on your get_sol function from Programming Project

#2. Of course, before calling ubitname_force_sol, the b vector must be created (based on the mass) and the LU decomposition of A (including the P matrix) must be obtained—these should be accomplished in your ubitname_plot_forces function (see Task 1, above).

 

For testing and verification purposes, you may compare the force solution obtained by ubitname_force_sol

with the results of MATLAB’s built-in “backslash” solver: A\b  or its function form mldivide(A,b).

 

 

Grading

 

Points will be deducted if the directions are not followed, such as if the required function inputs and outputs are not in the forms specified above. Points will also be deducted for any extraneous outputs to the screen (in any form). The functions that you write should be self-contained functions that do not require additional input from users or the keyboard, nor should they require any other dependencies (i.e. other m-files, tool- boxes, etc.) other than a basic installation of MATLAB itself. If m-files uploaded to UBlearns are not named as described above, they will not be graded.