User:Eml4500.f08.echo.mott/Echo.HW1

This Wikiversity user page contains Finite Element Analysis lecture notes and a MATLAB tutorial as required for the HW1 report.

General Information EML4500
Professor
 * Dr. Loc Vu-Quoc

Course Website
 * http://mae.ufl.edu/~vql

EXAM Dates:
 * 09/24
 * 10/22
 * 12/03

Grade Breakdown
 * Old approach:
 * Homework: 10%
 * Exam 1:  30%
 * Exam 2:  30%
 * Exam 3:  30%
 * New approach:
 * Homework: 31%
 * Exam 1:  23%
 * Exam 2:  23%
 * Exam 3:  23%

09/10/08 - Deadline for submitting team structure.

Each team (5 or 6 students) submit a paper containing the following team info:
 * Team Name: Minimum of 4 characters and Maximum of 6 characters
 * Member names and UF ID numbers
 * Wikipedia Usernames for this class

Vision for Wikiversity
Wikiversity
 * Means of sharing educational information
 * Similar to MIT's Open Course Web

Vision
 * Wikiversity members will be able to share ideas throughout the world
 * Provides means for a team to collaborate easily without having to meet in person
 * Examples: Teams in a class, professor and students in a class

Confidentiality
 * Wikiversity name-spaces are not the same as Wikipedia articles
 * Only other members who know a person's member name can access the page
 * Link can be given for others to access the page if desired

Finite Element Notation


The following conventions should be followed for all finite element truss problems. They are intended to assist in computation.


 * Global Nodes shall be labeled with a circle around the node number.
 * Local Nodes shall be labeled with a square around the node number.
 * Elements shall be labeled with a triangle around the node number.
 * Displacement notation shall include the element number in parenthesis in the upper-right corner. The lower-right corner shall include the internal force number of the element.
 * di(e), where e is the element number in parenthesis and i is the ith degree of freedom.
 * The degrees of freedom should be numbered starting in the x-direction, then the y-direction. This should be repeated for all nodes of the element.
 * Forces shall be labeled similar to displacements.
 * fi(e)
 * Reactions shall be labeled with the axis (x,y,ỹ,etc) in the upper-right corner and the node number n in the lower-right corner.
 * Rnx

Force-Displacement Relation
The following diagrams illustrate the force-displacement relation.


 * The first diagram shows a 1D Spring Element with 1 end fixed.




 * This shows a system with both ends free.




 * This equation shows the relation of the forces, displacements, and spring constant in the system. Matrix k represents the stiffness matrix.
 * $$\begin{Bmatrix} f_1 \\ f_2 \end{Bmatrix}=

\begin{bmatrix} k & -k \\ -k & k\end{bmatrix} \begin{Bmatrix} d_1 \\ d_2 \end{Bmatrix}$$


 * Case 1 - Observer sits on node 1.
 * $$f_2=k(d_2-d_1)$$


 * Case 2 - Observer sits on node 2. (Alternatively,  by equilibrium $$f_1+f_2=0$$)
 * $$f_1=-f_2=-k(d_2-d_1)=k(d_1-d_2)$$

Method/Recipe for Solving Truss Systems
Element truss systems can be solved by following a step-by-step process.

The first step is to draw a global diagram of the system. This diagram should show any external forces acting on the truss and any connection points (pinned, fixed, etc). The global node numbers and element numbers should be labeled.


 * Shown below is a sample global diagram. Global nodes 1 and 3 are constrained to center. The load P can be any direction.


 * A global free-body diagram (FBD) should also be drawn to include the forces at the reactions. The global node numbers shall be included in the diagram.



The next step of the process is to draw an individual diagram for each truss element. The individual diagram should be drawn similar to the global diagram by labeling both the displacement and force degrees of freedom. The nodes of each element can be numbered with a new convention or by using the global node numbers. Both the local and global node numbers should be drawn in the diagram.


 * Free Body Diagram of Element 1


 * Free Body Diagram of Element 2


 * Everything should be labeled according to the convention outlined in this section.


 * After all of the element diagrams have been drawn, an element force matrix  F  can be assembled in global coordinates. The stiffness matrix  K  can be found from the properties of the truss.

