• Home
  • Textbooks
  • MATLAB Programming for Engineers
  • MATLAB Basics

MATLAB Programming for Engineers

Stephen J.Chapman

Chapter 2

MATLAB Basics - all with Video Answers

Educators


Chapter Questions

01:36

Problem 1

Answer the following questions for the array shown below.
$$
\text { array } 1=\left[\begin{array}{rrrrr}
1.1 & 0.0 & 2.1 & -3.5 & 6.0 \\
0.0 & 1.1 & -6.6 & 2.8 & 3.4 \\
2.1 & 0.1 & 0.3 & -0.4 & 1.3 \\
-1.4 & 5.1 & 0.0 & 1.1 & 0.0
\end{array}\right]
$$
a. What is the size of array2?
b. What is the value of array $1(4,2)$ ?
c. What is the size and value of array $1(:, 2: 2)$ ?
d. What is the size and value of array $1([13]$, end) ?

James Kiss
James Kiss
Numerade Educator
02:41

Problem 2

Are the following MATLAB variable names legal or illegal? Why?
a. dog1
b. $1 \mathrm{dog}$
c. Do you_know_the_way_to_san_jose
d. help
e. What's_up?

Jeff Vermeire
Jeff Vermeire
Numerade Educator
02:00

Problem 3

Determine the size and contents of the following arrays. Note that ti later arrays may depend on the definitions of arrays defined earlier this exercise.
a. $a=1: 2: 5$;
b. $\mathrm{b}=\left\{\mathrm{a}^{\prime} \mathrm{a}^{*} \mathrm{a}^{*} 1\right.$;
c. $c=b(1: 2: 3,1: 2: 3)$;
d. $d=a+b(2,1)=$
c. $w=$ [zeros $(1,3)$ ones $(3,1)+3: 5,1$,
f. $b([1] 3], 2)=b([3] 1], 2)=$

Kyle Christian
Kyle Christian
Numerade Educator
00:37

Problem 4

Assume that array arrayl is defined as shown, and determine the contents of the following sub-arrays.
$\operatorname{array} 1=\left[\begin{array}{rrrrr}1.1 & 0.0 & 2.1 & -3.5 & 6.0 \\ 0.0 & 1.1 & -6.6 & 2.8 & 3.4 \\ 2.1 & 0.1 & 0.3 & -0.4 & 1.3 \\ -1.4 & 5.2 & 0.0 & 1.1 & 0.0\end{array}\right]$
a. array $1(3, t)$
b. array $1(:, 3)$
c. array $1\left(1: 2: 3,\left[\begin{array}{lll}3 & 3 & 4\end{array}\right]\right)$
d. array $\left.1\left(\begin{array}{ll}1 & 1\end{array}\right], 4\right)$

Kyle Christian
Kyle Christian
Numerade Educator
02:01

Problem 5

Assume that value has been initialized to $10 \pi$, and determine what is printed out by each of the following statements.

Erika Bustos
Erika Bustos
Numerade Educator
03:31

Problem 6

Assume that $a, b, c$, and $a$ are defined as follows, and calculate the results of the following operations if they are legal. If an operation is itlegal, explain why it is illegal.
$$
\begin{array}{ll}
a=\left[\begin{array}{rr}
2 & -2 \\
-1 & 2
\end{array}\right] & b=\left[\begin{array}{rr}
1 & -1 \\
0 & 2
\end{array}\right] \\
c=\left[\begin{array}{r}
1 \\
-2
\end{array}\right] & d=\text { eye }(2)
\end{array}
$$
a. result $=a+b$;
b. result $=a * d t$
c. result $=a \cdot d$ i
d. result $=a \cdot c$ z
e. reault $=a \cdot * c$ ?
f. result $=a \backslash b$;
g. result $=a .1 \mathrm{~b}$ :
h. result $=a \cdot A \mathrm{~b}$;

Adarsh Kumar
Adarsh Kumar
Numerade Educator
01:58

Problem 7

Evaluate each of the following expressions.
a. $11 / 5+6$
b. $(11,5)+6$
c. $11 /(5+6)$
d. $3 \wedge 2 \wedge 3$
e. 3 A $(2 \times 3)$
f. $(3=2) \neq 3$
g. round $(-11 / 5)+6$
h. $\operatorname{cesin}(-11 / 5)+6$
i. Eloor $(-11 / 5)+6$

Julian Wong
Julian Wong
Numerade Educator
View

Problem 8

Use MATLAB to evaluate each of the following expressions.
a. $(3-5 i)(-4+6 i)$
b. $\cos ^{-1}(1.2)$

Sarah Parrigin
Sarah Parrigin
Numerade Educator
01:21

