11> module NewtonianMechanics.SingleParticle where
22
3- > import Calculus.SyntaxTree
3+ < import Calculus.SyntaxTree
4+
45> import Test.QuickCheck
56
67Laws:
78
89- A body remains at rest or in uniform motion unless acted upon by a force.
9- - A body acted upon by a force moves in such a manner that the time rate of change of the momentum equals the force.
1010- If two bodies exert forces on each other, these forces are equal in magnitude and opposite in direction.
1111
1212We will begin our journey into classical mechanics by studying point particles.
@@ -19,7 +19,7 @@ position in each dimension, x, y, and z. Since we've already defined vectors and
1919mathmatical functions in previous chapters we won't spend any time on them here
2020and instead just import those two modules.
2121
22- > import Calculus.Calculus
22+ > import Calculus
2323> import Vector.Vector as V
2424
2525 The mass of a particle is just a numerical value so we'll model it using
@@ -49,6 +49,8 @@ of function expressions. So our data type is simply:
4949
5050So now we can create our particles! Let's try it out!
5151
52+ **TODO: IMPLEMENT NUM INSTANCE FOR FunExpr AND REWRITE**
53+
5254`` `
5355ghci > let particle = P (V3 (3 :* Id :* Id) (2 :* Id) 1) 3
5456ghci > particle
@@ -64,10 +66,10 @@ Velocity & Acceleration
6466------------------
6567
6668Velocity is defined as the derivative of the position with respect to time. More
67- formally:
69+ formally, ( $ \vec {r} $ denotes the position vector) :
6870
6971\begin {equation* }
70- \vec {v} = \frac {d\vec {p }}{dt}
72+ \vec {v} = \frac {d\vec {r }}{dt}
7173\end {equation* }
7274
7375And since the position of our particles are given as vectors we'll do the
@@ -86,54 +88,87 @@ Acceleration is defined as the derivative of the velocity with respect to time,
8688or the second derivative of the position. More formally:
8789
8890\begin {equation* }
89- \vec {a} = \frac {d\vec {v}}{dt} = \frac {d^2\vec {p }}{dt^2}
91+ \vec {a} = \frac {d\vec {v}}{dt} = \frac {d^2\vec {r }}{dt^2}
9092\end {equation* }
9193
9294**Exercise** Try to figure out how to define the function for calculating the
93- acceleration of a particle
95+ acceleration of a particle.
96+
97+ <details>
98+ <summary>
99+ **Solution**
100+ </summary>
101+
102+ We already know how to get the velocity of a particle, so the the
103+ only step we need to take is to take the derivative of the velocity.
104+
105+ < acceleration :: Particle -> VectorE
106+ < acceleration = vmap D . velocity
107+
108+ Which is the same as:
109+
110+ < acceleration :: Particle -> VectorE
111+ < acceleration = vmap D . vmap D . pos
112+
113+ <details>
114+ <summary>
115+ **Trivia**
116+ </summary>
117+
118+ Those of you familiar with functor laws will probably see that the code
119+ for calculating the acceleration could also be written as:
120+
121+ > acceleration :: Particle -> VectorE
122+ > acceleration = vmap (D . D ) . pos
123+
124+ </details>
125+ </details>
94126
95127Forces & Newton's second law
96128------------------------------
97129
130+ Newton's second law states that
131+ <blockquote>
132+ A body acted upon by a force moves in such a manner that the time rate of change
133+ of the momentum equals the force.
134+ </blockquote>
135+
98136This law expresses the relationship between force and momentum and is
99- as follows:
137+ mathematically defined as follows:
138+
100139\begin {equation }
101140 \vec {F} = \frac {d \vec {p}}{d t} = \frac {d(m \cdot \vec {v})}{d t}
102141\end {equation }
103142
104-
105-
106- The quantity $ m \cdot v$ is what we mean when we say momentum. So the law
143+ The quantity $ m \cdot \vec {v}$ is what we mean when we say momentum. So the law
107144states that the net force on a particle is equal to the rate of change of the
108- momentum with respect to time. And since the definition of acceleration is $ a =
109- \frac {d \vec {v}}{d t}$ we can write this law in a more familiar form, namely:
145+ momentum with respect to time. And since the definition of acceleration is
146+ $ \vec {a} = \frac {d \vec {v}}{d t}$ we can write this law in a more familiar form,
147+ namely:
110148
111149\begin {equation }
112150 \vec {F} = m \cdot \vec {a}
113151\end {equation }
114152
115- And thus if the particle is accelerating we can calculate the net force that
153+ And thus if the particle is accelerating we can calculate the force that
116154must be acting on it, in code this would be:
117155
118156
119- > force :: Particle -> VectorE
120- > force p = vmap (* m) a
121- > where
122- > m = mass p
123- > a = acceleration p
157+ < force :: Particle -> VectorE
158+ < force p = vmap (* m) a
159+ < where
160+ < m = mass p
161+ < a = acceleration p
124162
125163> type Energy = FunExpr
126164
127165Where the acceleration of particle is found by deriving the velocity of that
128166same particle with respect to $ t$ :
129167
130- > acceleration :: Particle -> VectorE
131- > acceleration = vmap D . velocity
132-
133168TODO: Write something here
134169
135- > square :: VectorE -> FunExpr
136- > square v = dotProd v v
170+ < square :: VectorE -> FunExpr
171+ < square v = dotProd v v
137172
138173Work and energy
139174---------------------
@@ -148,12 +183,12 @@ as the dot product of the force and the vector of displacement.
148183
149184where $ \Delta \vec {r} = \vec {r_2} - \vec {r_1}$ .
150185
151- > kineticEnergy :: Particle -> Energy
152- > kineticEnergy p = Const 0.5 * m * v2
153- > where
154- > m = mass p
155- > v = velocity p
156- > v2 = square v
186+ < kineticEnergy :: Particle -> Energy
187+ < kineticEnergy p = Const 0.5 * m * v2
188+ < where
189+ < m = mass p
190+ < v = velocity p
191+ < v2 = square v
157192
158193The work-energy theorem states that for a particle of constant mass *m*, the
159194total work *W* done on the particle as it moves from position $ r_1 $ to $ r_2 $ is
@@ -168,25 +203,25 @@ Let's codify this theorem:
168203PS: This used to work just fine, but it no longer does since the switch to
169204FunExpr. Problem probably lies somewhere in SyntaxTree
170205
171- > prop_WorkEnergyTheorem :: Mass -> VectorE -> VectorE -> IO Bool
172- > prop_WorkEnergyTheorem m v1 v2 = prettyEqual deltaEnergy (kineticEnergy displacedParticle)
173- > where
174- > particle1 = P v1 m -- | Two particles with the same mass
175- > particle2 = P v2 m -- | But different position vector
176- > -- | E_k,2 - E_k,1
177- > deltaEnergy = kineticEnergy particle2 - kineticEnergy particle1
178- > displacedParticle = P (v2 - v1) m
179-
180- > -- Test values
181- > v1 = V3 (3 :* Id ) (2 :* Id ) (1 :* Id )
182- > v2 = V3 0 0 (5 :* Id )
183- > v3 = V3 0 (3 :* Id ) 0 :: VectorE
184- > v4 = V3 2 2 2 :: VectorE
185- > m = 5
186- > p1 = P v1 m
187- > p2 = P v2 m
188- > dE = kineticEnergy p2 - kineticEnergy p1
189- > p3 = P (v2 - v1) m
206+ < prop_WorkEnergyTheorem :: Mass -> VectorE -> VectorE -> IO Bool
207+ < prop_WorkEnergyTheorem m v1 v2 = prettyEqual deltaEnergy (kineticEnergy displacedParticle)
208+ < where
209+ < particle1 = P v1 m -- | Two particles with the same mass
210+ < particle2 = P v2 m -- | But different position vector
211+ < -- | E_k,2 - E_k,1
212+ < deltaEnergy = kineticEnergy particle2 - kineticEnergy particle1
213+ < displacedParticle = P (v2 - v1) m
214+
215+ < -- Test values
216+ < v1 = V3 (3 :* Id ) (2 :* Id ) (1 :* Id )
217+ < v2 = V3 0 0 (5 :* Id )
218+ < v3 = V3 0 (3 :* Id ) 0 :: VectorE
219+ < v4 = V3 2 2 2 :: VectorE
220+ < m = 5
221+ < p1 = P v1 m
222+ < p2 = P v2 m
223+ < dE = kineticEnergy p2 - kineticEnergy p1
224+ < p3 = P (v2 - v1) m
190225
191226Law of universal gravitation
192227-------------------------------------
@@ -211,20 +246,20 @@ objects interacting, *r* is the distance between the centers of the masses and
211246The gravitational constant has been finely approximated through experiments
212247and we can state it in our code like this:
213248
214- > type Constant = FunExpr
215- >
216- > gravConst :: Constant
217- > gravConst = 6.674 * (10 ** (- 11 ))
249+ < type Constant = FunExpr
250+ <
251+ < gravConst :: Constant
252+ < gravConst = 6.674 * (10 ** (- 11 ))
218253
219254Now we can codify the law of universal gravitation using our definition
220255of particles.
221256
222- > lawOfUniversalGravitation :: Particle -> Particle -> FunExpr
223- > lawOfUniversalGravitation p1 p2 = gravConst * ((m_1 * m_2) / r2)
224- > where
225- > m_1 = mass p1
226- > m_2 = mass p2
227- > r2 = square $ pos p2 - pos p1
257+ < lawOfUniversalGravitation :: Particle -> Particle -> FunExpr
258+ < lawOfUniversalGravitation p1 p2 = gravConst * ((m_1 * m_2) / r2)
259+ < where
260+ < m_1 = mass p1
261+ < m_2 = mass p2
262+ < r2 = square $ pos p2 - pos p1
228263
229264If a particles position is defined as a vector representing its displacement
230265from some origin O, then its heigh should be x. Or maybe it should be the
0 commit comments