The global force-displacement (FD) relationship is shown below:


 *  K   d  =  F 

The stiffness matrix  K  is non-singular (invertible) and therefore the displacement matrix  d  can be found:


 *  d  =  K -1  F 


 * Now that the displacement matrix is known, the element forces can be found.
 * Once the element forces are found, the global reactions can be solved.

Example





Global Stiffness Matrix for Example

Introduction

 * Matlab comes from Matrix Laboratory and allows its users to make complicated calculations using matrices. The information presented in this tutorial is only a brief summary of MATLAB basics. For more information please reference the Primer or consult the MATLAB User Guide.

How to Create a Matrix
The following are ways to assign data to matrices in MATLAB: i.e. entering "A = [1 1 1; 2 2 2; 3 3 3]" or entering " A = [             1 1 1             2 2 2             3 3 3 ]" into MATLAB are both proper ways to create a matrix named A where each row contains three number "1's", "2's" and "3's" respectively and each column contains the numbers 1 through 3.
 * Data is entered through an explicit list of elements

Users may also enter/change a specific data point by entering the matrix name followed by (row, column) i.e. If we wanted to modify matrix A from above so that the data in row 1 column 3 (the top right hand corner) to contain the number 4, we would enter "A(1,3) = 4;"

i.e. MATLAB function "rand(m,n)" creates a matrix size m x n, where the data is randomly generated numbers uniformly distributed between the numbers 0 and 1 MATLAB function "magic(n)" creates a matrix size n x n, where the data is a magic square(rows, columns, and diagonals have a common sum) MATLAB function "eye(n)" creates an identity matrix size of n x n
 * Data is generated by-built in MATLAB statements and functions
 * Data is loaded into a matrix using a diskfile (.m file)
 * Data is loaded into a matrix using and external data file

