Escolar Documentos
Profissional Documentos
Cultura Documentos
Tutorial 1:
Tutorial Modes
Presentation
Hands on
Examples
Home work
submit here Usually two weeks after submission Checkout the course website for updates and FAQs
2
Before we start
Problems If you have computer problems while using the room, please contact:
Irit Orr (#2470) or the WICC PC Helpdesk (#3440). If you see issues that can be taken care of after your session is over, please contact Irit Orr (#2470) or Ariela Mendel (#3938).
Before we start
Rules of use Please help us keep the room in good working order.
Do not allow food or drink to be brought into the room Report problems promptly When leaving the room at the end of a session: Leave the computers on Turn off the projector Turn off all the heating / air conditioning units. This can be tricky; cup your hand around the end of the remote control to help focus the beam on one unit at a time. Put the doorstop on the ledge under the whiteboard at the front of the room Put garbage into the receptacle Turn off all the lights, including the spotlights that are controlled by the dimmer switch Close the door and make sure that it locks
Why?
Very easy to learn Great HELP (!) menu and tutorial Check out the resources in our website. From a simple calculator to complex data analysis toolbox. Many implemented algorithms.
Very useful:
Installing Matlab
Boris 2443
Input devices
Storage devices
Output devices
8
Hardware
compiler
Human language
Matlab language
Intermediate language
Computer language
Operating System
10
Matlab - Background
An interactive program that is suitable for running computations, drawing graphs and much more (graphical interface). A programming language for technical computing (scripts).
Lets start
11
Command Window
1+1
12
Command Window
Previous Command line Output (answer)
Workspace Window
Workspace Window All workspace variables
Variable value
Demo: matlab(demo) http://www.mathworks.com/support/2009b/matlab/7. 9/demos/WorkingInTheDevelopmentEnvironment.htm l
14
15
3.14159265
Imaginary unit
Relative precision 2-52 Smallest number 2-1022 Largest number (2-eps)* 21023
Inf
NaN
Infinity
Not a Number
17
What is the total num of fruits needed? How much will it cost to make the salad? Answer:
18
2/3*4
1 3 2 3 4
1/0 0/0 1+2+3+4+5+6 2*realmax Try to use: clc , up/down arrow
(-1+3+2*pi)^(3/4)
What did you get? Inf NaN Try to use in order to write in more than one line What did you get? Overflow
Usually a Matlab command ends with ; to disable echo to the command line. There are 3 ways to display the output: disp() , no ; fprintf()
19
Help:
Help (help cos); lookfor Doc (doc cos); Search F1 / right click Google matlab
Getting started Matlab contains many mathematical functions. Matlab is case sensitive!
1. Search for elementary math functions reference and find the mathematical function reference list 2. How do I calculate square root ? Search... 3. What does the function factor do? 4. What are the differences between ceil floor, fix and round? Try to run Fix what happened?
20
Output Format
Use the format function to control the output format of numeric values displayed in the Command Window.
format short (5 digits) , format Long (15 digits) , format rat Pi = 3.1416, 3.141592653589793 , 355/113
format Compact / format loose determines the line spacing in the output Checkout the doc of format
21
Files
Double click on a file will open it: .m file (script) in Editor/Debugger .fig file (figure) in Graphic window .mat file (data) will load variables to the workspace
22
disp(hello world);
F5 / run button
24
Can be done also using addpath, rmpath , path etc. Matlab search order: variables -> keywords -> current directory -> search path.
25
More: Cntrl-C (editor / command win.), Cntrl-V, Cntl-Z, Cntl-F, Cntrl-H Comments % , %{ this is a comment %} Case sensitive (and syntax errors)
26
Handling Errors
27
Desktop Layout
28
Standard Toolbar
http://www.mathworks.com/support/2007a/matlab/7.4/demos/desktop.html
29
Arithmetic operators. plus - Plus + uplus - Unary plus + minus - Minus uminus - Unary minus mtimes - Matrix multiply * times - Array multiply * mpower - Matrix power ^ power - Array power .^ mldivide - Backslash or left matrix divide \ mrdivide - Slash or right matrix divide / ldivide - Left array divide .\ rdivide - Right array divide ./ kron - Kronecker tensor product kron Relational operators. eq - Equal == ne - Not equal ~= lt - Less than < gt - Greater than > le - Less than or equal <= ge - Greater than or equal >= Logical operators. and - Logical AND & or - Logical OR | not - Logical NOT ~ xor - Logical EXCLUSIVE OR any - True if any element of vector is nonzero all - True if all elements of vector are nonzero
30
Magic Numbers: - if (final_grades<60) - for i=1:5 - hourly_pay=500*3.62 - if (final_grades<passing_grade) - for i=1:length(students_ID) - hourly_pay=salary*dollarRate
31