User:Eml4500.f08.RAMROD.A/HW1

=Finite Element Analysis=

Finite Element Analysis, otherwise known as the Finite Element Method, is a technique used to attain solutions to Partial differential equations(ODE's) and integral equations. This method is most often used to solve ODE's over complex domains. This class will focus on learning how to use and apply this method to real world situations in which it is necessary to determine the tendencies of a system.

The goal of this course is to avoid the old ad-hoc structure of analysis and to encourage true learning and judgment of correctness.

This course will not be conducted in the usual manner. Instead of the old method of simple lecture notes and homework assignments, Wikiversity will be used to post the concepts we learn in class as well as the problems that are assigned to us for homework. At first glance this structure seems like a lot of work and as well as a hindrance to the learning experience, but if an in depth look at the new system is taken, one would emerge with a greater appreciation of what is being accomplished.

=Wikiversity and The Class=

What is Wikiversity

Wikiversity is part of the Wikimedia Foundation, which is a foundation in which provides free content to its users. It is a very large server-based software that allows its users to create articles on any topic of their choosing. The incredible aspect of this software is that anyone who has an account with any Mediawiki project can go into that article and make corrections. The ability to edit any article allows for an environment that promotes collaborative learning.

Questions may arise as to the quality of contributions made to an article found on any of the Mediawiki projects. For example, an article may be writen that doesn't contain a single factual statement. In this case, the administrators in charge of overseeing all activities within the domain will quickly eliminate the article. Another example is that of a contribution made to an article already approved by the administrators. The contribution will be reviewed and either accepted or rejected. If rejected, the last acceptable saved copy of the article gets uploaded back onto the Wiki. This brings up another advantageous aspect of the software. When an edit is made and saved to any article, a copy of that article is stored in a database and will remain there until the MediWiki software is shut down. This means that any copy of any article can be retrieved by simply going into the history of that article and searching for the needed copy. This function serves as a solution to vandalism to articles as well. It is almost always safe to assume that information posted on Mediawiki software are correct.

Advantages of Wikiversity

There are numerous advantages to using a Mediawiki software such as Wikiversity, the first of which would be learning through collaboration and teamwork. Teamwork has been proven to be one of the most effective ways of learning and deploying this method in the classroom is absolutely essential. Not only is this a collaboration of the team, but it's also a collaboration of the class because each team can view and learn from other team contribution. Taking it even a step further, this software allows there to be a collaboration between the class and the professor.

Another important advantage of using such a software is that a user will forever have the information they input into the database for future reference. This is a great aspect of the software that allows the user to go back and review the material they learned whenever they need a little reminder of concepts.

=Trusses, Beams, and Frames=

Diagram of Truss
Below is a diagram of a truss with 2 elastic, or deformable, bars. There is a known load P applied where the two bars join. The two bases of the truss are both fixed, or constrained, in both the x and y axes. There will be no displacement at these points. The goal is to find all of the unknown forces and displacements.



Global Free Body Diagram
Below is the Global (the whole structure) Free Body Diagram of the same 2-bar truss. Notice that the constraints have been replaced with reaction forces.



Currently, there are 4 unknown reaction forces (R1x, R1y, R3x, and R3y). However, there are only three equations that can be used (ΣFx=0, ΣFy=0, and ΣM=0). In other words, we have 4 unknowns but only 3 equations to solve for them, therefore this system is statically indeterminant.

Free Body Diagrams of the 2 bar elements
To continue, we will separate the two bars and look at them independently. A new local free body diagram is drawn for each bar element. Forces and the resulting displacements are again drawn and the nodes are renumbered accordingly.

Bar Element 1 Bar Element 2

Notes
 * fdegree of freedomundefined


 * fi(e) = ith eternal force of element e with:


 * i=1,2,3,4


 * e=1,2


 * for this example

There are two possible cases in this situation:


 * Case 1: The observer sits on node 1


 * In this case:


 * f2 = k(d2 -d1)


 * Case 2: The observer sits on node 2 (or equivalently f1+f2=0)


 * In this case


 * f1= -f2= -k(d2 -d1)


 * f1=k(d1 -d2)

Alternate Node Numbering Method
Below is another way to number the local nodes.



Force Displacement Relation
An elastic bar can be considered a spring with a spring constant of EI/L (E is Young's Modulus, I is the moment of inertia, and L is the length of the bar or spring). Recall the two following spring systems:


 * Below is a 1-dimensional spring with two free ends. A force f is applied and a displacement d results. The force-displacement relation is f=kd.




 * Another system is a 1-D (one dimensional) spring with 2 free ends. A force f is applied and a displacement d results. The matrix method (on the right) is used to find the force-displacement relationship. (The 2x2 matrix with the k's in it is known as the stiffness matrix).



= Notes Summary for Friday, September 5 =

Intro
We discussed the ordered steps to solve a the truss problem from September 3. We discussed a generalized format to begin with the diagram of a model system and to work our way down to computing reaction forces.

Step 1: Global Picture
The global picture is the overall structural picture of the system. The picture includes the following:
 * 1) Global Forces
 * 2) Global Degrees of Freedom (aka DOF)

The displacement definition are partitioned into:
 * 1) Known part, eq., fixed DOF, constraints
 * 2) Unknown part solved by using Finite Elemental Analysis (see the truss example above)