Problem 9

Solve the following system of simultaneous equations for $x$. $\begin{aligned}-2.0 x_{1}+5.0 x_{2}+1.0 x_{3}+3.0 x_{4}+4.0 x_{5}-1.0 x_{6}=0.0 \\ 2.0 x_{1}-1.0 x_{2}-5.0 x_{3}-2.0 x_{4}+6.0 x_{5}+4.0 x_{6}=& 1.0 \\-1.0 x_{1}+6.0 x_{2}-4.0 x_{3}-5.0 x_{4}+3.0 x_{5}-1.0 x_{6}=&-6.0 \\ 4.0 x_{1}+3.0 x_{2}-6.0 x_{3}-5.0 x_{4}-2.0 x_{5}-2.0 x_{6}=10.0 \\-3.0 x_{1}+6.0 x_{2}+4.0 x_{3}+2.0 x_{4}-6.0 x_{5}+4.0 x_{6}=&-6.0 \\ 2.0 x_{1}+4.0 x_{2}+4.0 x_{3}+4.0 x_{4}+5.0 x_{5}-4.0 x_{6}=&-2.0 \end{aligned}$

Weston Bell-Geddes
Weston Bell-Geddes
Numerade Educator
00:08

Problem 10

Position and Velocity of a Ball. If a stationary ball is released at a height $h_{o}$ above the surface of the Earth with a vertical velocity $v_{o}$, the position and velocity of the ball as a function of time will be given by the equations
$$
\begin{gathered}
h(t)=\frac{1}{2} g t^{2}+v_{0} t+h_{0} \\
v(t)=g t+v_{0}
\end{gathered}
$$
where $g$ is the acceleration due to gravity $\left(-9.81 \mathrm{~m} / \mathrm{s}^{2}\right), h$ is the height above the surface of the Earth (assuming no air friction), and $v$ is the vertical component of velocity. Write a MATLAB program that prompts a user for the initial height of the ball in meters and velocity of the ball in meters per second, and plots the height and velocity as a function of time. Be sure to include proper labels in your plots.

Stanley Enemuo
Stanley Enemuo
Numerade Educator
05:17

Problem 11

The distance between two points $(x 1, y 1)$ and $(x 2, y 2)$ on a Cartesian coordinate plane is given by the equation
$$
d=\sqrt{\left(x l-x^{2}\right)^{2}+(y l-y 2)^{2}}
$$
Write a program to calculate the distance between any two points $(x 1, y 1)$ and $(x 2, y 2)$ specified by the user. Use good programming practices in your program. Use the program to calculate the distance between the points $(2,3)$ and $(8,-5)$.

Harriet O'Brien
Harriet O'Brien
Numerade Educator
01:28

Problem 12

Decibels. Engineers often measure the ratio of two power measurements in decibels, or $\mathrm{dB}$. The equation for the ratio of two power measurements in decibels is
$$
\mathrm{dB}=10 \log _{10} \frac{P_{2}}{P_{1}}
$$
where $P_{2}$ is the power level being measured, and $P_{1}$ is some reference power level.
a. Assume that the reference power level $P_{1}$ is I milliwatt, and write a program that accepts an input power $P_{2}$ and converts it into $\mathrm{dB}$ with respect to the $1 \mathrm{~mW}$ reference level. (Engineers have a special unit for dB power levels with respect to a $1 \mathrm{~mW}$ reference: $\mathrm{dBm}$.) Use good programming practices in your program.
b. Write a program that creates a plot of power in watts versus power in $\mathrm{dBm}$ with respect to a $1 \mathrm{~mW}$ reference level. Create both a linear $x y$ plot and a log-linear $x y$ plot.

Kader Bayar
Kader Bayar
Numerade Educator
02:40

Problem 13

Hyperbolic cosine. The hyperbolic cosine function is defined by the equation
$$
\cosh x=\frac{e^{x}+e^{-x}}{2}
$$
Write a program to calculate the hyperbolic cosine of a user-supplied value $x$. Use the program to calculate the hyperbolic cosine of $3.0$. Compare the answer that your program produces to the answer produced by the MATLAB intrinsic function cosh $(x)$. Also, use MATLAB to plot the function $\cosh (x)$. What is the smallest value that this function can have? At what value of $x$ does it occur?

Joseph Lentino
Joseph Lentino
Numerade Educator
03:34

Problem 14

Energy Stored in a Spring. The force required to compress a linear spring is given by the equation
$$
F=k x
$$
where $F$ is the force in newtons and $k$ is the spring constant in newtons per meter. The potential energy stored in the compressed spring is given by the equation
$$
E=\frac{1}{2} k x^{2}
$$
where $E$ is the energy in joules. The following information is available for four springs.

