SlideShare a Scribd company logo
1 of 47
Copyright © 2010. The McGraw-Hill Companies, Inc. This work is only for
non-profit use by instructors in courses for which this textbook has been
adopted. Any other use without publisher’s consent is unlawful.
Introduction to MATLAB
for Engineers, Third Edition
William J. Palm III
Chapter 1
An Overview of MATLAB®
PowerPoint to accompany
The Default MATLAB Desktop, Fig. 1.1-1, page 5
1-1
1-2
Entering Commands and Expressions
• MATLAB retains your previous keystrokes.
• Use the up-arrow key to scroll back back through
the commands.
• Press the key once to see the previous entry, and
so on.
• Use the down-arrow key to scroll forward. Edit a
line using the left- and right-arrow keys the
Backspace key, and the Delete key.
• Press the Enter key to execute the command.
Scalar arithmetic operations
Table 1.1–1, page 8
1-3
An Example Session, Pages 7-8
>> 8/10
ans =
0.8000
>> 5*ans
ans =
4
>> r=8/10
r =
0.8000
>> r
r =
0.8000
>> s=20*r
s =
16
1-4
Order of precedence
Table 1.1–2, page 9
1-5
>> 8 + 3*5
ans =
23
>> 8 + (3*5)
ans =
23
>>(8 + 3)*5
ans =
55
>>4^2128/4*2
ans =
0
>>4^212 8/(4*2)
ans =
3
1-6
Examples of Precedence, Page 9
>> 3*4^2 + 5
ans =
53
>>(3*4)^2 + 5
ans =
149
>>27^(1/3) + 32^(0.2)
ans =
5
>>27^(1/3) + 32^0.2
ans =
5
>>27^1/3 + 32^0.2
ans =
11
1-7
Examples of Precedence, Page 9 Continued
Commands for managing the work session
Table 1.1–3, Page 12
1-8
Special variables and constants
Table 1.1–4, Page 14
1-9
Complex Number Operations, Pages 14-15
• The number c1 = 1 – 2i is entered as follows:
c1 = 12i.
• An asterisk is not needed between i or j and
a number, although it is required with a
variable, such as c2 = 5 i*c1.
• Be careful. The expressions
y = 7/2*i
and
x = 7/2i
give two different results:
y = (7/2)i = 3.5i
and
x = 7/(2i) = –3.5i.
1-10
Numeric display formats. Table 1.1–5, Page 15
1-11
The Desktop Menus and Toolbar. Figure 1.2-1, page 16
Arrays
• The numbers 0, 0.1, 0.2, …, 10 can be assigned to the
variable u by typing u = 0:0.1:10.
• To compute w = 5 sin u for u = 0, 0.1, 0.2, …, 10, the
session is;
>>u = 0:0.1:10;
>>w = 5*sin(u);
• The single line, w = 5*sin(u), computed the formula
w = 5 sin u 101 times.
1-12
Array Index
>>u(7)
ans =
0.6000
>>w(7)
ans =
2.8232
• Use the length function to determine how
many values are in an array.
>>m = length(w)
m =
101
1-13
Polynomial Roots, Page 20
To find the roots of x3 – 7x2 + 40x – 34 = 0, the session
is
>>a = [1,-7,40,-34];
>>roots(a)
ans =
3.0000 + 5.000i
3.0000 - 5.000i
1.0000
The roots are x = 1 and x = 3 ± 5i.
1-14
Some commonly used mathematical functions
Table 1.3–1, Page 21
1-15
When you type problem1,
1. MATLAB first checks to see if problem1 is
a variable and if so, displays its value.
2. If not, MATLAB then checks to see if
problem1 is one of its own commands, and
executes it if it is.
3. If not, MATLAB then looks in the current
directory for a file named problem1.m
and executes problem1 if it finds it.
4. If not, MATLAB then searches the
directories in its search path, in order,
for problem1.m and then executes it if
found.
1-16
System, directory, and file commands
Table 1.3–2,Page 23
1-17
A graphics window showing a plot. Figure 1.3-1, page 24.
1-18
Some MATLAB plotting commands
Table 1.3–3, Page 25
1-19
Linear Algebraic Equations, Page 26
6x + 12y + 4z = 70
7x – 2y + 3z = 5
2x + 8y – 9z = 64
>>A = [6,12,4;7,-2,3;2,8,-9];
>>B = [70;5;64];
>>Solution = AB
Solution =
3
5
-2
The solution is x = 3, y = 5, and z = –2.
1-20
You can perform operations in MATLAB in two
ways:
1. In the interactive mode, in which all
commands are entered directly in the
Command window, or
2. By running a MATLAB program stored in
script file. This type of file contains
MATLAB commands, so running it is
equivalent to typing all the commands—
one at a time—at the Command window
prompt. You can run the file by typing its
name at the Command window prompt.
1-21
COMMENTS
The comment symbol may be put anywhere in the
line. MATLAB ignores everything to the right of the
% symbol. For example,
>>% This is a comment.
>>x = 2+3 % So is this.
x =
5
Note that the portion of the line before the % sign is
executed to compute x.
1-22
The MATLAB Command window with the
Editor/Debugger open. Figure 1.4–1, Page 28
1-23
Keep in mind when using script files:
1. The name of a script file must begin with
a letter, and may include digits and the
underscore character, up to 63
characters.
2. Do not give a script file the same name
as a variable.
3. Do not give a script file the same name
as a MATLAB command or function. You
can check to see if a command, function
or file name already exists by using the
exist command.
1-24
Debugging Script Files
Program errors usually fall into one of the
following categories.
1. Syntax errors such as omitting a parenthesis
or comma, or spelling a command name
incorrectly. MATLAB usually detects the
more obvious errors and displays a message
describing the error and its location.
2. Errors due to an incorrect mathematical
procedure, called runtime errors. Their
occurrence often depends on the particular
input data. A common example is division by
zero.
1-25
To locate program errors, try the following:
1. Test your program with a simple version of
the problem which can be checked by hand.
2. Display any intermediate calculations by
removing semicolons at the end of
statements.
3. Use the debugging features of the
Editor/Debugger.
1-26
Programming Style
1. Comments section
a. The name of the program and any key
words in the first line.
b. The date created, and the creators' names
in the second line.
c. The definitions of the variable names for
every input and output variable. Include
definitions of variables used in the calculations
and units of measurement for all input and all
output variables!
d. The name of every user-defined function
called by the program.
1-27
2. Input section Include input data
and/or the input functions and
comments for documentation.
3. Calculation section
4. Output section This section might
contain functions for displaying the
output on the screen.
Programming Style (continued)
1-28
Some Input/output commands
From Table 1.4–1, Page 31
1-29
Example of a Script File, Page 32
Problem:
The speed v of a falling object dropped with no initial
velocity is given as a function of time t by v = gt.
Plot v as a function of t for 0 < t < tfinal, where tfinal is the
final time entered by the user.
1-30
Example of a Script File (continued)
% Program falling_speed.m:
% Plots speed of a falling object.
% Created on March 1, 2009 by W. Palm
%
% Input Variable:
% tfinal = final time (in seconds)
%
% Output Variables:
% t = array of times at which speed is
% computed (in seconds)
% v = array of speeds (meters/second)
%
1-31
Example of a Script File (continued)
% Parameter Value:
g = 9.81; % Acceleration in SI units
%
% Input section:
tfinal = input(’Enter final time in
seconds:’);
%
1-32
Example of a Script File (continued)
% Calculation section:
dt = tfinal/500;
% Create an array of 501 time values.
t = 0:dt:tfinal;
% Compute speed values.
v = g*t;
%
% Output section:
Plot(t,v),xlabel(’t (s)’),ylabel(’v m/s)’)
1-33
Getting Help From the Textbook
 Throughout each chapter margin notes identify where
