-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathformulas.tex
More file actions
140 lines (113 loc) · 5.52 KB
/
formulas.tex
File metadata and controls
140 lines (113 loc) · 5.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
%\section{Computing with formulas}
The exercises in this chapter concern with programming of mathematical formulae,
and correspond to Chapter 2 in the book by Sundnes and Chapter 1 in the book by Langtangen.
\begin{Problem}{\textbf{Throw a ball}} \label{prob11}
%\addcontentsline{toc}{section}{Exercise 1.1: Throw a ball - \texttt{ball.py}}
\noindent When throwing a ball in the air, the position of the ball can be calculated using the acceleration of the ball. When neglecting air resistance, the acceleration will be the negative of the gravitational constant, $-g$. The height of the ball relative to its starting
point is
\begin{equation*}
y(t) = v_0t - \frac{1}{2}gt^2,
\end{equation*}
where $v_0$ is the initial velocity of the ball and $t$ is the time after the throw.
The ball reaches its maximum height at time
\begin{equation*}
t_{\text{max}} = \frac{v_0}{g}.
\end{equation*}
Write a program computing the maximum height of the ball, that is $y(t_{\text{max}})$,
when $v_0 = 8.2\mathrm{m/s}$ and $g = 9.81\mathrm{m/s^2}$. Print the result.
Filename: $\texttt{ball.py}$
\end{Problem}
\begin{Problem}{\textbf{Growth of a bank deposit}}\label{prob12}
Let $r$ be a bank’s interest rate in percent per year. An initial amount $P$ will then grow to
$$
A = P(1+r/100)^n
$$
after $n$ years. Write a program that computes how much money 1000 euros have
grown to after three years with 5 percent interest rate, and prints the amount in the terminal.
Filename: $\texttt{interest\_rate.py}$
\end{Problem}
\begin{Problem}{\textbf{Population growth}}\label{prob13}
%\addcontentsline{toc}{section}{Exercise 1.2: Population growth - \texttt{population.py}}
\noindent The growth of a population can often be described by a logistic function
\begin{equation*}
N(t) = \frac{B}{1 + C \exp{-kt}},
\end{equation*}
where $B$ is the carrying capacity of the species in the environment, i.e., the
maximum size of the population that the environment can sustain indefinitely.
The constant $k$ tells us something about how fast the population grows, while $C$ is given
by the initial conditions. Let us consider a bacterial colony where the carrying
capacity is $B = 50 000$, and $k = 0.2\mathrm{h^{-1}}$ (where $h$ is the unit of hours). The population is
$5000$ at $t = 0$. Use the initial condition to determine $C$
and write a program that finds the number of bacteria in the colony after $24$ hours.
Hint: To find $C$ you insert $t=0$ in the expression above, and solve the resulting
equation for $C$. This gives a formula for calculating $C$ as a function of $N$ and
$B$, and this formula can be used directly in your program.
Filename: $\texttt{population.py}$
\end{Problem}
\begin{Problem}{\textbf{Solve the quadratic equation}}\label{prob14}
%\addcontentsline{toc}{section}{Exercise 1.3: Solve the quadratic equation - \texttt{find\_roots.py}}
\noindent Given a quadratic equation
\begin{equation*}
ax^2 +bx + c = 0,
\end{equation*}
the two roots are
\begin{equation*}
x_1 = \frac{-b + \sqrt{b^2 - 4ac}}{2a}, \quad x_2 = \frac{-b - \sqrt{b^2 - 4ac}}{2a}.
\end{equation*}
Make a program evaluating the roots of
\begin{equation*}
6x^2 - 5x + 1 = 0.
\end{equation*}
Print out both roots with two decimals.
Filename: $\texttt{find\_roots.py}$
\end{Problem}
\begin{Problem}{\textbf{Forces in the hydrogen atom}}\label{prob15}
%\addcontentsline{toc}{section}{Exercise 1.4: Forces in the hydrogen atom - \texttt{hydrogen.py}}
\noindent There are two kinds of forces acting between the proton and the electron in the
hydrogen atom; Coulomb force and gravitational force. The Coulomb force can be
expressed as
\begin{equation*}
F_C = k_e \frac{e^2}{r^2},
\end{equation*}
where $k_e$ is Coulomb's constant, $e$ is the elementary charge, and $r$ is the
distance between the proton and the electron.
The gravitational force can be expressed as
\begin{equation*}
F_G = G\frac{m_pm_e}{r^2},
\end{equation*}
where $G$ is the gravitational constant, $m_p$ is the mass of the proton, $m_e$
is the mass of the electron, and $r$ is the distance between the particles.
We can use these expressions for $F_C$ and $F_G$ to illustrate the difference in
strength of these two forces, i.e., the electromagnetic force and gravitational force.
Use the values
$k_e = 9.0\cdot 10^9 \ \mathrm{Nm^2C^{-2}}$,
$e = 1.6\cdot 10^{-19} \ \mathrm{C}$, $G = 6.7\cdot 10^{-11} \ \mathrm{Nkg^{-2}m^2}$,
$m_p = 1.7\cdot 10^{-27} \ \mathrm{kg}$ and $m_e = 9.1 \cdot 10^{-31} \ \mathrm{kg}$.
You can take the distance between the proton and electron to be approximately
the Bohr radius $r = a_0 = 5.3\cdot 10^{-11} \ \mathrm{m}$.
Make a program that computes both the Coulomb force and the gravitational force
between the proton and the electron. Write out the forces in scientific notation
with one decimal in units of Newton $(\mathrm{N = kg m/s^2})$. Also print the
ratio between the two forces.
Filename: $\texttt{hydrogen.py}$
\end{Problem}
\begin{Problem}{\textbf{Type in program text}}\label{formulas_shapes}
\noindent Type the following program in your editor, save it to a file
\py{formulas_shapes.py} and run the program. If thes program does
not work, check that you have typed the code correctly.
\begin{python}
from math import pi
h = 5.0 # height
b = 2.0 # base
r = 1.5 # radius
area_para = h*b
print(f'The area of the parallelogram is {area_para:.3f}')
area_square = b**2
print(f'The area of the square is {area_square:g}')
area_circle = pi*r**2
print(f'The area of the circle is {area_circle:.3f}')
volume_cone = 1.0/3*pi*r**2*h
print('The volume of the cone is {volume_cone:.3f}')
\end{python}
Filename: $\texttt{formulas\_shapes.py}$
\end{Problem}