Tutoria matlab 1
6.094
Lecture 1: Variables, Scripts, and Operations
Danilo Šćepanović
IAP 2010
Course Layout
• Lectures
1: 2: 3: 4: 5:
Variables, Scripts and Operations Visualization and Programming Solving Equations, Fitting Images, Animations, Advanced Methods Optional: Symbolic Math, Simulink
Course Layout
• Problem Sets / Office Hours
One perday, should take about 3 hours to do Submit doc or pdf (include code, figures) No set office hours but available by email
• Requirements for passing
Attend all lectures Complete all problem sets (-, √, +)
• Prerequisites
Basic familiarity with programming Basic linear algebra, differential equations, and probability
Outline
(1) (2) (3) (4) (5) Getting Started Scripts Making VariablesManipulating Variables Basic Plotting
Getting Started
• To get MATLAB Student Version for yourself » https://msca.mit.edu/cgi-bin/matlab
Use VPN client to enable off-campus access Note: MIT certificates are required
• Open up MATLAB for Windows
Through the START Menu
• On Athena » add matlab » matlab &
Current directory
Workspace
Command Window
Command History
Courtesy ofThe MathWorks, Inc. Used with permission.
Making Folders
• Use folders to keep your programs organized
• To make a new folder, click the ‘Browse’ button next to ‘Current Directory’
• Click the ‘Make New Folder’ button, and change the name of the folder. Do NOT use spaces in folder names. In the MATLAB folder, make two new folders: IAPMATLAB\day1 • Highlight the folder you just made andclick ‘OK’ • The current directory is now the folder you just created • To see programs outside the current directory, they should be in the Path. Use File-> Set Path to add folders to the path
Customization
• File Preferences
Allows you personalize your MATLAB experience
Courtesy of The MathWorks, Inc. Used with permission.
MATLAB Basics
• MATLAB can be thought of as a super-powerfulgraphing calculator
Remember the TI-83 from calculus? With many more buttons (built-in functions)
• In addition it is a programming language
MATLAB is an interpreted language, like Java Commands executed line by line
Help/Docs
• help The most important function for learning MATLAB on your own • To get info on how to use a function: » help sin Help lists related functions at the bottomand links to the doc • To get a nicer version of help with examples and easy-toread descriptions: » doc sin • To search for a function by specifying keywords: » doc + Search tab
Outline
(1) (2) (3) (4) (5) Getting Started Scripts Making Variables Manipulating Variables Basic Plotting
Scripts: Overview
• Scripts are
collection of commands executed in sequence written in the MATLAB editorsaved as MATLAB files (.m extension)
• To create an MATLAB file from command-line » edit helloWorld.m • or click
Courtesy of The MathWorks, Inc. Used with permission.
Scripts: the Editor
* Means that it's not saved Line numbers MATLAB file path Debugging tools Real-time error check
Help file
Comments
Possible breakpoints
Courtesy of The MathWorks, Inc. Used with permission.Scripts: Some Notes
• COMMENT!
Anything following a % is seen as a comment The first contiguous comment becomes the script's help file Comment thoroughly to avoid wasting time later
• Note that scripts are somewhat static, since there is no input and no explicit output • All variables created and modified in a script exist in the workspace even after it has stopped running
Exercise:Scripts
Make a helloWorld script • When run, the script should display the following text:
Hello World! I am going to learn MATLAB!
• Hint: use disp to display strings. Strings are written between single quotes, like 'This is a string'
Exercise: Scripts
Make a helloWorld script • When run, the script should display the following text:
Hello World! I am going to learn MATLAB!
• Hint:...
Regístrate para leer el documento completo.