%=====CME434 Fall 06: HW5 revised on 10/19/06 is due on 10/27/06 %INTRODUCTION: %A (user defined) function is a MATLAB script that begins on the first line with, for example, % function [] = Get2D_Truss_Data(FIDI_NAME) %The left side is the function name, a matter of choice. The [] identifies any values to be returned by the function (none in this case) and the () identifies the values to be passed to the function. The name of a function and the name of the file where it is stored must be identical (in this case 'Get2D_Truss_Data.m'. %A function may call other functions or itself (but not endlessly), and functions needed only within a function can be defined within the same file. A function ends at the last executable line in the file, or when the statement 'function =' begins another function, or when the command 'return' appears in the script. The functions we need can be %The function script cannot be copied to the command window and executed ('function =' in the command window will cause an error). A function is executed by typing its name with any values to be passes. Example: inv(A) (a built-in function) returns the inverse of A. Functions can return values or do some job, like read a file. To modify the work space, information is shared with functions by the the 'global' statement: % global A B C %allows the variables A, B, and C to be shared by the function and the script that calls the function. In this case, A, B and C are not passed as parameters when calling the function. The non-global part of a function's workspace is not visible in the workspace window, but 'A' appearing in a function will show the value of A in the command window as usual. %We will need at least two files to use a function, for example HW5main.m and Get2D_Truss_Data.m. In both scripts, all the variables we want to see in the workspace window are declared global. Get2D_Truss_Data() appearing in HW5main.m will make the function execute. If another function, say fun2() is called, it can be defined in a third file fun2.m, and so on. %Another way (our author's way), the two files could be HW5main.m and HW5sub.m Within HW5main.m would be the declaration of the global variables, and HW5sub.m would be called to do all the work. Within HW5sub.m would be declaration of the global variables and the script for all we want to do, and also for Get2D_Truss_Data() and any other functions we may employ. %18 (Undergraduate students): A user defined MATLAB function Get2D_Truss_Data() will be available from the web site. It will read the problem data for 2D trusses and create the workspace. It allows you to give any name for the input file, rather than copying the problem into hw4data.txt. Copy the file Get2D_Truss_Data.m to your current directory. Replace your older "in line" code for initializing the workspace by a call to the function after declairing the globals. Check to see it produces the same workspace. %19 (Undergraduate students): A user defined MATLAB function QF_Solver() (for description, see part %17 of HW4) will be available from the website. Study it to understand how the similarity transform works. Copy QF_Solver.m to your current directory and call it from the main part of the script to solve problems where the essential displacements can be anywhere in Q. Delete parts %8 and %9 (your original solver that needs essential displacements to be in the upper part of Q). Check the results are the same for all three of the previous HW4 problems. Check that results are correct for the problem given in hw43data.txt. %20 (Graduate students only): Revise your entire HW4 script to solve 3D trusses where node coordinates are stored in XYZ(ns,ns), and there are three linear displacements per node. See Lecture notes on 3D trusses for definitions of Qe and Fe. QF_Solver should not need modification, as the major difference is in the construction of K. Script (or a function) will read 3D data from hw5data.txt to create the initial work space. Use the view() function to produce isometric figures. Test your script on data in hw51data.txt (3D version of the plane truss of hw3data.txt) and solve hw52data.txt (a 3D space truss).