Chapter 6: Problem 7
Imagine that a GPS device measures your position at every \(s\) seconds. The positions are stored as \((x, y)\) coordinates in a file src/files/pos.dat with the an \(x\) and \(y\) number on each line, except for the first line which contains the value of \(s\). First, load \(s\) into a float variable and the \(x\) and \(y\) numbers into two arrays and draw a straight line between the points (i.e., plot the \(y\) coordinates versus the \(x\) coordinates). The next task is to compute and plot the velocity of the movements. If \(x(t)\) and \(y(t)\) are the coordinates of the positions as a function of time, we have that the velocity in \(x\) direction is \(v_{x}(t)=d x / d t\), and the velocity in \(y\) direction is \(v_{y}=d y / d t .\) Since \(x\) and \(y\) are only known for some discrete times, \(t_{k}=k s, k=0, \ldots, n-1\), we must use numerical differentation. A simple (forward) formula is \(v_{x}\left(t_{k}\right) \approx \frac{x\left(t_{k+1}\right)-x\left(t_{k}\right)}{s}, \quad v_{y}\left(t_{k}\right) \approx \frac{y\left(t_{k+1}\right)-y\left(t_{k}\right)}{s}, \quad k=0, \ldots, n-2\) Compute arrays vx and vy with velocities based on the formulas above for \(v_{x}\left(t_{k}\right)\) and \(v_{y}\left(t_{k}\right), k=0, \ldots, n-2 .\) Plot vx versus time and vy versus time. Name of program file: position2velocity.py.
Short Answer
Step by step solution
Key Concepts
These are the key concepts you need to understand to accurately answer the question.