8bef9d54-93b1-4b22-9136-0af003721c7c

# 8bef9d54-93b1-4b22-9136-0af003721c7c - Getting started with...

This preview shows pages 1–3. Sign up to view the full content.

Getting started with MATLAB %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Introduction to Matlab % This course is adapted from MIT, Stanford, U Delaware Matlab crash % courses. % I have used the documents written by Stefan Roth and Tobin Driscoll % besides the Matlab online tutorial. Azadeh Samadani 01/10/2007 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Useful links: The Getting Started with MATLAB manual is a very good place to get a more gentle and thorough introduction: http://www.mathworks.com/access/helpdesk/help/techdoc/learn_matlab/ http://www.mathworks.com/academia/student_center/tutorials/ Basics: If you type in a valid expression and press Enter, MATLAB will immediately execute it and return the result, just like a calculator. >> 2+2 ans = 4 >> 4ˆ2 ans = 16 >> sin(pi/2) ans = 1 >> 1/0 Warning: Divide by zero. ans = Inf >> exp(i*pi) ans = -1.0000 + 0.0000i Notice some of the special expressions here: pi for π , Inf for ∞, and i for 1 - . Another special value is NaN , which stands for not a number . NaN is used to express an undefined value. For example, >> Inf/Inf ans = NaN * Challenge: Calculate the following statements: 2 5 1 + = ρ and ) 2 / 1 ( sin 1 - - and tan(e) ( Hint: >>help exp). Here are a few other demonstration statements. % % Anything after a % sign is a comment. x = rand(2,2); % ; means "don’t print out result" s = ’Hello world’; % single quotes enclose a string t = 1 + 2 + 3 + . .. % . .. means continue a line

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
4 + 5 + 6 % . .. Here are a few useful commands: who % gives you your variables cd % Change current working directory. pwd % Show (print) current working directory. dir % List directory. ls % List directory. * Type why in your command window Creating matrices and vectors A = [1 2; 3 4]; % Creates a 2x2 matrix B = [1,2; 3,4]; % The simplest way to create a matrix is % to list its entries in square brackets. % The ";" symbol separates rows; % the (optional) "," separates columns. N = 5 % A scalar v = [1 0 0] % A row vector v = [1; 2; 3] % A column vector v = v' % Transpose a vector (row to column or % column to row) v = 1:0.5:3 % A vector filled in a specified range: v = pi*[-4:4]/4 % [start:stepsize:end], brackets are % optional v = [] % Empty vector Creating special matrices 1ST parameter is ROWS, 2ND parameter is COLS m = zeros(2, 3) % Creates a 2x3 matrix of zeros
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 04/05/2010 for the course CHEMENG 05078870 taught by Professor Mustafa during the Spring '10 term at Ege Üniversitesi.

### Page1 / 6

8bef9d54-93b1-4b22-9136-0af003721c7c - Getting started with...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online