Essentials of MATLAB Programming 3rd Edi
Essentials of MATLAB Programming 3rd Edi
eu/Essentials-of-MATLAB-Programming-3rd-Edition-Chapman-Solutions-Manual
! "
(d) .1 2/ 0 consists of the elements in the first and third rows on the last column
of :
3 # $!
(a) Legal (b) Illegal—names must begin with a letter. (c) Legal (d) Illegal—names must begin
with a letter. (e) Illegal—the apostrophe and the question mark are illegal characters.
(a) This is a three element row array containing the values 2, 5, and 8:
3 %
3 & # $
4
(c) This is a 2 × 2 element array containing the first and third rows and columns of 4:
3 ' & !
(d) This is a 1 × 3 row array containing the sum of (= [2 5 8]) plus the second row of 4 (= [5 5
5]):
3 & !
5
© 2018 Cengage Learning®. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
3 #( )* ! ) * ! " $
that the expression 5 is the same as , because the transpose operator applies to the
single element 5 only: 5 . Both expressions produce the row array 1 2. To produce a
column array, we would write the expression as . 05, so that the transpose operator applied to
the entire vector.
(f) This statement swaps the first and third rows in the second column of array 4:
3 & # $! & # $!
4
(g) This statement produces nothing, because even the first element (1) is below the termination
condition (5) when counting down:
3 "
3 !
3 !
(c) This array consists of the first and third rows and the third and fourth columns of , with
the third column repeated twice:
3 !# $
3 # $!
6
© 2018 Cengage Learning®. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
(a) This statement displays the number using the normal MATLAB format:
3 * # + * + $
7 -%
3 * # + * + $
7 -%
3 , , + - . ! +
7 -%
3 , , + -,. ! +
7 -%
(e) This statement displays the number in general format, which uses an exponential form if the
number is too large or too small.
3 , , + -/. ! +
7 -%
(f) This statement displays the number in floating2point format in a 122character field, with 4 digits
after the decimal point:
3 , , + - 0 ,. ! +
7 -%
3 * + &
%-&
1 0
(b) Legal: This is matrix multiplication. Since . 0 is the 2 × 2 identity matrix , the
0 1
result of the multiplication is just the original matrix .
3 * +
%-&
7
© 2018 Cengage Learning®. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
3 * + 0
%-&
3 * + '
%-&
(e) Illegal: This is element by element array multiplication, and the two arrays have different sizes.
3 * + . &
%-&
3 * + 0. &
%-&
3 * + 0 &
%-&
(a) 8.2 (b) 8.2 (c) 1.0 (d) 729 (e) 6561 (f) 729 (g) 4 (h) 4 (i) 3
The solution to this set of equations can be found using the left division operator:
3 # 01 "01 01 01 01 01 000
01 01 "01 01 201 01 000
01 201 01 "01 01 01 000
01 01 201 "01 01 01 000
01 201 01 01 201 01 000
01 01 01 01 "01 01 $
8
© 2018 Cengage Learning®. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
A program to plot the height and speed of a ball thrown vertically upward is shown below:
9 : & ; - 4 -- "
9
9 <% $
9 )$ - %- & - &! & = &$ $; 4 --
9 &! $ % & % ; ! >!&
9
9 ? $ $; 7 $
9 # & < $> "" # & $ $; ! >
9
9 8 8 : @ ! " A > - $
9
9 # ; 7 4-
9 > ( - & $ % &$ > 7 & ."8 B 0
9 ! C >!& ."0
9 ! D & - ! >!& ."0
9 & ) " . 0
9 7 E & - : ."8 0
9 7 D & - E & - : ."8 0
9 # - &! %-&
-$&.&/!/&/70G
& &- .5<-$& $; ! >!& 7 & " 50G
- 4 -.5) " . 050G
9
© 2018 Cengage Learning®. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
3 & ++
6 & &! & - 7 -$ & $; &! 4 -- 1
6 & &! & - ! >!& $; &! 4 -- 1
A program to calculate the distance between two points in a Cartesian plane is shown below:
9 - %- & &
& L &.. 0B . 0B 0G
9 ) -- %
.15)! & 5 %" & . &020G
3 *
6 &
6 &
6 & 2
6 & 2
)! &
A program to calculate the distance between two points in a Cartesian plane is shown below:
9 - %- & &
& L &.. 0B . 0B .F F 0B 0G
9 ) -- %
.15)! & 5 %" & . &020G
11
© 2018 Cengage Learning®. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
3 *
6 &
6 &
6 & F
6 &
6 &
6 & F
)! &
9 : & ; - 4 - "
9
9 <% $
9 )$ - %- & &! +" $ $ > &$ % % -
9 $ &&
9
9 ? $ $; 7 $
9 # & < $> "" # & $ $; ! >
9
9 8 8 : @ ! " A > - $
9
9 # ; 7 4-
9 +" <$ +"
9 <$ &&
9 - %- & +"
+" K -$> . 8 0G
9 ) -- %
.15<$ 5 %" & . +"0 5 +"520G
3 ' & +
6 & &! $ && 1
<$ +"
3 ' & +
6 & &! $ && 10
<$ +"
12
© 2018 Cengage Learning®. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
9
9 ? $ $; 7 $
9 # & < $> "" # & $ $; ! >
9
9 8 8 : @ ! " A > - $
9
9 # ; 7 4-
9 +" <$ +"
9 <$ &&
9 & $; $ &&
G
9 - %- & $ +"
+" K -$> . 8 0G
9 <-$& $ - -
; >% . 0G
-$&. +"/ 0G
& &- .5<-$& $; $ && 7 $ +"50G
- 4 -.5<$ . +"050G
- 4 -.5<$ . && 050G
> $ G
13
© 2018 Cengage Learning®. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
A program to calculate and plot the power consumed by a resistor as the voltage across the resistor
is varied from 1 to 200 volts shown below:
14
© 2018 Cengage Learning®. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
9 <-$& $ - -
; >% . 0G
-$&.7 / 0G
& &- .5<-$& $; $ && 7 7$-& > 7$-& 50G
- 4 -.5E$-& > .E050G
- 4 -.5<$ . && 050G
> $ G
15
© 2018 Cengage Learning®. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
16
© 2018 Cengage Learning®. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
(a) A program that accepts a 3D vector in rectangular coordinates and calculates the vector in
spherical coordinates is shown below:
9 ) -- %
.5)! ! - $$ & 50G
.15 5 %" & . 020G
.15&! & 5 %" & .&! & 020G
.15 ! 5 %" & . ! 020G
' * ' +
6 &
6 &
6 & F 1
)! ! - $$ &
&! &
!
' * ' +
6 &
6 & 1
6 & F
)! ! - $$ &
17
© 2018 Cengage Learning®. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
&! &
!
(b) A program that accepts a 3D vector in spherical coordinates (with the angles θ and ϕ in
degrees) and calculates the vector in rectangular coordinates is shown below:
9 ) -- %
.5)! # & >%- $$ & 50G
.15 5 %" & . 020G
.15 5 %" & . 020G
.15F 5 %" & .F020G
* ' + '
6 & 7 &$ - >&! "
6 & - 7 >- &! & > 20%3
6 & - 7 & $ >- ! > 1
)! & >%- $$ &
F
* ' + '
6 & 7 &$ - >&! "
18
© 2018 Cengage Learning®. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
(a) A program that accepts a 3D vector in rectangular coordinates and calculates the vector in
spherical coordinates is shown below:
9 ) -- %
.5)! ! - $$ & 50G
.15 5 %" & . 020G
.15&! & 5 %" & .&! & 020G
.15 ! 5 %" & . ! 020G
' * ' +
6 &
6 &
6 & F 1
)! ! - $$ &
19
© 2018 Cengage Learning®. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
&! &
!
' * ' +
6 &
6 & 1
6 & F
)! ! - $$ &
&! &
!
(b) A program that accepts a 3D vector in spherical coordinates (with the angles θ and ϕ in
degrees) and calculates the vector in rectangular coordinates is shown below:
9 ) -- %
.5)! # & >%- $$ & 50G
.15 5 %" & . 020G
.15 5 %" & . 020G
.15F 5 %" & .F020G
* ' + '
6 & 7 &$ - >&! "
6 & - 7 >- &! & > 20%3
20
© 2018 Cengage Learning®. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
F
* ' + '
6 & 7 &$ - >&! "
6 & - 7 >- &! & > 1
6 & - 7 & $ >- ! > 20%3
)! & >%- $$ &
A program to calculate cosh(x) both from the definition and using the MATLAB intrinsic function is
shown below. Note that we are using ; &; to display the results, so that we can control the
number of digits displayed after the decimal point:
9 : & ; - $ ! "
9
9 <% $
9 )$ - %- & &! ! 4$- $ $;
9
9 ? $ $; 7 $
9 # & < $> "" # & $ $; ! >
9
9 8 8 : @ ! " A > - $
9
9 # ; 7 4-
9 D %& 7 -%
9 $ !. 0 ; $" &! ; & $
9 $ !. 0 ; $" &! '()*(+ ;% & $
9 - %- & $ !. 0
. . 0 . 0 0 8 G
$ !. 0G
9 ) -- %
; &;.5? %-& ; $" ; & $ 9 ; 5/ 0G
; &;.5? %-& ; $" ;% & $ 9 ; 5/ 0G
3 ')*
6 &
? %-& ; $" ; & $
? %-& ; $" ;% & $
21
© 2018 Cengage Learning®. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
9 & $; $ %& 7 -%
G
9 - %- & $ !. 0
$ ! $ !. 0G
9 <-$& $ - -
-$&. / $ ! 0G
& &- .5<-$& $; $ !. 0 7 50G
- 4 -.5 50G
- 4 -.5 $ !. 050G
> $ G
The resulting plot is shown below. Note that the function reaches a minimum value of 1.0 at x = 0.
22
© 2018 Cengage Learning®. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
9 ) -- %
; &;.5# - " & 9 ; " & 5/ 0G
; &;.5:&$ > 9 ; =$%- 5/ > 0G
When this program is executed, the results are as shown below. The second spring stores the most
energy.
3 * /
6 & ;$ $ > .I0 1
6 & > $ & & .I8"0 11
# - " & " &
:&$ > =$%-
3 * /
6 & ;$ $ > .I0 1
6 & > $ & & .I8"0 "1
# - " & " &
:&$ > =$%-
3 * /
6 & ;$ $ > .I0 "
6 & > $ & & .I8"0 11
# - " & " &
:&$ > =$%-
3 * /
6 & ;$ $ > .I0 1
6 & > $ & & .I8"0 %11
23
© 2018 Cengage Learning®. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
9 : & ; - $ "
9
9 <% $
9 )$ - %- & &! $ & ; L% $; $
9
9 ? $ $; 7 $
9 # & < $> "" # & $ $; ! >
9
9 8 8 : @ ! " A > - $
9
9 # ; 7 4-
9 & .J0
9 ; L ? $ & ; L% .CF0
9 - D % & .C0
9 - %- & $ & ; L%
; L 8 . K K L &.-K 0 0G
9 ) -- %
; &;.5? $ & ; L% 9 ; CF 5/; L0G
3 )
6 & % & ! 10 "
6 & & ; 10 8
? $ & ; L% CF
(a) A program to calculate the frequency response of a radio receiver is shown below:
9 : & ; - $ "
9
9 <% $
9 )$ -$& &! ; L% $ $; $ 7
9
9 ? $ $; 7 $
9 # & < $> "" # & $ $; ! >
9
9 8 8 : @ ! " A > - $
9
9 # ; 7 4-
9 & .J0
9 ; L ? $ & ; L% .CF0
9 - D % & .C0
24
© 2018 Cengage Learning®. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
9 & .$!" 0
9 7 $%& %& 7 -& > .E0
9 7 %& 7$-& > .E0
9 ( >%- ; L% . 8 0
9 D & - 7 -%
G
- G
G
7 G
9 - %- &
K K ; LG
9 <-$& $ - -
-$&.; L/70G
& &- .5<-$& $; $%& %& 7$-& > 7 ; L% 50G
- 4 -.5J L% .CF050G
- 4 -.5E$-& > .E050G
> $ G
25
© 2018 Cengage Learning®. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
The resulting frequency response is shown below. Note that the function reaches a minimum value
of 1.0 at x = 0.
(b) The resonant frequency of this circuit is about 1.007 MHz. If the frequency is changed to 1.1
MHz, the output voltage will be 1.75 mV instead of the 10 mV at the resonant frequency. This
receiver is not very selective—real radios do much better.
(c) The output voltage drops from 10 mV to 5 mV at 0.979 MHz and 1.035 MHz.
A program to calculate the output power of the receiver for a given input voltage and frequency is
shown below:
9 : & ; - $ "
9
9 <% $
9 )$ - %- & &! $%& %& $ $; $ 7
9
9 ? $ $; 7 $
9 # & < $> "" # & $ $; ! >
9
9 8 8 : @ ! " A > - $
9
9 # ; 7 4-
9 & .J0
9 ; L ? $ & ; L% .CF0
9 - D % & .C0
9 & .$!" 0
26
© 2018 Cengage Learning®. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
9 D & - 7 -%
G
- G
G
9 - %- &
K K ; LG
9 ) -- %
; &;.5A%& %& $ 9; H 5/ 0G
3 )
6 & 7$-& > .E0
6 & ; L% .CF0 2
A%& %& $ H
3 )
6 & 7$-& > .E0
6 & ; L% .CF0 108" 2
A%& %& $ H
(a) A program for calculating the turning radius of the aircraft is shown below:
27
© 2018 Cengage Learning®. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
9 ? $ $; 7 $
9 # & < $> "" # & $ $; ! >
9
9 8 8 : @ ! " A > - $
9
9 # ; 7 4-
9 > ' - & $ .>0
9 > 7 ( - & $ $; > 7 & . "8 0
9 " ! : $; $% . "8 0
9 % )% > % ."0
9 ( ;& ' !
9 D & - 7 -%
> 7 G
" ! G
9 - %- & %
% . K " ! 0 B 8 . > K > 7 0G
9 ) -- %
; &;.5)% > % 9; " 5/ % 0G
/
6 & .' !0 0%"
6 & " - & $ .>0
)% > % "
(b) When this program is executed with the new speed, the results are:
/
6 & .' !0 0"
6 & " - & $ .>0
)% > % "
(c) A program to plot the turning radius as a function of speed for a constant max acceleration is
shown below:
28
© 2018 Cengage Learning®. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
9 ? $ $; 7 $
9 # & < $> "" # & $ $; ! >
9
9 8 8 : @ ! " A > - $
9
9 # ; 7 4-
9 > ' - & $ .>0
9 > 7 ( - & $ $; > 7 & . "8 0
9 " ! : $; $% . "8 0
9 " M ' "%" ' ! %"4
9 " M ' "%" ' ! %"4
9 % )% > % ."0
9 ( ;& ' !
9 D & - 7 -%
> 7 G
" ! G
9 - %- & > $;
" M ." M " M 08 " M G
9 - %- & %
% . K " ! 0 B 8 . > K > 7 0G
/
6 & " .' !0 10"
6 & " .' !0 01
6 & " - & $ .>0
29
© 2018 Cengage Learning®. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
/
6 & .' !0 0"
6 & " - & $ .>0 3
)% > % "
(e) A program to plot the turning radius as a function of centripetal acceleration is shown below:
30
© 2018 Cengage Learning®. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
9 D & - 7 -%
> 7 G
" ! G
9 - %- & %
% . K " ! 0 B 8 . > K > 7 0G
/
6 & .' !0 10%"
6 & " - & $ .>0
6 & " - & $ .>0 %
31
© 2018 Cengage Learning®. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
32
© 2018 Cengage Learning®. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.