key terms are introduced.
 Each chapter contains tables summarizing the MATLAB
commands introduced in that chapter.
 At the end of each chapter is a summary guide to the
commands covered in that chapter.
 Appendix A contains tables of MATLAB commands,
grouped by category, with the appropriate page
references.
 There are four indexes. The first lists MATLAB
commands and symbols, the second lists Simulink
blocks, the third lists MuPAD commands, and the fourth
lists topics.
1-34
Getting Help From MATLAB:
The Function Browser after plot has been selected
(Figure 1.5-1, page 33)
1-35
The MATLAB Help Browser
Figure 1.5-2, page 34
1-36
The Help Navigator
Fig. 1.5-3, page 35
1-37
MATLAB Help Functions,
From Table 1.5-1, page 38
 help funcname: Displays in the Command
window a description of the specified function
funcname.
 lookfor topic: Displays in the Command
window a brief description for all functions
whose description includes the specified key
word topic.
 doc funcname: Opens the Help Browser to
the reference page for the specified function
funcname, providing a description, additional
remarks, and examples.
1-38
Steps in engineering problem solving
Table 1.6–1,
Page 39
1-39
Sketch of the dropped-package problem.
Figure 1.6–1, page 41
1-40
Steps for developing a computer solution
Table 1.6–2, page 42
1-41
A piston, connecting rod, and crank for an internal
combustion engine. Figure 1.6–2, 43
1-42
Plot of the piston motion versus crank angle.
Figure 1.6–3, page 45
1-43
Key Terms with Page References
Argument, 8 MAT-files, 20
Array, 19 Model, 39
Array index, 19 Overlay plot, 24
ASCII files, 21 Path, 22
Assignment operator, 10 Precedence, 9
Command window, 6 Scalar, 8
Comment, 27 Script file, 27
Current directory, 16 Search path, 22
Data file, 21 Session, 7
Data marker, 25 String variable, 31
Debugging, 29 Variable, 7
Desktop, 5 Workspace, 11
Graphics window, 23
1-44
Homework Problem 25, Figure P25, page 50
1-45
1-46
Homework Problem 29, Figure P29, page 51