Operations with Matrices and Arrays
MATLAB offers the following matrix operations (operations are in parentheses):


 * (+)	Addition
 * (-)	Subtraction
 * (*)	Multiplication
 * (/)	Right Division
 * (\)	Left Division
 * (^)	Power
 * (')	Conjugate Transpose

Using "A = [1 1 1; 2 2 2; 3 3 3]" and "B = [3 3 3; 2 2 2; 1 1 1]" as arrays: A + B = [4 4 4; 4 4 4; 4 4 4] A - B = [-2 -2 -2; 0 0 0; 2 2 2] A * B = [6 6 6; 12 12 12; 18 18 18] A ^ 2 = [6 6 6; 12 12 12; 18 18 18] A' = [1 2 3; 1 2 3; 1 2 3]

Using the matrix "C = [1 2 3]" and "D = [1; 2; 3], matrix division can now be performed         A / C = [0.4286; 0.8571; 1.2857]          A \ D = [0; 1; 0]


 * Matrix operations also apply to scalars, considered by MATLAB to be 1 by 1 matrices.
 * If Matrices are not the proper dimensions, an error message is generated by MATLAB.
 * By entering a period (.) before *, ^, /, or \, the matrix operations will be performed entry-wise.

Example: A .* B = [3 3 3; 4 4 4; 3 3 3]

Common Functions
The following functions we suggested by Sigmon in the MATLAB Primer1.

eig  - used to find eigenvalues and eigenvectors chol - for Cholesky factorization svd  - this is used for singular value decomposition inv  - this will give the inverse of a specified matrix lu   - this is for LU factorization qr   - this is for QR factorization hess - this will give the hessenberg form shur - this will provide the shur decomposition rref - this will provide the reduced row echelon form of a matrix expm - this provides the matrix exponential sqrtm - this gives the square root of a matrix poly - this will give the characteristic polynomial det  - this will give the determinant of a matrix size - returns the size of a matrix norm - provides 1- norm, 2-norm, etc. to infinity cond - condition number rank - provides rank of a matrix

Saving the Workspace
A MATLAB workspace can be saved by clicking File...Save Workspace As... or by typing Ctrl+S on the keyboard
 * Saving the workspace will save all variables so that they can be used in a later session
 * The workspace can be opened by clicking File...Open or by typing Ctrl+O on the keyboard.

Expression Based Software
MATLAB interprets expressions inputted by the user. Expressions can be assigned to variables, i.e. d = 4 + 5, where d is the variable, and 4 + 5 is the expression. When assigning expressions an equals sign must be included. If the expression 4 + 5 were entered into MATLAB, it would be automatically assigned to the variable ans.

MATLAB evaluates statements by pressing Enter or Return. When entering in multiple statements, they can all be entered at the same time without having to evaluate each one individually by separating them with either a comma, or a semicolon. Placing a semicolon after a statement will signal MATLAB to evaluate the statement without showing the result in the workspace.

Variables in MATLAB are case specific, i.e. the variable GOgators would not be the same as goGATORS.

Loops
For loops can be used to evaluate a certain expression a specific number of times. For example:

y = []; for j = 1:m, y=[y, 4*j^3], end

This For loop will run the expression 4*j^3 m-times, entering the value into the matrix y.

While statements run as long as a certain statement remains true. For example:

j = 4; while 4+j > 0 j = j - 2; end

Once this statement became false, i.e. 4+j < 0, this statement would stop running.

If statements will only run if a certain condition is met, i.e. if j>2, j = 4*j. If that condition is not met then j = 4*j will not be evaluated.

Editing the Command Line
Editting a command line can be done by using the arrow keys, the delete button, or the backspace key. Using the up arrow will cycle you through the previously entered statements. Because of this functionality, you can easily bring back a statement that may not have run correctly and make any corrections needed. Also, you will be able to use the same statement to apply the same or similar expressions to multiple variables.

Colon Notation
Colon notation is a type of formatting that makes the creation of matrices simple. For example, if you want a matrix that goes from one to five, incremented by one, you could enter:

>>1:5    =[1 2 3 4 5]

Also, if you want to have a different increment or decrement you can use:

>>10:-2:0      =[10 8 6 4 2 0]

Another use of colon notation is accessing certain parts of matrices. Entering A(1,2:6) will return elements two through six in row one of matrix A. Variations on this notation can be used to access submatrices. For example A([3 4],:) will take rows three and four of matrix A.

Strings
In MATLAB a string is stored in a single row matrix with a separate column for each character in the string. Strings are entered into MATLAB by simply surrounding your string of characters with apostrophes as shown below.

>> strFirst = 'This is String 1';

So the words "This is String 1" is now stored in matrix "strFirst".

If one needs to determine the number of characters in a string, for example strFirst, simply type in the following:

>> size(strFirst)

And MATLAB should return:

ans = 1  16

You can also turn a string of characters into their corresponding ascii codes using the double command and turn a single row in a matrix to it's ascii character equivalent. The following is an example of how to convert strFirst to its ascii code and then back to a string.

Enter: >> strSec = double(strFirst)

Returns: strSec = 84  104   105   115    32   105   115    32    83   116   114   105   110   103    32    49

Enter: >> strThir = char(strSec)

Returns: strThir = This is String 1

One final note on strings, if there is ever a need for an apostrophe in a string use 2 single apostrophes at the space where it's needed.

Algorithm Efficiency
In MATLAB, one can see how quickly the software is able to compute an expression is given. This can be done easily with the following format:

tic, expression, toc

This will display a text line at the end of the result stating how much time it took for MATLAB to calculate the entire statement.

M-Files
M-Files are statements that are stored in files. They have the extension ".m". M-Files can be broken up into two main categories:

Script Files are files containing a normal sequence of MATLAB statements. These are programs that when called upon operate in the main window to completion. Script files use global variables, which means that any variables in the main window that are the same as variables in the script file will be replaced. Script files can be called upon by simply typing the name of the file and dropping the extension. For example, for filename.m, one would simply type filename on the command line to call on the program.

Function Files are used to create functions. Functions are sub-programs that operate within the main program. Function files are declared by typing the name of the function, input arguments, and output arguments on the first line of the M-File. Without typing this first line, the file would be a script file. Variables within the function file will have local scope, meaning they will not affect variables acting within the scope of the main program.

When writing function files different built in functions or commands can be used to help program more efficiently. Two such commands are nargin and nargout. nargin allows the user to control the number of arguments passed to the function. nargout allows the number of arguments passed from the function back to the main program to be specified.

All comments are denoted by using the "%" symbol.

Graphics
MATLAB has the ability to take any of the statements that you have entered into the program and plot them. The program is able to handle planar and three dimensional plots.

For planar plots, the command plot(a,b), where "a" and "b" are both vectors, will bring up a graph showing the "a" vector on the x-axis, and the "b" vector on the y-axis.

>> t=0:.001:2*pi; x=cos(3*t); y=sin(2*t); plot(x,y)



Another function of the plotting tool is the command fplot which would be used to plot ".m" files.

(in an m.file “expnormal”): function y = expnormal(x) y=exp(-x.^2);

>> fplot('expnormal',[-1.5,1.5])



MATLAB is also capable of plotting 3-dimensional graphics for 3 given functions. Using the command plot3 one could take three separate vectors and see what the three dimensional line would come out to look like. Along with plot3 are several other types of 3-dimensional plots including:

>> mesh(eye(10))
 * mesh - This function projects a mesh grid over the plot area giving depth to the z values over an x-y plot area.

>> surf(eye(10))
 * surf - This function is similar to mesh but does not project the grid over the plot area, instead using colors changes to indicate                 the z values.

As part of the graphics tool, one can add details, change the color, and the type of shading used. For example:


 * xlabel('Test') - This would assign the label "Test" to the x-axis of the graph. The same could be done for the y-axis using the command ylabel.
 * colormap(copper) - This command would give the graph a copper colored look. Other possibilities are pink, cool, gray, and bone.
 * shading faceted - This command would give the plot a more faceted look. Other types of shading include interpolated and flat.

>> colormap copper >> xx=-2:.2:2; yy=xx; [x,y]=meshgrid(-2:.2:2,-2:.2:2); z=exp(-x.^2-y.^2);surf(z)



MATLAB also has predefined 3-dimensional shapes such as cylinders and spheres which can be brought up using the commands cylinder and sphere, respectively.

Formatting Output
While all computations performed in MATLAB are done with double precision, it is possible to control the format output that is displayed. This can be done with a variety of functions. NOTE:Once the format is changed it remains until changed again.

Output formatting functions: format short  - formats the output to a fixed point with four decimal places format long   - formats the output to a fixed point with 14 decimal places format short e - formats the output to scientific notation with 4 decimal places format long e - formats the output to scientific notation with 14 decimal places format rat    - formats output to an approximation by ratio of small integers format hex    - formats the output to a hexidecimal character format bank   - formats the output to fixed dollars and cents format(+,-, ) - formats the output to either a plus, minus, or blank space.

When formatting the whole viewing window, it is possible to remove excess blank spaces. This can be done with the command format compact. The screen can be returned to the original format by typing format loose.

Sparse Matrices
MATLAB initially assumes that a matrix is sparse, or that the values in the matrix may be non-zero. If a matrix contains multiple zeros MATLAB can utilize a function to streamline it's processes, increasing efficiency.
 * MATLAB has two storage modes
 * Full
 * Sparse

Full is the default storage setting.

In Sparse storage mode a matrix is stored as a linear array of non-zero elements. It does this by using row and column indices.

To convert between Sparse and Full use the following functions: F=Sparse(F) (1) F=Full(s)  (2)

Function one converts the storage mode to sparse, while function 2 converts to Full mode.

To check which mode is currently being used. This can be done by using issparse(A) Where A is the name of the matrix.

It is possible to specify certain parts of a matrix to change into sparse storage. For example one may only wish to turn the diagonals into a sparse matrix. This can be done using spdiags. Below is a list of sparse conversions for different aspects of a matrix.

eye - speye zeros - sparse ones - spones randn - sprandn

A sparse matrix can also be created by listing the non-zero entries. This can be done by: sparse(i,j,s,m,n)

Where: i  - row index j  - column index s  - non-zero elements of sparse matrix m,n - intended size of matrix

Sparse operations Vs. Full

When using a sparse function on a full matrix the result is always in Full. This can be negated in a few ways, one being S.*F.

When using a sparse funtion on Eigen Vectors, eig(S), is full if the sparse matrix is symmetric. The Eigen vectors are however undefined if the matrix is unsymmetric.

Note: A matrix built of other matrices, or blocks, such as [E,F,G,H] is sparse if any of the matrices constituting the block are sparse.