Introduction To MATLAB For Engineers, Third Edition
Introduction To MATLAB For Engineers, Third Edition
IntroductiontoMATLAB
forEngineers,ThirdEdition
William J. Palm III
Chapter 1
An Overview of MATLAB
1-1
1-2
1-3
1-4
>>8/10
ans=
0.8000
>>5*ans
ans=
4
>>r=8/10
r=
0.8000
>>r
r=
0.8000
>>s=20*r
s=
16
Order of precedence
Table 1.12, page 9
1-5
1-6
>>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
1-8
1-9
1-11
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 thelengthfunction to determine how
many values are in an array.
>>m=length(w)
m=
101
1-13
1-14
1-15
1-16
1-17
1-18
1-19
>>A=[6,12,4;7,2,3;2,8,9];
>>B=[70;5;64];
>>Solution=A\B
Solution=
3
5
2
The solution isx=3,y=5,andz=2.
1-20