• Home
  • Textbooks
  • Computer science with Mathematica: theory and practice for science, mathematics, and engineering
  • Operations on Vectors and Matrices

Computer science with Mathematica: theory and practice for science, mathematics, and engineering

Roman Maeder

Chapter 8

Operations on Vectors and Matrices - all with Video Answers

Educators


Chapter Questions

00:58

Problem 1

Give the result of evaluating the following expressions. If there are any nested functions, also give the most important intermediate steps. Assume that each example is evaluated in a fresh Mathematica session. Consecutive expressions in one example are evaluated one after another in the same session.
1. $\mathrm{p}\left[\mathrm{x}_{-}, \mathrm{y}_{-}\right.$Integer $]:=\mathrm{x} \wedge(\mathrm{y}-1)$
Thread $[\mathrm{p}[1.1,\{1,2,3.5\}]]$
2. $\mathrm{m}=\{\{\mathrm{a} 11, \mathrm{a} 12, \mathrm{a} 13\},\{\mathrm{a} 21, \mathrm{a} 22, \mathrm{a} 23\},\{\mathrm{a} 31, \mathrm{a} 32, \mathrm{a} 33\}\}$;
Rest [ Transpose[ Rest [ Transpose[m] ] ] ]
3. Inner[Power, $\{a, b, c\},\{x, y, z\}$, Times]
4. $\operatorname{Duter}[D,\{x-y, x y\},\{x, y\}]$
5. Inner [ List, $\{\mathrm{a}, \mathrm{b}\},\{\mathrm{x}, \mathrm{y}\}$, Dot $]$

AG
Ankit Gupta
Numerade Educator

Problem 2

Write a function split [list, $s]$ that takes two lists as arguments. The first list, list, is any list, the second list, $s$, is a list of nonnegative integers. The result should be the partitioning of the first list into sublists whose lengths are given by the elements of $s$ in turn.
(Table Cant Copy)
This partitioning is possible only if the sum of the elements of $s$ is equal to the length of list. Formally, the result of
$$
\operatorname{split}\left[\left\{e_1, e_2, \ldots, e_n\right\},\left\{s_1, s_2, \ldots, s_m\right\}\right]
$$
is equal to
$$
\left\{\left\{e_1, \ldots, e_{s_1}\right\},\left\{e_{s_1+1}, \ldots, e_{s_1+s_2}\right\}, \ldots,\left\{e_{s_1+\ldots+s_{m-1}+1}, \ldots, e_{s_1+\ldots+s_m}\right\}\right\},
$$
with $n=s_1+\ldots+s_m$.

Check back soon!
08:54

Problem 3

Write a function Maxima[llst $]$ that finds all numbers in the list list that are larger than all preceding numbers in the list.
The result $1 \mathrm{~s}$ a hist of all those elements of the list that are larger than all preceding ones
$$
\begin{aligned}
& \operatorname{In}[3]:=\operatorname{Max} 1 \mathrm{ma}[\{4,7,5,2,7,9,1\}] \\
& \operatorname{Out}[3]=\operatorname{Max} 1 \mathrm{ma}[\{4,7,5,2,7,9,1\}]
\end{aligned}
$$

Tarandeep Singh
Tarandeep Singh
Numerade Educator
04:31

Problem 4

Write a function that counts how often each of the numbers $1 \ldots n$ occurs in a list of positive numbers. The result should be a list of frequencies $\left\{f_1, f_2, \ldots, f_n\right\}$, where $f_2$ is the number of occurrences of $i$, and $n$ is the largest number occurring in the list.
In this example, the number 1 occurs once, 2 does not occur at all, 3 occurs three times, and so on.
$$
\begin{aligned}
& \text { In }[4]:=\text { Prequencies }[\{1,3,3,4,3,5\}] \\
& \text { Out }[4]=\{1,0,3,1,1\}
\end{aligned}
$$

Bryan Lynn
Bryan Lynn
Numerade Educator

Problem 5

The run-length coding of a list $l$ is a list of pairs
$$
r=\left\{\left\{e_1, k_1\right\},\left\{e_2, k_2\right\}, .\left\{e_m, k_m\right\}\right\} .
$$
The $e_{\imath}$ are any expressions, the $k_{\imath}$ are integers $\geq 1$, and $m \geq 0$. The list $r$ describes (encodes) the list
$$
l=\{\underbrace{e_1, e_1, \ldots, e_1}_{k_1}, \underbrace{e_2, e_2, \ldots, e_2}_{k_2}, \ldots, \underbrace{e_m, e_m, \ldots e_m}_{k_m}\} .
$$
where each element $e_{\imath}$ occurs exactly $k_{\imath}$ times in sequence. If the list $l$ contains many repetitions of elements, the run-length coding is a short description of $l$.
Write a function RunLength $[l]$ that finds the run-length coding of $l$.
(Table Cant Copy)

Check back soon!
01:29

Problem 6

Modify the program for the solution of linear systems of equations Linalg.m such that pivots are searched in a column. Choose the element with the largest absolute value. See page 185 .

Jocelyn Shackelford
Jocelyn Shackelford
Numerade Educator

Problem 7

The circuit shown on the left is an inverting amplifier. Compute the voltage gain $A_v=V_o / V_i$ (see also Section 1.1.4).
The solution is valid also for arbitrary impedances instead of the resistors $R_1$ and $R_2$. Plot the frequency response for $R_1=C=2.0 \mu \mathrm{F}$ and $R_2=100 \Omega$.
(Figure Cant Copy)

Check back soon!