Similarly, the global forces are partitioned into:
 * 1) Known part: Applied forces
 * 2) Unknown part: Reactions

Step 2: Element Picture

 * 1) Element definitions
 * 2) Element forces

These can be found in either global coordinate systems or in local coordinate systems

Step 3: Global Force Diagram relationship

 * 1) Element stiffness matrices in global coordinates
 * 2) Element force matrices in global coordinates
 * 3) assembly of element stiffness matrix and element force matrix into global force displacement relation.

K · d = F

(NxN) (Nx1) = (Nx1)

Step 4: Elimination of DOF
Eliminate degrees of known degrees of freedom to reduce the global force displacement relationship. (The Stiffness Matrix is non-singular-invertible)
 * 1) M = the number of unknown DOF
 * 2) N = the number of both known and unknown DOF

K · d = F

(MxN) (Mx1) = (Mx1)                       M>N

Stiffness Matrix K nonsingular => k-1 exists (K is invertible)

K-1 · d = F

Step 5: Compute Element Forces
Compute element forces from known displacements => element stresses

Step 6: Compute Reactions
Compute reaction forces or the unknown forces.

= Matlab Summary =

Intro
Matlab is a software program, developed by Matrix Laboratories, that uses matrix-based mathematics to solve ordinarily difficult scientific and engineering applications. It has several advantages over traditional methods (i.e. Fortran or C++), specifically its ease of use, versatility of capabilities, and its ability to convey results graphically as charts and its ability to model very complex systems visually for ease in conveyance of results. Since its development, Matlab has become very widely used in nearly all scientific fields and, especially in engineering practice, has become an absolutely vital tool for all types of engineering analysis.

Matrices in Matlab
As was stated above, Matlab is a matrix-based program. Thus, all variables, whether scalars, vectors, or much more complex and larger-scale matrices are all stored in the same manner. Because of the significance of matrices in this program, the first, and most important operations to know are those involving matrices.

Creating Matrices
There are several ways in Matlab to make new matrices. One method is to enter the values directly. For example:


 * A = [2,3,4;5,3,6;9,5,2]


 * A = [2 3 4; 5 3 6; 9 5 2]

Both of these entry syntaxes would create a 3x3 rectangular matrix with the indicated values. Other permissible formats are for scientific notation, such as [2.34e-4, 3.53e8], or for complex numbers, entered as [2+4i,3+8i] or [2,3] + i*[4,8]. In both instances (exponential and complex numbers) spaces should be avoided between numbers and commas should be used. When manually entering values into a matrix, as shown in the above examples, commas (or spaces where allowed) separate entries in a row while a colon separates one row from the next.

Another option for creating matrices is to read from an input file, usually an ASCII file from another editor on your computer. This is completed by using the load command. To load input file "input.dat", the command would be load input.dat.

After creating a matrix, it can then be referenced by its name (i.e. A). Also, you can reference individual entries such as A(4,2) for the second entry in row four of matrix A.

