matlab_tut_plain

matlab_tut_plain - MATLAB Tutorial ME17: Applied Numerical...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: MATLAB Tutorial ME17: Applied Numerical Methods 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. ¡ 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. 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 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) Some useful matrices ¡ Ones : all elements are 1 ¡ Zeros: all elements are 0...
View Full Document

This note was uploaded on 08/06/2008 for the course ME 17 taught by Professor Milstein during the Summer '07 term at UCSB.

Page1 / 43

matlab_tut_plain - MATLAB Tutorial ME17: Applied Numerical...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online