About MATLAB MATLAB is an interactive software which has been used recently in various areas of engineering and scientific applications. It is not a computer language in the normal sense but it does most of the work of a computer language. Writing a computer code is not a straightforward job, typically boring and time consuming for beginners. One attractive aspect of MATLAB is that it is relatively easy to learn. It is written on an intuitive basis and it does not require in-depth knowledge of operational principles of computer programming like compiling and linking in most other programming languages. This could be regarded as a disadvantage since it prevents users from understanding the basic principles in computer programming. The interactive mode of MATLAB may reduce computational speed in some applications. The power of MATLAB is represented by the length and simplicity of the code. For example, one page of MATLAB code may be equivalent to many pages of other computer language source codes. Numerical calculation in MATLAB uses collections of well-written scientific/mathematical subroutines such as LINPACK and EISPACK. MATLAB provides Graphical User Interface (GUI) as well as three-dimensional graphical animation. In general, MATLAB is a useful tool for vector and matrix manipulations. Since the majority of the engineering systems are represented by matrix and vector equations, we can relieve our workload to a significant extent by using MATLAB. The finite element method is a well-defined candidate for which MATLAB can be very useful as a solution tool. Matrix and vector manipulations are essential parts in the method. MATLAB provides a help menu so that we can type the help command when we need help to figure out a command. The help utility is quite convenient for both beginners and experts.

1

Vector and Matrix Manipulations Once we get into MATLAB, we meet a prompt » called the MATLAB prompt. This prompt receives a user command and processes it providing the output on the next line. Let us try the following command to define a matrix. >> A=[1,3,6;2,7,8;0,3,9] Then the output appears in the next line as shown below. A= 1 2 0 3 7 3 6 8 9

Thus, a matrix is entered row by row, and each row is separated by the semicolon(;). Within each row, elements are separated by a space or a comma(,). Commands and variables used in MATLAB are case-sensitive. That is, lower case letters are distinguished from upper case letters. The size of the matrix is checked with >> size(A) ans = 3 3 In order to find the transpose of matrix A, we type

6 8 9 which is the third column of matrix A. In addition, >>A(:,1) represents the first row of A as ans = 1 3 6 We can also try >> A(:,1)+A(:,3) as addition of the first and third rows of A with the result ans= 1 6 15 Now let us introduce another matrix B as >> B = [3,4,5; 6,7,2:8,1,0]; Then there seems to be no output on the screen. MATLAB does not prompt output on the screen when an operation ends with the semicolon (;). If we want to check the B matrix again, we simply type >>B The screen output will be 3 4 5 B = 6 7 2 8 1 0 Matrix addition >> C = A + B 4 8 7 4 11 9 Adding two matrices is straightforward like

C = 8 14 10

Matrix subtraction

In order to subtract matrix B from matrix A, we type

3

>> C = A-B -2 C = -4 -1 0 1 6

- 8 2 9 Note that C is now a new matrix, not the summation of A and B anymore. Matrix multiplication >> C = A*B 69 C= 112 90 Matrix Functions Manipulation of matrices is a key feature of the MATLAB functions. MATLAB is a useful tool for matrix and vector manipulations. Collections of representative MATLAB matrix functions are listed in Table 1. Examples and detailed explanations are provided for each function...

YOU MAY ALSO FIND THESE DOCUMENTS HELPFUL

...Using Matlab to Execute a Genetic Algorithm
Optimization of Two Variable Function
The function to be optimized is given by:
[pic]
The maximum value of this two variable function is desired, however Matlab’s gatool finds the minimum of fitness functions and so as in the previous example the function must be altered as follows:
[pic]
Now we must enter this function, as before, into a Matlab function file.
Start Matlab and change the working directory to your Knowledge Based Systems folder. (i.e. U:\Current Class\KBS\) Create an m-file by either typing “edit fitness2” at the command prompt, or clicking the new file icon on the toolbar.
The Matlab Genetic Algorithm accepts multiple variable functions, however these variables must be contained in an array. Therefore every “x” in the above equation is replaced with “x(1)” and every “y” with “x(2)”. Once the m-file editor is open, enter the following code:
function y = fitness2(x)
y = -((1-x(1))^2*exp(-x(1)^2-(x(2)+1)^2) - (x(1) - x(1)^3 - x(2)^3)*exp(-x(1)^2-x(2)^2));
end
Save the file. (Note: The file must be saved under the same name as the function name. i.e. fitness2 as shown above)
In the Matlab command window type “gatool”. This will open the genetic algorithm tool as shown in Figure 1.
[pic]
Enter the name of your fitness function in the Fitness function text box preceded with an @ symbol as...

