{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

matlab_tut_plain

# matlab_tut_plain - MATLAB Tutorial ME17 Applied Numerical...

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

MATLAB Tutorial ME17: Applied Numerical Methods

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

View Full Document
Your TA Gaurav Soni Email: [email protected] Class Webpage: www.engr.ucsb.edu/~gsoni/me17.html This tutorial is already posted on the webpage. Read chapter 2 and 3 of the book
MATLAB: A math tool MATLAB is a tool for doing complicated math calculations and plotting basically Everybody uses MATLAB: Engineers, physicists, chemists, mathematicians Very interactive, easy to learn, can learn the basics in one day. In order to learn, go back and implement the commands yourself in the CAD lab Don’t try too hard to remember the commands. You can always find them easily.

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

View Full Document
Beginning a MATLAB session in the CAD lab. Building: Engineering 2 Room: 2243 This lab might not be open 24 hours during summer so work accordingly (please check with dept. for hours) Login? If you don’t have an ECI computer account please visit https://accounts.engr.ucsb.edu/create/ and create an account for yourself Start the MATLAB program? Click on the MATLAB icon on the desktop or click Start, then Programs, then MathApps, then MATLAB. Use the latest version. If CAD lab is very busy, there are other ECI labs in chemical and electrical engineering depts.
Different windows Familiarize yourself with command window, workspace, current-directory, command history etc.

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

View Full Document
Start with simple math Operations Just like a calculator - + * / ^ Input the following commands in the command window and press enter ¾ 55-16 ¾ ans+11 (can use the word ‘ans’ to use the previous output) ¾ 5*4 ¾ 5/2 ¾ 3.5^2 ¾ 3.5^2; (use semicolon to suppress the echo printing) ¾ (9*3+6/2)^0.5 (understand the priority of operations, notice the use of parentheses) A cool trick: Use the up and down arrow keys repeatedly to revoke the earlier used commands
Assignment ¾ a=4 ¾ A=6; (case sensitive) ¾ c=a*A ¾ a=c (‘a’ will be overridden) Complex numbers: ¾ x=2+i*4 i is the imaginary unit and is equal to sqrt(-1) Readymade constants: pi (=3.1416) Some cool commands Format short : to display 4 decimal places Format long : to display 15 decimal places

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

View Full Document
Built-in functions MATLAB has a very rich library of functions for our use. Examples ¾ sin(pi/2) ¾ a=10; b=sin(a) (can use variables as arguments) ¾ cos(0) ¾ log(10) ¾ log(a) ¾ sqrt(a) Need help? help function name ¾ help sin ¾ help * Google is always there. E.g., search for ‘sin in MATLAB’. It will give you the matlab help on sin
Vectors and Matrices Vectors and matrices are collections of values Row vector: a=[1 2 3 4 5] Column vector: b=[2;4;6;8;10] (use of semicolons to separate the rows) or, b=[2 4 6 8 10]’ (taking transpose by using ) Matrix: A=[1 2 3; 4 5 6; 7 8 9] ((use of semicolons to separate the rows) Accessing the elements of matrices a(2) (vectors need one subscript) b(4) A(2,3) (matrices need two subscripts)

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

View Full Document
Some useful matrices Ones : all elements are 1 Zeros: all elements are 0 ones(2,3) (# of rows=2, # of columns=3) zeros(3,2) These are used for initializing matrices and allocating appropriate memory. You can change the values later d=zeros(2,3) d(1,1)=2;d(2,1)=3 ; eye(3,3) Gives an Identity matrix
Math op’s on vectors and matrices ¾

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.