Merge branch 'master' of github.com:thomasabishop/computer_science

This commit is contained in:
thomasabishop 2022-08-30 09:36:24 +01:00
commit c5d152e2c4
10 changed files with 308 additions and 19 deletions

View file

@ -0,0 +1,85 @@
---
categories:
- Electronics
tags: [physics, electricity]
---
# Cells and batteries
Cells are a [voltage source](/Electronics/Physics_of_electricity/Voltage.md#chemicals-cells-and-batteries) that generate a difference of potential via a positive and negative electrode separated by an electrolytic solution. The electrolytes pull free electrons from one of the materials which creates a positive charge. The other material gains the free electrons creating a negative charge.
> A battery is a combination of two or more cells.
> Cells which cannot be recharged are called **primary cells**. Cells which can be recharged are called **secondary cells**.
## Connecting batteries
Cells and batteries can be connected to each other in electrical ciruits to increase the overall voltage and current that is produced. There are three main connection types:
- series
- parallel
- series-parallel
> The key thing to remember: **cells configured in series increases the overall voltage available** and **cells configured in parallel increases the overall current available**
The table below summarises the relative differences:
![](/img/cell-comparison.svg)
### Series connections
With series connections we distinguish **series aiding** and **series opposing** configurations.
In the case of **series aiding**, cells are connected one in front of another with the positive terminal connecting to the negative terminal of the other in a line.
In this configuration the same current flows through all the cells; it is not cumulative. We represent this as follows:
$$
I_{T} = I_{1} = I_{2} = I_{3}
$$
However the voltage is cumulative: it is the _sum_ of the individual cell voltages, represented below as [electrical field](/Electronics/Physics_of_electricity/Voltage.md#distinguishing-voltage-from-electric-field):
$$
E_{T} = E_{1} + E_{2} + E_{3} \\
$$
Thus series connections increase voltage but keep current constant.
_Series battery connection:_
![](/img/series-battery-diagram.svg)
_Can be represented in a circuit diagram in one of the following two ways: as a series of cells or as a single battery:_
![](/img/series-battcircuit.svg)
In the case of **series opposing**, negative terminals are connected to each other and positive terminals are connected to each other in a series. This doesn't have many applications.
### Parallel connections
In parallel connections all positive terminals are connected to each other and all negative terminals are connected to each other.
This time the voltage is the same as each individual cell but the current is the sum of the individual cell currents. So the voltage is constant but the current is cumulative:
$$
E_{T} = E_{1} = E_{2} = E_{3} \\
$$
$$
I_{T} = I_{1} + I_{2} + I_{3}
$$
_Parallel battery connection:_
![](/img/parallel-battery-diagram.svg)
_Parallel battery circuit diagram:_
![](/img/circ-batt-final.svg)
### Series-parrallel
If we want both a higher voltage and a higher current we can use series-parallel configurations. Connecting cells in series increases the voltage and connecting cells in parellel increases the current so doint both boosts the amount of both quantities.
// TODO: Add notes on series parallel once I have a better grasp of the basics of circuits.

9
Electronics/Circuits.md Normal file
View file

@ -0,0 +1,9 @@
---
categories:
- Electronics
tags: [electricity, circuits]
---
# Circuits
// TODO: Add much more simplified GCSE-level notes on what a circuit is

View file

@ -8,14 +8,15 @@ tags: [physics, electricity]
> Electrical current is the movement of electrons from negatively charged atoms to negatively charged atoms when an appropriate external force is applied.
So current is the flow of electrons. Charge is the quantity that flows.
So current is the flow of electrons. Charge is the quantity that flows.
> The amount of current is the sum of the charges of the moving electrons past a given point.
## Why current exists
Current exists because of the [first law of electrostatics](/Electronics/Physics_of_electricity/Coulombs_Law.md).
When there is an excess of electrons at one terminal (i.e. negatively charged atoms) and a deficiency of electrons at the other terminal (i.e. positively charged atoms), a _difference of potential_ exists between the two terminals.
When there is an excess of electrons at one terminal (i.e. negatively charged atoms) and a deficiency of electrons at the other terminal (i.e. positively charged atoms), a \*\*difference of potential\_ exists between the two terminals.
When the terminals are connected to each other via a conductor (e.g. copper wire) electrons will flow along the conductor. This is provided that there is a source to supply electrons at one end and remove them at the other. We call this force the **voltage source**.
@ -23,12 +24,14 @@ _The diagram below illustrates the flow of current where the circles are electro
![](/img/charge-cylinder.svg)
> Electrons travel very slowly through a conductor. This is in contrast to their intrinsic motion which of course equal to the speed of light (186, 000 miles per second).
## Formal expression
We measure **charge** in Coulombs ($C$). A Coulomb is an aggregate of the charge of thousands of electrons because their individual charge is so small.
One Coulomb is equal to the charge of $6.24 \cdot 10 ^{18}$ electrons.
One Coulomb is equal to the charge of $6.24 \cdot 10 ^{18}$ electrons.
We measure **current** in amps. When one coulomb of charge moves past a point in one second it is called an **ampere** (amp) represented as $A$.
We measure **current** in amps. When one coulomb of charge moves past a point in one second it is called an **ampere** (amp) represented as $A$.
This relationship is captured in the following equation:
@ -36,14 +39,15 @@ $$
I = \frac{Q}{t}
$$
* $I$ = current measured in amps
* $Q$ = quantity of electrical charge measured in coulombs
* $t$ = time
- $I$ = current measured in amps
- $Q$ = quantity of electrical charge measured in coulombs
- $t$ = time
### Application
_Calculate the current in amps if 9 coulombs of charge flow past a point in an electric circuit in 3 seconds._
$$
I = \frac{9}{3} \\
I = 3 A
$$
$$

View file

@ -0,0 +1,13 @@
---
categories:
- Electronics
tags: [physics, electricity, electromagnetism]
---
# Electromagnetism
For a long time electricity and magnetism were thought to be separate forces. In the 19th century Maxwell demonstrated that they were interrelated phenomena then Einstein proved with the Special Theory of Relativity that they are aspects of one unified phenomenon.
The core of the relationship is that a changing magnetic field produces an electric field and conversely, a changing electric field produces a magnetic field.
https://www.britannica.com/science/electromagnetism

View file

@ -9,17 +9,17 @@ tags: [physics, electricity, exponents]
In electronics we are often dealing with units that are very large or very small, thus we rely on [exponents](/Mathematics/Algebra/Exponents.md) for formal expression.
| Prefix | Symbol | Expression as exponent | Expression as decimal value |
|--------|--------|------------------------|-----------------------------|
| ------ | ------ | ---------------------- | --------------------------- |
| Giga- | G | $10^9$ | 1,000,000,000 |
| Mega- | M | $10^6$ | 1,000,000 |
| Kilo- | k | $10^3$ | 1,000 |
| Milli- | m | $10^{-3}$ | 0.001 |
| Micro- | $\mu$ | $10^{-6}$ | 0.0000001 |
| Nano- | n | $10^{-9}$ | 0.0000000001 |
| Pico- | p | $10^{-12}$ | 0.0000000000001 |
| Milli- | m | $10^{-3}$ | 0.001 |
| Micro- | $\mu$ | $10^{-6}$ | 0.0000001 |
| Nano- | n | $10^{-9}$ | 0.0000000001 |
| Pico- | p | $10^{-12}$ | 0.0000000000001 |
For example, with Amps we tend not to use 1 whole amp as this is far too large for most electronics. More common is the milliampere (mA) and the microampere ($\mu$A).
For example, with Amps we tend not to use 1 whole amp as this is far too large for most electronics. More common is the milliampere (mA) and the microampere ($\mu$A).
A mA is equal to one thousandth of an ampere: 0.001 A. It takes 1000 milliamperes to equal one ampere.
A $\mu$A is equal to one millionth of an ampere: 0.0000001 A. It takes one million micoramperes to equal one ampere.
A $\mu$A is equal to one millionth of an ampere: 0.0000001 A. It takes one million micoramperes to equal one ampere.

View file

@ -4,4 +4,109 @@ categories:
tags: [physics, electricity]
---
# Voltage
# Voltage
## Difference of potential and the tranfer of energy
We noted in the discussion of [current](/Electronics/Physics_of_electricity/Current.md) that current flows when there is difference of potential between two points with negatively charged atoms at one point and positively charged atoms at the other.
'Difference of potential' is the same thing as voltage. We use the term 'voltage' to denote the propensity for charge to flow from one place to another. Voltage is essential to current because it is the force that enables the current to flow.
## Distinguishing _voltage_ from _electric field_
Without voltage there can be no current because in their natural state, the electrons in an atom are in random motion with no direction. To produce a current, energy must be imparted to the electrons so that they all flow in the same direction.
Voltage is the application of this energy. Any form of energy that dislodges electrons from atoms can be used to produce current.
> It is important to realise that in this process energy is not 'created', rather there is a transfer of energy from one form to another. The force applied to generate the currThe Expanse Season 4
## Distinguishing _voltage_ from _electric field_
It can be confusing that two different symbols often seemed to be used interchangeably when talking about voltage: $V$ and $E$. However, while they broadly point to the same phenomenon there is a difference in emphasis.
- $V$ stands for volts or voltage conceived purely in terms of the difference in potential between two points: the positive and negative terminals
- $E$ stands for electric field. This is the field that surround each electric charge and exerts force on all other charges in the field, attracting or repelling them. So it is more the physical process that the volatage represents rather than the numerical representation of the potential between the terminals.
## Voltage sources
The following are the main sources of voltage:
- friction
- magnetism
- chemicals
- light
- heat
- pressure
Energy in these states can be transformed into energy as current. We will review the most common sources below.
### Magentism (electrical generators)
Magnetism is used the voltage source in electrical generators by far the most common method of producing powerful and large currents at scale.
If a conductive wire is passed through a magnetic field voltage will be produced so long as there is motion between the magnetic field and the conductor. A **generator** is a device that generates current in this manner. Generators themselves need to be powered. They can be powered by steam from a nuclear power plant, water, wind, coal or other fossil fuels.
The Expanse Season 4
#### AC/DC
Depending on how it is wired, a generator can produce **directed current** (DC) or **alternating current** (AC):
- **Directed current**
- The electrons flow in only one direction
- **Alternating current**
- The electrons flow in one direction and then the other
### Chemicals (cells and batteries)
The chemical creation of current is the physics behind [batteries](/Electronics/Cells_and_batteries.md). Chemical current production produces currents on a smaller and less industrial scale than generators.
A chemical cell consists in two dissimilar metals such as copper and zinc. We call these the **electrodes**. They are immersed in a salt, acid or alkaline solution. We call these the **electrolytes**. The electrolyte pulls the free electrons from the copper electrode which leaves it imbalanced with a positive charge. The zinc electrode attracts the free electrons from the electrolyte giving it a negative charge, thus a difference of potential is achieved.
### Light (photovoltaic cells)
Solar energy can be converted to electrical energy through solar panels which are large collections of **photovoltaic cells**.
When the surfaces of these cells are exposed to light, it dislodges electrons from their orbits around the surface atoms of the cell material. For each cell this only produces a very small amount of energy, therefore large quantities must be used.
## Voltage rise and voltage drops
In circuits there are actually two types of voltage:
1. Voltage rise
2. Voltage drop
### Voltage rise
When we introduce potential energy into a ciruit in the form of voltage, this is a voltage rise. The current flows from the negative terminal of the voltage source and returns to the positive terminal of the voltage source.
A 12V battery connected to a circuit gives it a voltage rise of 12 volts.
### Voltage drop
Voltage drop is the corrolary to voltage rise. It is the loss of energy that the electrons of the circuit current experience as a result of encountering resistance.
As they move through the circuit the electrons encounter a **load** which is what we call resistance to the flow of electrons. As they run into this, they give up their energy. The relinquishing of energy happens in the form of a conversion of electrical energy to heat. The amount lost is equal to the amount of energy imparted by the voltage rise.
> The voltage drop in a circuit equals the the voltage rise of the circuit because energy cannot be created or destroyed, only changed to another form. When a voltage rise is converted to a voltage drop we say that **the energy has been _consumed_ by the circuit**.
#### Examples
- If a 12V source is connected to a 12V lamp, the source supplies a 12V voltage rise and the lamp produces a 12V voltage drop.
- If two identical 6V lamps are connected in series to the same 12V source, each lamp produces a 6V drop for a total of 12 volts
- If two different lamps are connected in series to to a 12V source: a 3V and a 9V lamp, the 9V lamp produces a drop of 9V and the 3V lamp produces a drop of 3V. The sum of the voltage drops equals the voltage rise of 12 volts.
These examples demonstrate that the voltage rise: voltage drop ratio always evens out.
## Ground: zero potential
We use the term **ground** to refer to zero potential - the point at which there is no difference of potential (voltage) that could generate current.
We need ground to prevent electric shock from appliances and circuits. It keeps all devices at the same potential.
In domestic settings appliances are **earth grounded**. The name comes from the fact that all appliances will ultimately connect to the earth to neutralise potential. This means there can be no difference of potential between circuits.
In electronics ground doesn't refer to the specific appliance but is a concept of a zero reference point against which all voltages are measured. A measured voltage will be negative or positive with respect to ground. This said, all circuitry will also have a physical mechanism of discharging potential.
// TODO: Don't really understand this so return to with better explanation

View file

@ -0,0 +1,36 @@
---
categories:
- Linux
tags: [sytems-programming]
---
# Monitoring processes and resources
## Processor time and memory usage: `top`, `htop` etc
We can use [ps](/Programming_Languages/Shell_Scripting/Processes.md) to list the currently running processes but it does not provide much information about the resource metrics or how the process changes over time. We can use `top` to get more information.
`top` provides an interactive interface for the information that `ps` displays. It updates in real time and shows the most active processes based on the CPU time that they are utilising. You can also order by memory usage.
_Here I have pressed `u` to show only the processes associated with my user:_
![](/img/htop.png)
### Main commands
| Command | Action |
| ------- | ------------------------------- |
| -u | Show processes by selected user |
| M | Sort by memory usage |
| P | Sort by cumulative CPU usage |
| ? | View key and explanation |
## Files being used by active processes: `lsof`
`lsof` stands for _list open files_. It lists opened files and the processes using them. Without modifiers it outputs a huge amount of data. The best way to use it is to execute it against a specific PID. For example the below output gives me some useful info about which files VS Code is using:
![](/img/lsof.png)
## System calls: `strace`
A system call is when a process requests a service from the [kernel](/Operating_Systems/The_Kernel.md), for instance an I/O operation to memory. We can trace these system calls with `strace`.

View file

@ -17,6 +17,31 @@ The command in its most minimal application returns the following
7112 pts/2 00:00:00 ps
```
With the `-e` modifier we can list more processes:
```
PID TTY TIME CMD
1 ? 00:00:05 systemd
2 ? 00:00:00 kthreadd
3 ? 00:00:00 rcu_gp
4 ? 00:00:00 rcu_par_gp
5 ? 00:00:00 netns
7 ? 00:00:00 kworker/0:0H-events_highpri
9 ? 00:00:00 mm_percpu_wq
11 ? 00:00:00 rcu_tasks_kthread
12 ? 00:00:00 rcu_tasks_rude_kthread
13 ? 00:00:00 rcu_tasks_trace_kthread
14 ? 00:00:08 ksoftirqd/0
15 ? 00:03:20 rcu_preempt
16 ? 00:00:00 rcub/0
17 ? 00:00:00 migration/0
18 ? 00:00:00 idle_inject/0
20 ? 00:00:00 cpuhp/0
21 ? 00:00:00 cpuhp/1
22 ? 00:00:00 idle_inject/1
23 ? 00:00:00 migration/1
```
<dl>
<dt>pid</dt>
<dd>Process ID: every currently running process has a unique ID<dd>
@ -43,8 +68,9 @@ The command in its most minimal application returns the following
## Process termination
The general schema is: `kill [pid]`. This allows for process clean-up. If this doesn't succeed you can force with `KILL [pid]` which will terminate the process immediately but is obviously more risky.
The general schema is: `kill [pid]`. This allows for process clean-up. If this doesn't succeed you can force with `KILL [pid]` which will terminate the process immediately but is obviously more risky.
We can also start/stop processes with modifiers on `kill`:
* `kill -STOP pid`
* `kill -CONT pid`
- `kill -STOP pid`
- `kill -CONT pid`

11
markdown-styles.css Normal file
View file

@ -0,0 +1,11 @@
* {
font-family: 'Inter';
}
pre, code {
font-family: 'Liga Liberation Mono' !important;
}
code {
font-family: 'Liga Liberation Mono' !important;
}