0% found this document useful (0 votes)
19 views7 pages

1.matlab Week1

The document outlines an introduction to MATLAB course covering installing and accessing MATLAB, the user interface, using MATLAB as a calculator, matrices and arrays, functions, control flow, plotting, debugging, numerical methods and good programming practices.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views7 pages

1.matlab Week1

The document outlines an introduction to MATLAB course covering installing and accessing MATLAB, the user interface, using MATLAB as a calculator, matrices and arrays, functions, control flow, plotting, debugging, numerical methods and good programming practices.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

29‐May‐23

DEPARTMENT OF CIVIL ENGINEERING  Course Outline


INDIAN INSTITUTE OF TECHNOLOGY BOMBAY
 Installing and Accessing MATLAB
 Introduction to MATLAB Environment (User Interface)
 MATLAB as a Calculator
 Matrices and Array Operations
 MATLAB as a Programming Language

Introduction to MATLAB  Functions and Scripts

 Control Flow (Conditional statements, loop control)

Summer of Core - 2023  Plotting and File Handling


IIT Bombay  Error Handling and Debugging

Mohammad Rafiq Joo  Numerical Methods and Basic Optimization Techniques


Prime Minister’s Research Fellow
 Good Programming Practices
IIT Bombay
1
([email protected]) © MR Summer of Core - 2023 2
1 2

 Course Weightage
 Attendance - 10%
 Weekly Assignments – 20%
 Course Project – 70% Week 1
Session-I

© MR Summer of Core - 2023 3 © MR Summer of Core - 2023 4


3 4
29‐May‐23

 What is MATLAB ?  Installing MATLAB Licensed Version

 MATLAB: Matrix Laboratory


 Developed by Wilkinson, Forsythe, and Todd.
 Marketed and further developed by MathsWorks Inc.
 Used for matrix-based manipulation, plotting functions and
data, algorithm implementation, user interface creation, etc.
 Available in many operating systems – Windows, Macintosh, https://matlab.mathworks.com/
Unix, DOS
 Number of toolboxes available to solve specific problems.

© MR Summer of Core - 2023 5 © MR Summer of Core - 2023 6


5 6

 Accessing MATLAB MATLAB Online


 User Interface
Current Directory
 Interaction with MATLAB
Files in current directory
 Windows & tabs
 Primary windows
 Command Window
 Workspace
 Editor
 Current Directory/File explorer
 MATLAB session
 Meaning
 Saving/reproducing/starting‐from‐where‐you‐left

Workspace Command window

© MR Summer of Core - 2023 7 © MR Summer of Core - 2023 8


7 8
29‐May‐23

 MATLAB as a Calculator

 Let’s try out some examples


 Basic operations
 Variable assignment
MATLAB as a Calculator  And a lot more

© MR Summer of Core - 2023 9 © MR Summer of Core - 2023 10


9 10

 Getting Started  Getting Started


Some facts to remember  Variable name = a value ( or an expression).
 No need to declare variables, allocate storage, dimension 
 Expression could be a manual entry ( numbers, array, matrix, other
statements. variables), built-in function, user-defined functions.
 However, initialization, if possible, is a good practice.  Overwriting variables
 Programs can be executed step‐by‐step with full access to all 
 Error Messages
variables and functions.
 Making Corrections
 Variable names cannot have special characters and cannot 
 Get a hang of using up-arrow and tab keys.
start with a number or underscore.
 Controlling the hierarchy of operations
 Strictly avoid naming variables the same as function names.
 Comments‐ % (Use Ctrl+R/T to comment/uncomment).

© MR Summer of Core - 2023 11 © MR Summer of Core - 2023 12


11 12
29‐May‐23

 Getting Started  Some Tips


 Getting help  Ctrl + C‐ to abort an ongoing computation
 …‐ to continue a line
 help functionname
 Use of single inverted comma for strings and 
 lookfor, doc characters
 Function name is not known but not syntax, F1  Some mathematical functions you should try out.
 sqrt(x), round(x)
 Function is kind-of-known, See also  sum(x), sum(x, dim), sum(sum(x))
 Function is unknown, Google (or any other search engine)!  prod(x), prod(x, dim), prod(prod(x))
 max(x), min(x) over array or matrix (column/row)
 MathWorks® online reference manual, stack exchange
 sin(x), asin(x), log(x), log10(x), exp(x)
 Exponent‐ ^, Negation‐ ~, Division‐ /, Left division‐ \  Some Pre‐defined variables
 ans, pi, i, inf, NaN (0 * inf)