More Related Content

Similar to matlabchapter1.ppt

MATLAB sessions Laboratory 1MAT 275 Laboratory 1Introdu.docx
MATLAB sessions Laboratory 1MAT 275 Laboratory 1Introdu.docxMATLAB sessions Laboratory 1MAT 275 Laboratory 1Introdu.docx
MATLAB sessions Laboratory 1MAT 275 Laboratory 1Introdu.docxandreecapon
 
Matlab for diploma students(1)
Matlab for diploma students(1)Matlab for diploma students(1)
Matlab for diploma students(1)Retheesh Raj
 
Matlab ch1 intro
Matlab ch1 introMatlab ch1 intro
Matlab ch1 introRagu Nathan
 
6 weeks summer training in matlab,jalandhar
6 weeks summer training in matlab,jalandhar6 weeks summer training in matlab,jalandhar
6 weeks summer training in matlab,jalandhardeepikakaler1
 
data mining training in Bangalore
data mining training in Bangaloredata mining training in Bangalore
data mining training in Bangalorematrixphagwara
 
6months industrial training in matlab, jalandhar
6months industrial training in matlab, jalandhar6months industrial training in matlab, jalandhar
6months industrial training in matlab, jalandhardeepikakaler1
 
vlsi training in chandigarh
vlsi training in chandigarhvlsi training in chandigarh
vlsi training in chandigarhmatrixphagwara
 
interfacing matlab with embedded systems
interfacing matlab with embedded systemsinterfacing matlab with embedded systems
interfacing matlab with embedded systemsRaghav Shetty
 
Kevin merchantss
Kevin merchantssKevin merchantss
Kevin merchantssdharmesh69
 
KEVIN MERCHANT DOCUMENT
KEVIN MERCHANT DOCUMENTKEVIN MERCHANT DOCUMENT
KEVIN MERCHANT DOCUMENTtejas1235
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlabTarun Gehlot
 
Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013amanabr
 
Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013Kurmendra Singh
 
MATLAB Workshop yugjjnhhasfhlhhlllhl.pptx
MATLAB Workshop yugjjnhhasfhlhhlllhl.pptxMATLAB Workshop yugjjnhhasfhlhhlllhl.pptx
MATLAB Workshop yugjjnhhasfhlhhlllhl.pptxprashantkumarchinama
 

Similar to matlabchapter1.ppt (20)

1. Ch_1 SL_1_Intro to Matlab.pptx
1. Ch_1 SL_1_Intro to Matlab.pptx1. Ch_1 SL_1_Intro to Matlab.pptx
1. Ch_1 SL_1_Intro to Matlab.pptx
 
MATLAB guide
MATLAB guideMATLAB guide
MATLAB guide
 
MATLAB sessions Laboratory 1MAT 275 Laboratory 1Introdu.docx
MATLAB sessions Laboratory 1MAT 275 Laboratory 1Introdu.docxMATLAB sessions Laboratory 1MAT 275 Laboratory 1Introdu.docx
MATLAB sessions Laboratory 1MAT 275 Laboratory 1Introdu.docx
 