Matrix Building Functions
In addition to creating your own matrices, Matlab has several default "special" matrices and matrix references that can be called on using their reserved names. The following are a few of the standard Matlab matrices and uses:


 * eye(m,n) will create the identity matrix of dimensions mxn.
 * zeros(m,n) will create a mxn matrix where all entries are zeros.
 * ones(m,n) will create an mxn matrix where all entries are ones.
 * diag(x) will create a matrix where the diagonal is the predefined vector x.
 * triu(x) or tril(x) references the upper or lower triangle of matrix x, respectively.
 * rand(m,n) will create an mxn matrix with Matlab randomly generating values for each entry that will be uniformly distributed between 1 and 0.
 * magic(m,n) will provide an mxn matrix that is a "magic" matrix in which each column, row, and diagonal totals to the same sum.
 * hilb(m,n) creates an nxn Hilbert Matrix.

It is useful to note also that creating a square matrix of any of the above forms is done by replacing the (m,n)dimensions by simply an (n) dimension.

Also, any of these matrices can be created to match the size of an existing matrix by using the command size(X) where X is a matrix. For example, eye(size(X)) creates an identity matrix with the same dimensions as matrix X.

All of these commands are extremely useful as starting points for building matrices. For example, A = eye(2) could then be edited (A(2,1)=5) to modify it from an identity matrix to the desired matrix without manually entering the value of each entry.

Matrix Operations
Once a matrix is created using the above stated methods, Matlab has several built in operations to manipulate it mathmatically. The following are the basic matrix operations that Matlab can perform:


 * +: addition - adds two matrices term by term to create a new matrix.
 * -: subtraction - subtracts two matrices term by term to create a new matrix.
 * *: multiplication - multiplies two matrices together
 * ^: power - raises a matrix to power indicated after ^.
 * ': conjugate transpose - returns a matrix where each term's indices are swapped (Aij goes to Aji) and all terms are replaced by their complex conjugate (a+bi goes to a-bi).
 * \: left division - A\b = b/A.
 * /: right division - normal division of two matrices.

While addition and subtraction above execute a term by term operation, the others do not. However, Matlab will allow this by placing a period before the operator. For example:

"[2,5,9,7].*[2,5,3,1] = [4,25,18,7]"

This form of multiplication, division, or exponents can be found very helpful when working with Matlab Graphics which will be described later.

Statements, expressions, and variables in Matlab
In addition to being a matrix-based software, the language of Matlab is expressions. Expressions are used for every function that Matlab is capable of. Generally, an expression can take the form of a equation or a simple statement.

Equations
Equations, such as Y = 5X+5, are generally created by stringing together variables, functions, and operators and results in a matrix that is then output to the screen and can be referenced in later functions.

Statements
If a certain variable and equals sign is not specified, 5X+5, this expression results in a newly created variable "ans" whose value is stored until a new expression is evaluated. For this case, the line ans = (value) will be output to the screen. However, if the expression is followed by a semicolon, 5X+5;, this line will not be shown. This is very convenient in long iterations where extra lines of output answers only complicate the code and calculations and are undesired.

Variables
An important thing to note here is that Matlab is case-sensitive, meaning that the variable y is not the same as the variable Y. If at any given time you wish to see a list of the current variables, the command "who" or also whos will print the list and their values to the screen. Additionally, variables can be cleared by the command clear followed by the variable name you wish to clear. The command clear by itself will clear all non-permanent variables in the cache.

Saving a Session
In order to not lose variables when you exit Matlab, it is very useful to know the save command. This will write all variables and their values to a non-accessable file named "matlab.mat". Upon entereing Matlab the next time, simply typing the load command will access the file and will bring back all variables as they were when the file was saved.

Scalar, Vector, and Matrix Functions
Matlab has many predefined functions that are very useful in doing matrix calcluations. Some are solely used for scalars matrices (1x1), some for vectors, and the most powerful are the matrix functions.

Scalar Functions
The below functions are designed to work with scalars only, but can be applied to a matrix. When the following are used in reference to a matrix, the operation is computed term by term in the matrix.

"*sin - returns sin of each entry" "*cos - returns sin of each entry" "*tan - returns sin of each entry" "*asin - returns arcsin of each entry" "*acos - returns arccos of each entry" "*atan - returns arctan of each entry" "*''exp' - returns e to the value of each entry" "*log - returns natural log of each entry" "*rem - returns remainder of each entry" "*abs - returns absolute value of each entry" "*sqrt - returns square root of each entry" "*sign - returns sign of each entry" "*round - rounds each entry to the nearest whole number" "*floor - returns lowest entry value" "*ceiling - returns highest entry value"