...~~~~~~~~~~~~~~~~~~~~ www.MathWorks.ir ~~~~~~~~~~~~~~~~~~~~
An Introduction to Programming
and Numerical Methods in MATLAB
~~~~~~~~~~~~~~~~~~~~ www.MathWorks.ir ~~~~~~~~~~~~~~~~~~~~
S.R. Otto and J.P. Denier
An Introduction to
Programming and
Numerical Methods
in MATLAB
With 111 Figures
~~~~~~~~~~~~~~~~~~~~ www.MathWorks.ir ~~~~~~~~~~~~~~~~~~~~
S.R. Otto, BSc, PhD
The R & A
St Andrews
Fife
KY16 9JD
Scotland
J.P. Denier, BSc (Hons), PhD
School of Mathematical Sciences
The University of Adelaide
South Australia 5005
Australia
British Library Cataloguing in Publication Data
Otto, S. R. (Stephen Robert)
An introduction to programming and numerical methods in
MATLAB
1. MATLAB (Computer file) 2. Numerical analysis — Data
processing
I. Title II. Denier, J. P.
518′.02855
ISBN 1852339195
Library of Congress Control Number: 2005923332
Apart from any fair dealing for the purposes of research or private study, or criticism or review, as
permitted under the Copyright, Designs and Patents Act 1988, this publication may only be reproduced, stored or transmitted, in any form or by any means, with the prior permission in writing of
the publishers, or in the case of reprographic reproduction in accordance with the terms of licences
issued by the Copyright Licensing Agency. Enquiries concerning reproduction outside those terms
should be sent to the publishers.
ISBN-10: 1-85233-919-5...

...Experiment # 1
Title: Starting with MATLAB.
Equipment Required: Personal computer (PC) with windows operating system and MATLAB software
Theory:-
MATLAB is a powerful computing system for handling the calculations involved in scientific and engineering problems. The name MATLAB stands for MATrix LABoratory, because the system was designed to make matrix computations particularly easy.
One of the many things aboutMATLAB (and which distinguishes it from many other computer programming systems, such as C++ and Java) is that you can use it interactively. This means you type some commands at the special MATLAB prompt, and get the answers immediately. The problems solved in this way can be very simple, like finding a square root, or they can be much more complicated, like finding the solution to a system of differential equations. For many technical problems you have to enter only one or two commands, and you get the answers at once.
Problems:-
Solve the following problems in the Command Window.
1) Calculate:
a)
((35.7*64)-7^3)/(45+5^2)
ans =
27.7400
b)
&gt;&gt; (5/4)*(7*6^2)+((3^7)/(9^3-652))
ans =
343.4026
c)
&gt;&gt; (2+7)^3+(273^2/3)+(55^2/3)
ans =
2.6580e+004
d)
&gt;&gt; (2^3)+(7^3)+(273^3/2)+(55^3/2)
ans =
10256747
e)
&gt;&gt; (3^7)*log(76)/((7^3)+546)/(910)^1/3
ans =
0.0039
f)
&gt;&gt;...

...DISCUSSION:
After using both languages, Microsoft Excel and MATLAB (MATrix LABoratory), on the same module experiments from 1 to 4, I observed the following:
* For Microsoft excel,
* It uses spreadsheet application where each elements or data values are distributed in cells.
* Most statistical computations are easy to solve due to the manner of data organization where data are inserted on cells arranged in numbered rows and letter-named columns.
* It is easy to plot the selected values by just choosing the selected data then use the chart tools/design tab.
* The Disadvantage of this language are as follows:
* Difficulty in debugging the error
* Limited set of statistical tools
* In the case of excessively large results, Excel returns #NUM! instead of an answer
* Inability to handle large datasets
* For MATLAB,
* It uses matrix based algorithms hence each element or data values are treated in an m row by n column, such that a single integer is considered a matrix of one row and one column.
* Manipulation of vectors is easily done by one command.
* To plot, matlab needs to use certain algorithms which are compiled in an M-file.
* The Disadvantage of this language are as follows:
* Expensive wherein every single toolbox has to be paid due to its licensure
* It uses a huge amount of computer memory; hard...