© MR Summer of Core - 2023 13 © MR Summer of Core - 2023 14


13 14

 Getting Started
 Controlling the appearance
 format long ↵
 format short ↵
 disp(x) ↵ Week 1
 Managing the workspace
 clear, clearvars, clearvars –except, who

 Multiple statements per line


Session-II
 Miscellaneous commands
 clc, ctrl-c

© MR Summer of Core - 2023 15 © MR Summer of Core - 2023 16


15 16
29‐May‐23

 What have we covered so far ?


 Installing and Accessing MATLAB

 Introduction to MATLAB Environment (User Interface)

 MATLAB as a Calculator

 Matrices and Array Operations

 MATLAB as a Programming Language Matrix and Array Operations


 Functions and Scripts

 Control Flow (Conditional statements, loop control)

 File Handling

 Plotting, Error Handling and Debugging

 Good Programming Practices

© MR Summer of Core - 2023 17 © MR Summer of Core - 2023 18


17 18

 Matrix and Array  Matrix and Array


 Matrices = MATLAB fundamentals (recall MATLAB definition)  Matrix Indexing

 Entering a vector  A(row,col)↵

 v1 = [1 2 5 8]↵  A(2,2) = 10 ↵

 v2 = [1; 2; 5; 8]↵ or ?  Colon Operator  

 v1(1:3); v1(2,end), v1(2) ↵  x = 0:0.1:5 ↵ n = length(x)↵

 Entering a matrix  Linear Spacing 

 A = [1 2 3;4 5 6;7 8 9]↵  y = linspace(0,5,51) ↵ x & y ?


 theta = linspace(0,2*pi,101)↵
 logspace
© MR Summer of Core - 2023 19 © MR Summer of Core - 2023 20
19 20
29‐May‐23

 Matrix and Array  Matrix and Array


 Deleting row or column
 Colon Operator in matrix
 A(3,:)= [] ↵
 A(3,:)↵
 Dimension
 A(:,2:3)=1↵
 size(A) ↵ [m,n] = size(A) ↵
 Creating a submatrix
 Continuation (…)
 B = A([2 3],[1 2])↵
 Transpose
 C = A([2 1 3],:) ↵ A(:)↵
 A’ or transpose(A) ↵
 D = A(end:-1:1,end)↵ Guess the result
 Concatenating matrices
 B = [A 10*A; -A [1 0 0; 0 1 0; 0 0 1]] ↵
© MR Summer of Core - 2023 21 © MR Summer of Core - 2023 22
21 22

 Matrix and Array  Matrix and Array Operations


 Matrix Generators and Special Matrices  Arithmetic Operations

 eye(m,n)↵ eye(n)↵  C = A+B ↵ D = A*B ↵

 zeros(m,n)↵ zeros(n)↵  A^2 ↵ E = 3*A ↵

 ones(m,n)↵ ones(n)↵  Sum(A)↵

 rand(m,n)↵, rng()↵  Element‐wise Operation

 diag(A), magic(n)↵  A.^2 F = A.*B

 hilb invhilb, pascal, Toeplitz,  A./B A.^B

vander, Wilkinson  Matrix Inverse 


 F = inv(A) F = A^-1
© MR Summer of Core - 2023 23 © MR Summer of Core - 2023 24
23 24
29‐May‐23

 Let’s Solve Simultaneous Linear equations

1   4    2 2 𝑥 4𝑦 2𝑧 2
 𝐴 2    3  2 𝑏 3 2𝑥 3𝑦 2𝑧 3
1 1 0 4 𝑥 𝑦 0𝑧 4

 Ax = b x=A-1b
 X = inv(A)*b x = A\b
 Some Matrix Functions
 det(A) diag(A) eig(A)
 inv(A) norm(A) rank(A)

© MR Summer of Core - 2023 25


25

You might also like