EE6711 Power System Simulation Lab manual
EE6711 Power System Simulation Lab manualEE6711 Power System Simulation Lab manual
EE6711 Power System Simulation Lab manual
 
Ch1
Ch1Ch1
Ch1
 
Matlab for diploma students(1)
Matlab for diploma students(1)Matlab for diploma students(1)
Matlab for diploma students(1)
 
Matlab ch1 intro
Matlab ch1 introMatlab ch1 intro
Matlab ch1 intro
 
6 weeks summer training in matlab,jalandhar
6 weeks summer training in matlab,jalandhar6 weeks summer training in matlab,jalandhar
6 weeks summer training in matlab,jalandhar
 
data mining training in Bangalore
data mining training in Bangaloredata mining training in Bangalore
data mining training in Bangalore
 
6months industrial training in matlab, jalandhar
6months industrial training in matlab, jalandhar6months industrial training in matlab, jalandhar
6months industrial training in matlab, jalandhar
 
vlsi training in chandigarh
vlsi training in chandigarhvlsi training in chandigarh
vlsi training in chandigarh
 
interfacing matlab with embedded systems
interfacing matlab with embedded systemsinterfacing matlab with embedded systems
interfacing matlab with embedded systems
 
Kevin merchantss
Kevin merchantssKevin merchantss
Kevin merchantss
 
KEVIN MERCHANT DOCUMENT
KEVIN MERCHANT DOCUMENTKEVIN MERCHANT DOCUMENT
KEVIN MERCHANT DOCUMENT
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
Matlab Tutorial.ppt
Matlab Tutorial.pptMatlab Tutorial.ppt
Matlab Tutorial.ppt
 
Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013
 
Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013
 
Matlab anilkumar
Matlab  anilkumarMatlab  anilkumar
Matlab anilkumar
 
MATLAB Workshop yugjjnhhasfhlhhlllhl.pptx
MATLAB Workshop yugjjnhhasfhlhhlllhl.pptxMATLAB Workshop yugjjnhhasfhlhhlllhl.pptx
MATLAB Workshop yugjjnhhasfhlhhlllhl.pptx
 

More from PariaMotahari1

Educational Objectives (1).pdf
Educational Objectives (1).pdfEducational Objectives (1).pdf
Educational Objectives (1).pdfPariaMotahari1
 
anemiaofchronicdisease-141214080635-conversion-gate01-1.pdf
anemiaofchronicdisease-141214080635-conversion-gate01-1.pdfanemiaofchronicdisease-141214080635-conversion-gate01-1.pdf
anemiaofchronicdisease-141214080635-conversion-gate01-1.pdfPariaMotahari1
 
components of a communication-2 .pptx
components of a communication-2 .pptxcomponents of a communication-2 .pptx
components of a communication-2 .pptxPariaMotahari1
 
835013767-6701662004782059.pptx
835013767-6701662004782059.pptx835013767-6701662004782059.pptx
835013767-6701662004782059.pptxPariaMotahari1
 
omtavpdvtma5mhgwzcmq-140611070359-phpapp02-4741661860748681.pptx
omtavpdvtma5mhgwzcmq-140611070359-phpapp02-4741661860748681.pptxomtavpdvtma5mhgwzcmq-140611070359-phpapp02-4741661860748681.pptx
omtavpdvtma5mhgwzcmq-140611070359-phpapp02-4741661860748681.pptxPariaMotahari1
 
neckmassdd-170813161534.pptx
neckmassdd-170813161534.pptxneckmassdd-170813161534.pptx
neckmassdd-170813161534.pptxPariaMotahari1
 
cns,_nbl,_hbl,gonads,_nephro.ppt
cns,_nbl,_hbl,gonads,_nephro.pptcns,_nbl,_hbl,gonads,_nephro.ppt
cns,_nbl,_hbl,gonads,_nephro.pptPariaMotahari1
 
differential_diagnosis_of_head_and_swellings-.ppt
differential_diagnosis_of_head_and_swellings-.pptdifferential_diagnosis_of_head_and_swellings-.ppt
differential_diagnosis_of_head_and_swellings-.pptPariaMotahari1
 

More from PariaMotahari1 (9)

