Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

MECH1004 - Slides - Section 16 Greyscale 6 To Page

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

MECH1004

COMPUTING

/ 16. Introduction to MATLAB

MECH1004

COMPUTING

/ 16. Introduction to MATLAB

16.1 What is MATLAB?


MATLAB is a proprietary* software package for interactive numeric computation, data analysis, and graphics. (*Think about the implications of this.)

16. Introduction to MATLAB

It can be applied to a wide range of technical disciplines: DIGITAL SIGNAL PROCESSING CONTROL THEORY LINEAR ALGEBRA SIGNALS AND SYSTEMS NUMERICAL METHODS ADVANCED ENGINEERING MATHEMATICS

MECH1004

COMPUTING

/ 16. Introduction to MATLAB

MECH1004

COMPUTING

/ 16. Introduction to MATLAB

MATLABs principal features are: MATRIX COMPUTATION INTEGRATED GRAPHICS TOOLBOXES MATLAB is not a programming language, although it has its own programming facility within it. Rather, it is like a test-bench where you can play around with formulae and mathematical constructs, plot graphs and, yes, write programs if you need to. (MATLAB = MATrix LABoratory)

Having said that MATLAB is not a programming language, many people treat it as such because its programming facility can be made to be on a par with other high level languages. In normal use MATLAB programs are loaded and run within the MATLAB programming environment. They are then interpreted line by line, where each line of MATLAB source code is converted in turn to a binary instruction for the computers CPU to work on. This is in contrast to compiled languages like FORTRAN where all the lines of source code are converted into binary code, and optimised, within a ready-to-run .exe file (executable file).

MECH1004

COMPUTING

/ 16. Introduction to MATLAB

MECH1004

COMPUTING

/ 16. Introduction to MATLAB

Thus, a MATLAB program running within the MATLAB environment will not usually be as fast as, say a FORTRAN program. However, the development time needed for the MATLAB program may be significantly less if it makes extensive use of the MATLAB built-in functions. If the speed of the running program is not an issue, then MATLAB may be the better choice. Having said that, compilers are now available to allow MATLAB program files (M-files) to be run outside the MATLAB environment.

MATLABs basic data structure is a MATRIX. Even a single integer variable is treated as a matrix of one row and one column. This concept might take a while to get used to. Names in MATLAB are formed by a letter, followed by other letters, digits or underscores though only the first nineteen characters are recognised/significant. Importantly, unlike Fortran, MATLAB does distinguish between uppercase and lowercase letters. Thus the variables a and A in a MATLAB program would be different entities.

MECH1004

COMPUTING

/ 16. Introduction to MATLAB

MECH1004

COMPUTING

/ 16. Introduction to MATLAB

16.2 The MATLAB Environment


MATLAB opens up by default with 5 windows to the environment. These can be closed or re-arranged as the user wishes. COMMAND WINDOW You can type command lines here
(as if MATLAB were a glorified calculator), or simply type the name of an M-file to get it to run, etc.

LAUNCHPAD Here you can access the various


Toolboxes that are available for different applications.

CURRENT DIRECTORY This shows the contents of the


Windows directory that you are working in.

COMMAND HISTORY This lists all the commands that


have been typed in the command window. Clicking on a previous command in the history activates that command again and saves your typing finger.

WORKSPACE This shows the variables (matrices) that


have been defined so far, and can be interrogated to show the current contents of the matrices.

OTHER WINDOWS
Other windows will be displayed when you click on certain files (e.g. M-files) or activate certain functions (e.g. graph plotting functions). These can be re-arranged or closed as required.

MECH1004

COMPUTING

/ 16. Introduction to MATLAB

MECH1004

COMPUTING

/ 16. Introduction to MATLAB

16.3 What the MATLAB Language Looks Like


Sample coding 1:(This could be typed in line by line in the command window or written to an m-file for repeated use.) % Test Program % disp('hello - who are you?'); name = input('Please enter name between quotes '); d = date; answer = ['Hello ' name '. Today is ' d '.']; disp (answer); MATLAB only recognises single quotes MATLABs comment symbol Semi-colons after a command stop the result being printed to the screen

Sample coding 2:(This could be typed in line by line in the command window or written to an m-file for repeated use.) % Simple sums x = 25.0 y = 33.9 z=x*y a=x+y A=y/x b = a * cos (30) c = A * sin (30) d=x^2 D = sqrt(y) e = sqrt(-1) NB different from FORTRAN which uses **

MECH1004

COMPUTING

/ 16. Introduction to MATLAB

MECH1004

COMPUTING

/ 16. Introduction to MATLAB

16.4 Why Use Matrices?


MATLAB developers realised that matrices/arrays were a very useful way for storing, representing and referencing ALL types of data. Now that we have studied FORTRAN we can see, at least, that array-type structures are obviously beneficial for the storage and referencing of: SEQUENCES/TABLES OF DATA VECTORS MATRICES

At this stage in your engineering education you will just have to take it on trust that it is because so many advanced maths and engineering type problems & solutions are so succinctly described by vector equations and algebra, that the writers of MATLAB decided to make the MATRIX the fundamental structure within their program. Well be looking at problem solving using matrices later. For now lets get familiar with how we can create matrices in MATLAB.

You might also like