Академический Документы
Профессиональный Документы
Культура Документы
Lecture Overview
This set of lecture notes describes:
1/10/2017 10:54:05 AM
Computer Languages
What is a computer language?
Example:
+1300042774
+1400593419
+1200274027
1/10/2017 10:54:05 AM
1/10/2017 10:54:05 AM
numerical computations
scientific visualization
symbolic computations
1/10/2017 10:54:05 AM
1/10/2017 10:54:05 AM
Command Window
Workspace Window
Current Folder Window
Editor Window
Figure Window
Help Window
1/10/2017 10:54:05 AM
Interactive mode
1/10/2017 10:54:05 AM
1/10/2017 10:54:05 AM
10
1/10/2017 10:54:05 AM
Semicolon (;)
Percent sign ( % )
11
1/10/2017 10:54:05 AM
1/10/2017 10:54:05 AM
13
1/10/2017 10:54:05 AM
Subtraction:
Exponentiation:
Left Division (Reciprocal): \
Order of Precedence
1.
2.
3.
4.
Addition: +
Multiplication: *
Right Division: /
14
1/10/2017 10:54:05 AM
Show Examples
15
1/10/2017 10:54:05 AM
Outputs
Example
y = sqrt( x )
output name argument
16
1/10/2017 10:54:05 AM
17
exp(x) Exponential
abs(x) Absolute value
log(x) natural (base ) logarithm = log ()
log10(x) base-10 logarithm log10
factorial(n) ! = 1 2 3 3 2 1
1/10/2017 10:54:05 AM
18
1/10/2017 10:54:05 AM
19
1/10/2017 10:54:05 AM
20
1/10/2017 10:54:05 AM
21
1/10/2017 10:54:05 AM
Example
22
>> x = 3;
>> x = x + 6; %read value stored in x,
%add 6 to it,
%and store result back in x
>> x = 2 * x; %read value stored in x,
%double it,
%and store result in x
ENGR 15100 (Lecture #1), Naumov
1/10/2017 10:54:05 AM
Naming Variables
23
1/10/2017 10:54:05 AM
Example: speed_of_light
24
Example: speedOfLight
ENGR 15100 (Lecture #1), Naumov
1/10/2017 10:54:05 AM
ans the value of the previous calculation that was not assigned to a
variable
pi The number 3.14159
eps Smallest difference between two real numbers capable of
being represented by MATLAB and the associated computer on which
MATLAB is installed
25
1/10/2017 10:54:05 AM
Example
>>i
ans =
0.0000 + 1.0000i
>>i = 20.5
%redefine predefined value of i
i =
20.5000
26
1/10/2017 10:54:05 AM
Examples
>>ENGR 15100 is easy!
>> myName = Steve Naumov;
>> aSingleSpace = ;
27
1/10/2017 10:54:05 AM
Example
>> temp = 90; %why didnt MATLAB display the result
>> disp(temp)
90
>> disp(Today is a hot day!);
Today is a hot day!
>> myName = Steve Naumov;
>> disp(myName)
Steve Naumov
28
1/10/2017 10:54:05 AM
Examples
29
1/10/2017 10:54:05 AM
1/10/2017 10:54:05 AM
31
1/10/2017 10:54:05 AM
load Command Loads data (variables) saved in a MATfile from disk back into workspace of interactive session
Examples
32
1/10/2017 10:54:05 AM
Batch mode
33
1/10/2017 10:54:05 AM
Script Files
34
1/10/2017 10:54:05 AM
Examples/Demos
35
1/10/2017 10:54:05 AM
If youve already named and saved the M-file, just click on the
Save button in the Editor tab
If you havent named the M-file yet, click the arrow on the Save
button in the Editor tab, then choose Save As
Naming rules for files are similar to rules for variable names
36
1/10/2017 10:54:05 AM
37
1/10/2017 10:54:05 AM
Errors in Scripts/Programs
MATLAB usually detects the more obvious errors and displays a message
describing the error and its location
MATLAB ALSO halts the execution of the script at the point of the error
38
1/10/2017 10:54:05 AM
39
1/10/2017 10:54:05 AM
Example Problem
= 15.9
40
1/10/2017 10:54:05 AM
Example Solution
%--------------------------------------------------------------------------------% Author: Steve Naumov
% Filename: example.m
% Purpose: This file computes circumference/area of a circle, perimeter/area
% of a rectangle, and uses those results to compute the surface area of a cylinder
%--------------------------------------------------------------------------------radius_in_mm = 22.4;
%suppress display in command window
height_in_cm = 15.9;
41
1/10/2017 10:54:05 AM
42
1/10/2017 10:54:05 AM
Lecture Summary
43
1/10/2017 10:54:05 AM