Educational Objectives (1).pdf
Educational Objectives (1).pdfEducational Objectives (1).pdf
Educational Objectives (1).pdf
 
Blood 111.pptx
Blood 111.pptxBlood 111.pptx
Blood 111.pptx
 
anemiaofchronicdisease-141214080635-conversion-gate01-1.pdf
anemiaofchronicdisease-141214080635-conversion-gate01-1.pdfanemiaofchronicdisease-141214080635-conversion-gate01-1.pdf
anemiaofchronicdisease-141214080635-conversion-gate01-1.pdf
 
components of a communication-2 .pptx
components of a communication-2 .pptxcomponents of a communication-2 .pptx
components of a communication-2 .pptx
 
835013767-6701662004782059.pptx
835013767-6701662004782059.pptx835013767-6701662004782059.pptx
835013767-6701662004782059.pptx
 
omtavpdvtma5mhgwzcmq-140611070359-phpapp02-4741661860748681.pptx
omtavpdvtma5mhgwzcmq-140611070359-phpapp02-4741661860748681.pptxomtavpdvtma5mhgwzcmq-140611070359-phpapp02-4741661860748681.pptx
omtavpdvtma5mhgwzcmq-140611070359-phpapp02-4741661860748681.pptx
 
neckmassdd-170813161534.pptx
neckmassdd-170813161534.pptxneckmassdd-170813161534.pptx
neckmassdd-170813161534.pptx
 
cns,_nbl,_hbl,gonads,_nephro.ppt
cns,_nbl,_hbl,gonads,_nephro.pptcns,_nbl,_hbl,gonads,_nephro.ppt
cns,_nbl,_hbl,gonads,_nephro.ppt
 
differential_diagnosis_of_head_and_swellings-.ppt
differential_diagnosis_of_head_and_swellings-.pptdifferential_diagnosis_of_head_and_swellings-.ppt
differential_diagnosis_of_head_and_swellings-.ppt
 

Recently uploaded

꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Callshivangimorya083
 
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Callshivangimorya083
 
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM TRACKING WITH GOOGLE ANALYTICS.pptx
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM  TRACKING WITH GOOGLE ANALYTICS.pptxEMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM  TRACKING WITH GOOGLE ANALYTICS.pptx
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM TRACKING WITH GOOGLE ANALYTICS.pptxthyngster
 
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改atducpo
 
Log Analysis using OSSEC sasoasasasas.pptx
Log Analysis using OSSEC sasoasasasas.pptxLog Analysis using OSSEC sasoasasasas.pptx
Log Analysis using OSSEC sasoasasasas.pptxJohnnyPlasten
 
B2 Creative Industry Response Evaluation.docx
B2 Creative Industry Response Evaluation.docxB2 Creative Industry Response Evaluation.docx
B2 Creative Industry Response Evaluation.docxStephen266013
 
From idea to production in a day – Leveraging Azure ML and Streamlit to build...
From idea to production in a day – Leveraging Azure ML and Streamlit to build...From idea to production in a day – Leveraging Azure ML and Streamlit to build...
From idea to production in a day – Leveraging Azure ML and Streamlit to build...Florian Roscheck
 
VIP High Class Call Girls Bikaner Anushka 8250192130 Independent Escort Servi...
VIP High Class Call Girls Bikaner Anushka 8250192130 Independent Escort Servi...VIP High Class Call Girls Bikaner Anushka 8250192130 Independent Escort Servi...
VIP High Class Call Girls Bikaner Anushka 8250192130 Independent Escort Servi...Suhani Kapoor
 
Schema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdfSchema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdfLars Albertsson
 
Industrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdfIndustrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdfLars Albertsson
 
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.pptdokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.pptSonatrach
 
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779Best VIP Call Girls Noida Sector 39 Call Me: 8448380779
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779Delhi Call girls
 
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service Amravati
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service AmravatiVIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service Amravati
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service AmravatiSuhani Kapoor
 
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service Bhilai
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service BhilaiLow Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service Bhilai
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service BhilaiSuhani Kapoor
 
RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998YohFuh
 
100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptxAnupama Kate
 