Vector Functions
As with scalar functions, the below commands are designed for vector matrices. The command is evaluated column by column and the output is a row matrix corresponding to the result from each evaluation. The vector functions are:

"*max(x) - returns maximum value in vector x" "*min(x) - returns minimum value in vector x" "*sort(x) - returns vector x in rearranged in numeric order" "*sum(x) - returns sum of all values in vector x" "*prod(x) - returns product of all values in vector x" "*median(x) - returns median of values in vector x" "*mean(x) - returns mean of values in vector x" "*std(x) - returns standard deviation of values in vector x" "*any(x) - applies a comparison to any value in vector x" "*all(x) - applies a comparison to all values x"

To apply these for an entire matrix rather than a single column, use them twice. For example, median(median(A)) would return the median of the row matrix which was returned by median(A).

Matrix Functions
Matrix functions are by far the most useful and powerful of Matlab's abilities. The following are the matrix functions and their description.

"*eig - eigenvalues and eigenvectors" "*chol - cholesky factorization" "*svd - singular value decomposistion" "*inv - inverse" "*lu - LU factorization" "*qu - QR factorization" "*hess - hessenberg form" "*schur - schur decomposition" "*rref - reduced row echelon form" "*expm - matrix exponential" "*sqrtm - matrix square root" "*poly - characteristic polynomial" "*det - determinant" "*size - size" "*norm - 1-norm, 2-norm, F-norm, infinite-norm" "*cond - condition number in teh 2-norm" "*rank - rank"

Logic Functions in Matlab
As in many program languages, logic functions such as for, if-and, and while loops are essential assets to understand. In most cases these are implemented very similarly to other languages. The details of each implementation is below.

For Loops
For loops are created using a for condition, an expression, and the end commmand. For example, if you wanted to make a vector y of size n (a predifined scalar) in which each element is the previous element plus one, the code would look like that below.

"y = [];" "for a = 1:n" "y[y,y(n-1)+1]" "end"

The loop will continue as long as the condition (a=1:n) is true. This condition is saying that a is incremented by one each iteration and will continue until a=n. Each time the loop is evaluated, the expression is evaluated and the value of the variable (in this case matrix y) is updated accordingly. If you wish to print the end value of the variable in question, just type the variable name after the end command.

While Loops
While loops also operate much like in other languages. They are generally stated using a while relation, a group of statements and operations, and the end command to finish the loop. These loops differ from For loops in the fact that they will execute until the relation is false, and not simply a preset number of iterations. A simple while loop, creating a matrix of the numbers one through ten, is shown below.

"x=[];" "a=0;" "while a<=10" "x=[x,n]" "end" "x"

This code would then print out the vector x = [0,1,2,3,4,5,6,7,8,9,10].

If Loops
If loops are implemented very similarly to while loops, involving a true/false relationship, a series of statements, and the end command. However, If loops allow the user to create several different branches of elseif and else loops to allow for more than two sets of operations. For example, if there is a vector with 5 entries, you could add 3 to entries 1 and 5 while subtracting 1 from entries 2 and 3 and force entry 4 to be zero using the code below.

"X=[1,1,1,1,1]" "n=1" "5''" "X(n)=X(n)+3"

"3''" "X(n)=X(n)-1"

"else" "X(n)=zero"

"end" "X"

This would then print out the new vector X = [2,0,0,0,2].

Relationship Operators
The following are the preset relationship operators that Matlab uses in the above described loops.


 * < - Less than
 * > - Greater than
 * <= - Less than or equal to
 * >= - Greater than or equal to
 * == - Equal to
 * ~= - Not equal to

Also, the three logical operators below are used to string relationships together.


 * & - and
 * | - or
 * ~ - not

It is important to so note that when an operator is used to compare two scalars, such as 4>5, the resultant answer will be a 1 or a 0, corresponding to either true or false, respectively.

However, comparing two matrices is a bit different. The comparison if A==B is true if every term in A is the same as every term in B. The any command can get around this aspect to compare matrices more generally. For instance, the command if any(any(A==B)) will be true if any element of A is the same as the corresponding term in B and is not a global matrix comparison.

