{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

matlab_tut_plain

matlab_tut_plain - MATLAB Tutorial ME17 Applied Numerical...

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

View Full Document Right Arrow Icon
MATLAB Tutorial ME17: Applied Numerical Methods
Background image of page 1

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

View Full Document Right Arrow Icon
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
Background image of page 2
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.
Background image of page 3

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

View Full Document Right Arrow Icon
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.
Background image of page 4
Different windows Familiarize yourself with command window, workspace, current-directory, command history etc.
Background image of page 5

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

View Full Document Right Arrow Icon
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
Background image of page 6
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
Background image of page 7

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

View Full Document Right Arrow Icon
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
Background image of page 8
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)
Background image of page 9

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

View Full Document Right Arrow Icon
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
Background image of page 10
Math op’s on vectors and matrices ¾
Background image of page 11

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

View Full Document Right Arrow Icon
Image of page 12
This is the end of the preview. Sign up to access the rest of the document.