{Pooja: 9892124323 } Call Girl in Mumbai | Jas Kaur Rate 4500 Free Hotel Del...
{Pooja:  9892124323 } Call Girl in Mumbai | Jas Kaur Rate 4500 Free Hotel Del...{Pooja:  9892124323 } Call Girl in Mumbai | Jas Kaur Rate 4500 Free Hotel Del...
{Pooja: 9892124323 } Call Girl in Mumbai | Jas Kaur Rate 4500 Free Hotel Del...Pooja Nehwal
 
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdfKantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdfSocial Samosa
 
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝soniya singh
 

Recently uploaded (20)

꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
 
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
 
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM TRACKING WITH GOOGLE ANALYTICS.pptx
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM  TRACKING WITH GOOGLE ANALYTICS.pptxEMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM  TRACKING WITH GOOGLE ANALYTICS.pptx
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM TRACKING WITH GOOGLE ANALYTICS.pptx
 
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
 
Log Analysis using OSSEC sasoasasasas.pptx
Log Analysis using OSSEC sasoasasasas.pptxLog Analysis using OSSEC sasoasasasas.pptx
Log Analysis using OSSEC sasoasasasas.pptx
 
B2 Creative Industry Response Evaluation.docx
B2 Creative Industry Response Evaluation.docxB2 Creative Industry Response Evaluation.docx
B2 Creative Industry Response Evaluation.docx
 
From idea to production in a day – Leveraging Azure ML and Streamlit to build...
From idea to production in a day – Leveraging Azure ML and Streamlit to build...From idea to production in a day – Leveraging Azure ML and Streamlit to build...
From idea to production in a day – Leveraging Azure ML and Streamlit to build...
 
VIP High Class Call Girls Bikaner Anushka 8250192130 Independent Escort Servi...
VIP High Class Call Girls Bikaner Anushka 8250192130 Independent Escort Servi...VIP High Class Call Girls Bikaner Anushka 8250192130 Independent Escort Servi...
VIP High Class Call Girls Bikaner Anushka 8250192130 Independent Escort Servi...
 
Schema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdfSchema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdf
 
Industrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdfIndustrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdf
 
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.pptdokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
 
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779Best VIP Call Girls Noida Sector 39 Call Me: 8448380779
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779
 
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service Amravati
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service AmravatiVIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service Amravati
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service Amravati
 
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service Bhilai
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service BhilaiLow Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service Bhilai
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service Bhilai
 
RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998
 
E-Commerce Order PredictionShraddha Kamble.pptx
E-Commerce Order PredictionShraddha Kamble.pptxE-Commerce Order PredictionShraddha Kamble.pptx
E-Commerce Order PredictionShraddha Kamble.pptx
 
100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx
 
{Pooja: 9892124323 } Call Girl in Mumbai | Jas Kaur Rate 4500 Free Hotel Del...
{Pooja:  9892124323 } Call Girl in Mumbai | Jas Kaur Rate 4500 Free Hotel Del...{Pooja:  9892124323 } Call Girl in Mumbai | Jas Kaur Rate 4500 Free Hotel Del...
{Pooja: 9892124323 } Call Girl in Mumbai | Jas Kaur Rate 4500 Free Hotel Del...
 
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdfKantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
 
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
 