Colon Notation
One very key shortcut in Matlab is what is known as colon notation. To this point, if you desired to create a vector of all even numbers between 2 and 20, you would have had to manually enter each entry. However, in actuality, the command 2:2:20performs the exact same operation. Note that the first number is the starting point, the second the increment, and the third is the ending point. If the middle number is left out, Matlab assumes is to be one.

The colon notation can also be reference certain submatrices within already created matrices. For example, X(1:2,5) references the first two rows of column five of matrix X. If you would like to reference an entire row or column in a matrix, there is a shortcut here as well. Suppose a 200x200 matrix, A, and assume you want to perform an operation to the entire 45th column of this matrix. Rather than referencing (1:200,45), you could simply use the syntax (:,45). Matlab interprets a colon by itself to mean an entire row or column. You can perform operations to specific submatrices to create the submatrix you would like to reference and you can reference more than one row or column in a specific operations. For examples, A([5,7],:) references all columns in both row 5 and row 7 of A. Likewise, the statemnt A([5,7],:) = A([5,7],:)*[1 2; 3 4] would multiply just rows 5 and 7 by the 2x2 matrix shown.

Again, this notation and utility is something unique to Matlab and is another aspect that gives it an enormous advantage over previously used softwares and languages.

Working with Files in Matlab
In Matlab, you are able to create files, much like source files in other languages, that perform a series of operations each time they are accessed. Such files are called M-files due to their file extension, .m. There are two types of M-files in Matlab and each is discussed below.

Script Files
Script files can be thought of in Matlab as sub-programs that can later be accessed for use. A script file is just series of statements that are executed until the file is complete. In order to reference a script file, say solveatriangle.m, simply type the command solveatriangle in your Matlab code and the file will be executed. One very important thing to note and to be cautious of is that variables in script files are global and any changes made to variables during execution will be applied to all variables with the same name in your matlab code. Additionally, it is possible for M-files in Matlab to reference many other M-files, and even itself, if necessary to complete the desired operation.

Function Files
Function Files are very similar to script files, with two major differences. The first, and most important, is that all variables in a function file are local unless specified to be global.

Secondly, script files are just a sequence of operations to be performed at a specified point in the code. However, function files are input/output operations, to which one or more input variables are passed and one or more outputs are retrieved. Because of this, the first line of every function file is the function name, the input arguments, and the output arguments. The following code would be an example of a simple function that takes 5x5 matrix A as an input, adds 3 to every entry in row 5 and outputs the resulting matrix and assigns it to a new 5x5 matrix B.

"Function File"

"function B = add3(A)" "B=A" "B=B(5,;)+3"

"Matlab Code"

"B = add3(A)"

At this point, Matlab would print the new matrix B.

Obviously, function files can be far more complex and, thus, much more utile than this example. However, the basic outline and format would remain the same whether it was four lines or 400.

Text Strings in Matlab
Text strings are very important tools, usually used in M-files. They serve to prompt for input and also to alert if an error has occurred. Strings can be referenced instance by instance or can be assigned to a variable and are specified by text between single quotes ('string'). If you wish to display a message, the disp(string) command will print the string identified in the. Also, the error will behave similarly. However, error will abort execution of the M-file it is a part of. The other function of strings is to prompt the user for input. To do this in an M-file, you need to use an equation, assigning the user's input to a variable as well as the input command. For example:

a = input('Please enter the length of side a: ')

This would prompt the user to "Please enter the length of side a: ". Upon entering a value and pressing enter, the input would then be assigned to variable a and the next statement in the M-file would be executed.

Managing M Files
Matlab has a neat command to allow users to manage/create new files without the need to exit Matlab or losing active data.

This tool is the ! feature.

! feature
When any command that would require the system to exit is preceded with an "!", Matlab will be returned to automatically with all current data - after whatever file management is completed.

Example: !ed Shamrock.m  will allow the user to edit the m-file named Shamrock and then return to Matlab exactly as it was.

More File Management Features
command pwd returns the present working directory name

command cd is used to change the working directory

commands dir or ls will show all contents of the current working directory

command what shows the M-files in the current directory

command delete can delete a diskfile

command type will print an M-file to the screen (PrtSC)

command path shows the current directories list

Note: M-files need to be in a directory accessible to Matlab.