...allocated to these courses
in the timetable
• These slots will be used in weeks 2-4
– Throughout term a PC lab session is available every
week
• Students should attend lab sessions when possible
Semester 1, 2014-2015
Structure of EG-264
• Two components
– MATLAB – Revision, Numerical Integration, Root
Finding
• Dr Mike Clee
• Lectures – Weeks 2-4, Labs – Weeks 3-5
• 50% 1 assignment
– CAD – Solidworks
• Dr Chengyuan Wang
• Lectures Weeks 5-6, Labs – Weeks 6-12
• 50% – 1 assignments
Semester 1, 2014-2015
General Information
• MATLAB lab slots
– There will be demonstrators in each lab to help with MATLAB
worksheets
– Each student has the opportunity to complete the assignment during
the lab sessions
– Remember - MATLAB labs will be held between Week 3 and Week 5
this is where help will be available.
• Every year, over 40% of level-3 research projects involve the use
of MATLAB
– The only way to master MATLAB is to practice!
– Revision worksheets are available on Blackboard for practice in your
own time during weeks 3-5
– Should also put the examples from the lecture notes into MATLAB
– Try to understand what each command is doing
Semester 1, 2014-2015
Assessment – MATLAB 1 component
• You will be asked to submit your MATLAB solutions
to specific problems
– Worth 50% of total marks for the module
– Assignment will be made available on...

...AP Induction Week Course
Introduction to Engineering Computation
Laboratory Manual
MATLAB programming
Department of Engineering Science
MATLAB Laboratory Manual Contents
Laboratory 1: An introduction to MATLAB ............................................................................................ 2 Laboratory 2: Debugging, Functions and Problem Solving ............................................................22 Laboratory 3: Logical Operators, Conditional Statements and Loops ........................................32 Laboratory 4: Graphics and Image Processing ...................................................................................46 Laboratory 5: Strings and Files ................................................................................................................52 Laboratory 6: Linear equations and differential equations ..........................................................57
Laboratory 1: An introduction to MATLAB
GETTING STARTED
Your Tutor will show you how to login to the Network. Most of the applications you will use reside on File Servers rather than on the local hard drive of your computer. You have also been allocated an ec (Electronic Campus) home directory (H drive), in which you can save your work. If your computer is switched off (you can tell this by the absence of a light on the front of the computer) you should press the Power on the computer’s...

...MATLAB Parallel Computing
John Burkardt (ARC/ICAM) & Gene Cliﬀ (AOE/ICAM) Virginia Tech .......... FDI Fall Short Course: Introduction to Parallel MATLAB at Virginia Tech http://people.sc.fsu.edu/∼burkardt/presentations/fdi matlab 2009.pdf .......... ARC: Advanced Research Computing AOE: Department of Aerospace and Ocean Engineering ICAM: Interdisciplinary Center for Applied Mathematics
09 September 2009
Burkardt MATLAB Parallel Computing
MATLAB Parallel Computing: Some Announcements
While we have your attention...
Burkardt MATLAB Parallel Computing
MATLAB Parallel Computing: Some Announcements
ITHACA is an IBM iDataPlex cluster recently installed by Virginia Tech’s Advanced Research Computing facility. It is intended to gradually take over the high performance computing load from System X. ITHACA supports OpenMP, MPI and Parallel MATLAB programming. Right Now: Friendly users accepted for Ithaca (talk to John Burkardt if you are interested,); Mid October: Ithaca opened to general users (accounts given out through online application.).
Burkardt
MATLAB Parallel Computing
MATLAB Parallel Computing: Some Announcements
MATLAB Training is available this fall. These classes will be presented by the MathWorks. Some of these classes are tentative. Check the FDI website for details. 2 October: Simulink...