Eric Mockensturm
Eric Mockensturm
Numerade Educator
03:45

Problem 15

Radio Receiver. A simplified version of the front end of an AM radio receiver is shown in Figure 2.13. This receiver consists of an $R L C$ tuned circuit containing a resistor, capacitor, and an inductor connected in series. The RLC circuit is connected to an external antenna and ground as shown in the figure.

The tuned circuit allows the radio to select a specific station out of all the stations transmitting on the AM band. At the resonant frequency of the circuit, essentially all of the signal $V_{0}$ appearing at the antenna appears across the resistor, which represents the rest of the radio. In other words, the radio receives its strongest signal at the resonant frequency. The resonant frequency of the LC circuit is given by the equation
$$
f_{0}=\frac{1}{2 \pi \sqrt{L C}}
$$
where $L$ is inductance in henrys (H) and $C$ is capacitance in farads (F). Write a program that calculates the resonant frequency of this radio set given specific values of $L$ and $C$. Test your program by calculating the frequency of the radio when $L=0.1 \mathrm{mH}$ and $C=0.25 \mathrm{nF}$.

Kajal Gautam
Kajal Gautam
Numerade Educator
14:29

Problem 16

Radio Receiver. The voltage across the resistive load in Figure $2.13$ varies as a function of frequency according to Equation (2.18).
$$
V_{R}=\frac{R}{\sqrt{R^{2}+\left(\omega L-\frac{1}{\omega C}\right)^{2}}} V_{\theta}
$$
where $\omega=2 \pi f$ and $f$ is the frequency in hertz. Assume that $L=0.1 \mathrm{mH}$, $C=0.25 \mathrm{nF}, R=50 \Omega$, and $V_{O}=10 \mathrm{mV}$. a. Plot the voltage on the resistive load as a function of frequency. At what frequency does the voltage on the resistive load peak? What is the voltage on the load at this frequency? This frequency is called the resonant frequency $f_{0}$ of the circuit.
b. If the frequency is changed to $10 \%$ greater than the resonant frequency, what is the voltage on the load? How selective is this radio receiver?
c. At what frequencies will the voltage on the load drop to half of the voltage at the resonant frequency?

Sheh Lit Chang
Sheh Lit Chang
University of Washington
02:23

Problem 17

Suppose two signals were received at the antenna of the radio receiver described in the previous problem. One signal has a strength of I V at a frequency of $1000 \mathrm{kHz}$, and the other signal has a strength of $1 \mathrm{~V}$ at $950 \mathrm{kHz}$. How much power will the first signal supply to the resistive load $R$ ? How much power will the second signal supply to the resistive load $R$ ? Express the ratio of the power supplied by signal I to the power supplied by signal 2 in decibels. How much is the second signal enhanced or suppressed compared to the first signal?

Rylie Howey
Rylie Howey
Numerade Educator
05:14

Problem 18

Aireraft Turning Radius. An object moving in a circular path at a constant tangential velocity $v$ is shown in Figure 2.14. The radial acceleration required for the object to move in the circular path is given by the equation
$$
a=\frac{v^{2}}{r}
$$
where $a$ is the centripetal accelenation of the object in $\mathrm{m} / \mathrm{s}^{2}, v$ is the tangential velocity of the object in $\mathrm{m} / \mathrm{s}$, and $r$ is the turning radius in meters. Suppose that the object is an aircraft, and answer the following questions about it:
a. Suppose that the aircraft is moving at Mach $0.85$, or $85 \%$ of the speed of sound. If the centripetal acceleration is $2 \mathrm{~g}$, what is the turning radius of the aircraft? (Note: For this problem, you may assume that Mach 1 is equal to $340 \mathrm{~m} / \mathrm{s}$, and that $1 \mathrm{~g}=9.81 \mathrm{~m} / \mathrm{s}^{2}$.)
b. Suppose that the speed of the aircraft increases to Mach 1.5. What is the turning radius of the aircraft now?
c. Plot the turning radius as a function of aircraft speed for speeds between Mach $0.5$ and Mach 2.0, assuming that the accelention remains $2 \mathrm{~g}$.
d. Suppose that the maximum acceleration that the pilot can stand is $7 \mathrm{~g}$. What is the minimum possible turning radius of the aircraft at Mach 1.5?
e. Plot the turning radius as a function of centripetal acceleration for accelerations between $2 \mathrm{~g}$ and $8 \mathrm{~g}$, assuming a constant speed of Mach $0.85$.

Donald Albin
Donald Albin
Numerade Educator