Efficiency of Matlab Algorithms: Commands: Flops, Tic and Toc
Flops or Floating Point Operations are one way to measure the efficiency of your Matlab algorithm.

The total duration of time is also a good measure of the efficiency.

Flops Command
Enter flops(0) prior to algorithm and flops after and Matlab will count the number of flops registered during the algorithm sequence.

Example: flops(0), x7+ey 2 =x3; flops

Tic and Toc
Similarly, if you precede the Algorithm with Tic and follow it with Toc and Matlab will post the time elapsed during calculations.

Example: tic, x7+ey 2 =x3; toc

Output Format Precision
Matlab computations will always be done in double precision but there are commands to format what is displayed.

Display Commands
format short - fixed point with 4 decimal places

format long - fixed point with 14 decimal places

format short e - scientific notation with 4 decimal places

format long e - scientific notation with 15 decimal places

format rat - approximation by ratio of small integers

format hex - hexadecimal format

format bank - fixed dollars and cents

format + - +, -, blank

Format Commands
format compact - eliminates blank lines compressing the page

format loose - returns to the original expanded format, similar to double space

Note: format commands remain in effect until changed

Hardcopy
A hardcopy of the information on the screen can be copied to a disk file with the command diary

diary filename - writes information to screen until diary off is entered

Graphics and 3D Graphing in Matlab
The most important commands are plot, plot3, mesh, and surf. The Demo command will give a brief into to each.

Plot
creates x-y plots of the linear form. The following examples will show how to plot vectors over an interval for x.

Example: x = -10:2:10; y=sin(x); plot(x,y)

Example: x = -1.5:0.1:1.5; y=exp(x.^3); plot(x,y)

Note: A period precedes the superscript for proper entry-wise operation

Fplot
Fplot works just the same as plot command and is used for plotting functions

Graph Commands
tittle - add a graph tittle

xlabel - label the x axis

ylabel - label the y axis

gtext - place text on the graph at desired location

text - position text by coordinates

Axis Commands
axis - set axis scaling to prescribed limits

axis(axis) - freezes scaling for subsequent graphs

axis auto - returns to auto-scaling

v = axis - returns vector v showing current scaling

axis square - same scale on both axes

axis equal - same scale and tic marks on both axes

axis off - turns off axis scaling and tic marks

axis on - turns on axis scaling and tic marks

Line-types, Marks and Colors
Line-types: solid (-), dashed (--), dotted, dashdot(-.)

Mark-types: point(.), plus(+), star(*), circle(o), x-mark(x)

Colors: yellow (y), magenta (m), cyan(c), red(r), green(g), blue(b), white(w), black(k)

Example: plot(x,y,'b:') will plot a blue dotted line

Plot3
Plot3 will produce a 3-Dimensional plot of vectors: x, y and z'

The vectors will usually be defined parametrically

Example: t = 0.05:0.01:10*pi; x = cos(2t); y = sin(0.5*t); z = t.^4; plot(x,y,z)

Title and axis commands are the same as for command Plot with the z axis included.

Mesh and Surf Commands
These commands will plot 3-Dimensional "mesh" graphs of matrices. Example: z = [3,9,1] mesh(z)

Surf creates surface plots

Advanced Example
Plot the graph of z = e-x 3+y2 over the square [-4,4] x [-4.4]

xx = -4:0.4:4; yy = xx; [x,y] = meshgrid(xx,yy); z = exp(-x.^3+y.^2); mesh(z)

Sparse Matrix Computations
The computing efficiency of large matrix based problems can be increased using the Sparse command.

The Command will force Matlab to only run computation on nonzero matrix elements - significantly increasing efficiency if said matrix is dense with zeroes.

Say we have Matrix A

To find the number of nonzero elements in A use command: nnz(A) to return the number.

Now we can convert it to a sparse matrix with S = sparse(A)

F = Full(S) will bring the matrix back to full

Matlab References
Many MATLAB features were not included in the tutorial but they are listed below and organized by their subject area. There are more functions beyond the ones that are included below but these can be located by using the help command. Here are some easy reference charts that will help during the use of MATLAB.

Reference
Sigmon, K. (1993). MATLAB Primer (Third Edition). Available Here Previously Accessed September, 12, 2008.

/HW1 contributing team members