Download presentation

Presentation is loading. Please wait.

Published byBarbara Gardner Modified over 3 years ago

1
Introduction to MATLAB CBE 502 Mathematical Methods of Engineering Analysis

2
Where to get MATLAB Princeton Software : Office of Information Technology (OIT) http://www.princeton.edu/software/licenses/ software/matlab/

3
What is MATLAB High level language useful for technical computing with extensive library of mathematical and graphical subroutines Stands for MATrix LABoratory

4
MATLAB Desktop

5
MATLAB Introduction Creating Matrices A=[1,2,3;4,5,6;7,8,9]; Will give a 3 X 3 matrix A= 1 2 3 4 5 6 7 8 9 Very easy to access/modify each element A(i,j)

6
MATLAB Introduction zeros(m, n): matrix with all zeros ones(m, n): matrix with all ones. eye(m, n): the identity matrix rand(m, n): uniformly distributed random randn(m, n): normally distributed random magic(m): square matrix whose elements have the same sum, along the row, column and diagonal.

7
MATLAB Introduction Colon Notation ‘:’ – Generating Vector Step Size – Access to part of Matrix ‘end’ Notation

8
MATLAB Introduction Operators – ^: exponentiation – *: multiplication – /: division – \: left division. The operation A\B is effectively the same as INV(A)*B, although left division is calculated differently and is much quicker. – +: addition – -: subtraction Pay attention to size of the arrays

9
Relational/Logical Operator == Equal to ~= Not equal to < Strictly smaller > Strictly greater <= Smaller than or equal to >= Greater than equal to & And operator | Or operator

10
MATLAB Introduction Element by Element.^,.*,./ – Different from Matrix Operation Flow Controls – If, else, for, while, break.. M File – text file containing program to run

11
Built In Functions mean(A): mean value of a vector max(A), min (A): maximum and minimum. sum(A): summation. sort(A): sorted vector median(A): median value std(A): standard deviation. det(A) : determinant of a square matrix dot(a,b): dot product of two vectors Cross(a,b): cross product of two vectors Inv(A): Inverse of a matrix A

12
Some Useful/Interesting MATLAB Commands who List known variables whos List known variables plus their size help >> help sqrt Help on using sqrt lookfor >> lookfor sqrt Search keyword sqrt in m-files what >> what a: List MATLAB files in a: clear Clear all variables from work space clear x y Clear variables x and y from work space clc Clear the command window any (x) returns 1 if any element of x is nonzero all (x) returns 1 if all elements of x are nonzero isnan (x) returns 1 at each NaN in x isinf (x) returns 1 at each infinity in x finite (x) returns 1 at each finite value in x

13
2D Plots Important Functions – plot, hold, title, xlabel, ylabel, legend – Sub plots, saveas,

14
Examples MATLAB.. Here we come !!

15
Keep on exploring MATLAB.. May the Coding force be with you Thanks..

Similar presentations

© 2019 SlidePlayer.com Inc.

All rights reserved.

To make this website work, we log user data and share it with processors. To use this website, you must agree to our Privacy Policy, including cookie policy.

Ads by Google