matlabchapter1.ppt

  • 1. Copyright © 2010. The McGraw-Hill Companies, Inc. This work is only for non-profit use by instructors in courses for which this textbook has been adopted. Any other use without publisher’s consent is unlawful. Introduction to MATLAB for Engineers, Third Edition William J. Palm III Chapter 1 An Overview of MATLAB® PowerPoint to accompany
  • 2. The Default MATLAB Desktop, Fig. 1.1-1, page 5 1-1
  • 3. 1-2 Entering Commands and Expressions • MATLAB retains your previous keystrokes. • Use the up-arrow key to scroll back back through the commands. • Press the key once to see the previous entry, and so on. • Use the down-arrow key to scroll forward. Edit a line using the left- and right-arrow keys the Backspace key, and the Delete key. • Press the Enter key to execute the command.
  • 5. An Example Session, Pages 7-8 >> 8/10 ans = 0.8000 >> 5*ans ans = 4 >> r=8/10 r = 0.8000 >> r r = 0.8000 >> s=20*r s = 16 1-4
  • 6. Order of precedence Table 1.1–2, page 9 1-5
  • 7. >> 8 + 3*5 ans = 23 >> 8 + (3*5) ans = 23 >>(8 + 3)*5 ans = 55 >>4^2128/4*2 ans = 0 >>4^212 8/(4*2) ans = 3 1-6 Examples of Precedence, Page 9
  • 8. >> 3*4^2 + 5 ans = 53 >>(3*4)^2 + 5 ans = 149 >>27^(1/3) + 32^(0.2) ans = 5 >>27^(1/3) + 32^0.2 ans = 5 >>27^1/3 + 32^0.2 ans = 11 1-7 Examples of Precedence, Page 9 Continued
  • 9. Commands for managing the work session Table 1.1–3, Page 12 1-8
  • 10. Special variables and constants Table 1.1–4, Page 14 1-9
  • 11. Complex Number Operations, Pages 14-15 • The number c1 = 1 – 2i is entered as follows: c1 = 12i. • An asterisk is not needed between i or j and a number, although it is required with a variable, such as c2 = 5 i*c1. • Be careful. The expressions y = 7/2*i and x = 7/2i give two different results: y = (7/2)i = 3.5i and x = 7/(2i) = –3.5i. 1-10
  • 12. Numeric display formats. Table 1.1–5, Page 15 1-11 The Desktop Menus and Toolbar. Figure 1.2-1, page 16
  • 13. Arrays • The numbers 0, 0.1, 0.2, …, 10 can be assigned to the variable u by typing u = 0:0.1:10. • To compute w = 5 sin u for u = 0, 0.1, 0.2, …, 10, the session is; >>u = 0:0.1:10; >>w = 5*sin(u); • The single line, w = 5*sin(u), computed the formula w = 5 sin u 101 times. 1-12
  • 14. Array Index >>u(7) ans = 0.6000 >>w(7) ans = 2.8232 • Use the length function to determine how many values are in an array. >>m = length(w) m = 101 1-13
  • 15. Polynomial Roots, Page 20 To find the roots of x3 – 7x2 + 40x – 34 = 0, the session is >>a = [1,-7,40,-34]; >>roots(a) ans = 3.0000 + 5.000i 3.0000 - 5.000i 1.0000 The roots are x = 1 and x = 3 ± 5i. 1-14
  • 16. Some commonly used mathematical functions Table 1.3–1, Page 21 1-15
  • 17. When you type problem1, 1. MATLAB first checks to see if problem1 is a variable and if so, displays its value. 2. If not, MATLAB then checks to see if problem1 is one of its own commands, and executes it if it is. 3. If not, MATLAB then looks in the current directory for a file named problem1.m and executes problem1 if it finds it. 4. If not, MATLAB then searches the directories in its search path, in order, for problem1.m and then executes it if found. 1-16
  • 18. System, directory, and file commands Table 1.3–2,Page 23 1-17
  • 19. A graphics window showing a plot. Figure 1.3-1, page 24. 1-18
  • 20. Some MATLAB plotting commands Table 1.3–3, Page 25 1-19
  • 21. Linear Algebraic Equations, Page 26 6x + 12y + 4z = 70 7x – 2y + 3z = 5 2x + 8y – 9z = 64 >>A = [6,12,4;7,-2,3;2,8,-9]; >>B = [70;5;64]; >>Solution = AB Solution = 3 5 -2 The solution is x = 3, y = 5, and z = –2. 1-20
  • 22. You can perform operations in MATLAB in two ways: 1. In the interactive mode, in which all commands are entered directly in the Command window, or 2. By running a MATLAB program stored in script file. This type of file contains MATLAB commands, so running it is equivalent to typing all the commands— one at a time—at the Command window prompt. You can run the file by typing its name at the Command window prompt. 1-21
  • 23. COMMENTS The comment symbol may be put anywhere in the line. MATLAB ignores everything to the right of the % symbol. For example, >>% This is a comment. >>x = 2+3 % So is this. x = 5 Note that the portion of the line before the % sign is executed to compute x. 1-22
  • 24. The MATLAB Command window with the Editor/Debugger open. Figure 1.4–1, Page 28 1-23
  • 25. Keep in mind when using script files: 1. The name of a script file must begin with a letter, and may include digits and the underscore character, up to 63 characters. 2. Do not give a script file the same name as a variable. 3. Do not give a script file the same name as a MATLAB command or function. You can check to see if a command, function or file name already exists by using the exist command. 1-24
  • 26. Debugging Script Files Program errors usually fall into one of the following categories. 1. Syntax errors such as omitting a parenthesis or comma, or spelling a command name incorrectly. MATLAB usually detects the more obvious errors and displays a message describing the error and its location. 2. Errors due to an incorrect mathematical procedure, called runtime errors. Their occurrence often depends on the particular input data. A common example is division by zero. 1-25
  • 27. To locate program errors, try the following: 1. Test your program with a simple version of the problem which can be checked by hand. 2. Display any intermediate calculations by removing semicolons at the end of statements. 3. Use the debugging features of the Editor/Debugger. 1-26
  • 28. Programming Style 1. Comments section a. The name of the program and any key words in the first line. b. The date created, and the creators' names in the second line. c. The definitions of the variable names for every input and output variable. Include definitions of variables used in the calculations and units of measurement for all input and all output variables! d. The name of every user-defined function called by the program. 1-27
  • 29. 2. Input section Include input data and/or the input functions and comments for documentation. 3. Calculation section 4. Output section This section might contain functions for displaying the output on the screen. Programming Style (continued) 1-28
  • 30. Some Input/output commands From Table 1.4–1, Page 31 1-29
  • 31. Example of a Script File, Page 32 Problem: The speed v of a falling object dropped with no initial velocity is given as a function of time t by v = gt. Plot v as a function of t for 0 < t < tfinal, where tfinal is the final time entered by the user. 1-30
  • 32. Example of a Script File (continued) % Program falling_speed.m: % Plots speed of a falling object. % Created on March 1, 2009 by W. Palm % % Input Variable: % tfinal = final time (in seconds) % % Output Variables: % t = array of times at which speed is % computed (in seconds) % v = array of speeds (meters/second) % 1-31
  • 33. Example of a Script File (continued) % Parameter Value: g = 9.81; % Acceleration in SI units % % Input section: tfinal = input(’Enter final time in seconds:’); % 1-32
  • 34. Example of a Script File (continued) % Calculation section: dt = tfinal/500; % Create an array of 501 time values. t = 0:dt:tfinal; % Compute speed values. v = g*t; % % Output section: Plot(t,v),xlabel(’t (s)’),ylabel(’v m/s)’) 1-33
  • 35. Getting Help From the Textbook  Throughout each chapter margin notes identify where key terms are introduced.  Each chapter contains tables summarizing the MATLAB commands introduced in that chapter.  At the end of each chapter is a summary guide to the commands covered in that chapter.  Appendix A contains tables of MATLAB commands, grouped by category, with the appropriate page references.  There are four indexes. The first lists MATLAB commands and symbols, the second lists Simulink blocks, the third lists MuPAD commands, and the fourth lists topics. 1-34
  • 36. Getting Help From MATLAB: The Function Browser after plot has been selected (Figure 1.5-1, page 33) 1-35
  • 37. The MATLAB Help Browser Figure 1.5-2, page 34 1-36
  • 38. The Help Navigator Fig. 1.5-3, page 35 1-37
  • 39. MATLAB Help Functions, From Table 1.5-1, page 38  help funcname: Displays in the Command window a description of the specified function funcname.  lookfor topic: Displays in the Command window a brief description for all functions whose description includes the specified key word topic.  doc funcname: Opens the Help Browser to the reference page for the specified function funcname, providing a description, additional remarks, and examples. 1-38
  • 40. Steps in engineering problem solving Table 1.6–1, Page 39 1-39
  • 41. Sketch of the dropped-package problem. Figure 1.6–1, page 41 1-40
  • 42. Steps for developing a computer solution Table 1.6–2, page 42 1-41
  • 43. A piston, connecting rod, and crank for an internal combustion engine. Figure 1.6–2, 43 1-42
  • 44. Plot of the piston motion versus crank angle. Figure 1.6–3, page 45 1-43
  • 45. Key Terms with Page References Argument, 8 MAT-files, 20 Array, 19 Model, 39 Array index, 19 Overlay plot, 24 ASCII files, 21 Path, 22 Assignment operator, 10 Precedence, 9 Command window, 6 Scalar, 8 Comment, 27 Script file, 27 Current directory, 16 Search path, 22 Data file, 21 Session, 7 Data marker, 25 String variable, 31 Debugging, 29 Variable, 7 Desktop, 5 Workspace, 11 Graphics window, 23 1-44
  • 46. Homework Problem 25, Figure P25, page 50 1-45
  • 47. 1-46 Homework Problem 29, Figure P29, page 51