Matrix Applications: SVD & PCA

FIZ353 - Numerical Analysis | 20/11/2020

Emre S. Tasci emre.tasci@hacettepe.edu.tr

The spring "problem"

Consider an ideal spring attached to a body, on a frictionless surface. What else can we ask! Here is how it will look like:

In [1]:
import numpy as np
import matplotlib.pyplot as plt
In [2]:
k = 10 # N/m Spring constant
m = 1 # kg # Mass

A = 5 # cm - Amplitude
w = np.sqrt(k/m) # Frequency

N = 50 # Number of observations

t = np.linspace(0,20,N)
x = A*np.cos(w*t)
In [3]:
tt = np.linspace(0,20,1000)
xx = A*np.cos(w*tt)
plt.plot(tt,xx,"r-")

plt.plot(t,x,"ob")
plt.xlabel("t (s)")
plt.ylabel("x (m)")
plt.yticks(np.arange(-5,6))
plt.title("Position vs. Time")
plt.grid(axis='y')

plt.show()

So, the harmonic motion is obvious. But keep in mind that this is the position vs. time graph. If we were to record the motion of the body using a camera placed on top, we would observe something like:

In [4]:
plt.plot(np.zeros((N,1)),x,"ob")
plt.show()

Which, obviously, is just the projection of the "x vs. t" graph unto the x axis (do please verify that this is indeed the case).

In [5]:
## A print script to feed into CalcPlot3d -- Nevermind 8)
## (https://www.monroecc.edu/faculty/paulseeburger/calcnsf/CalcPlot3D/)
#for i in x:
#    print("    <point>\n        point=\"(%.4f,0,0)\"\n        color=\"rgb(0,0,255)\"\n        size=\"4\" \n        visible=\"true\"\n    </point>\n"%(i))

Go on and just play with the interactable plot below (obtained using CalcPlot3D's wonderful scripting options)

In [6]:
from IPython.display import HTML
HTML('<iframe frameborder="0" height="480px" src="https://c3d.libretexts.org/CalcPlot3D/dynamicFigure/'\
     +'index.html?type=point;point=(5.0000,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(1.3821,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-4.2359,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-3.7239,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(2.1771,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(4.9275,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(0.5470,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-4.6251,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-3.1040,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(2.9091,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(4.7123,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-0.3039,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-4.8803,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-2.3942,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(3.5567,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(4.3605,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-1.1460,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-4.9940,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-1.6149,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(4.1012,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(3.8823,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-1.9549,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-4.9631,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-0.7889,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(4.5269,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(3.2916,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-2.7072,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-4.7882,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(0.0600,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(4.8214,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(2.6055,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-3.3810,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-4.4747,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(0.9072,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(4.9762,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(1.8439,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-3.9568,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-4.0314,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(1.7280,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(4.9868,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(1.0289,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-4.4179,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-3.4713,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(2.4988,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(4.8528,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(0.1840,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-4.7511,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-2.8106,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(3.1972,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(4.5782,0,0);visible=true;color=rgb(0,0,255);size=4&type=window;hsrmode=3;nomidpts=true;anaglyph=-1;center=0,0,-1,1;focus=0,0,0,1;up=1,0,0,1;transparent=false;alpha=140;twoviews=false;unlinkviews=false;axisextension=0.7;xaxislabel=x;yaxislabel=y;zaxislabel=z;edgeson=true;faceson=false;showbox=false;showaxes=true;showticks=true;perspective=false;centerxpercent=0.5170894526034712;centerypercent=0.4912280701754386;rotationsteps=30;autospin=true;xygrid=false;yzgrid=false;xzgrid=false;gridsonbox=true;gridplanes=false;gridcolor=rgb(128,128,128);xmin=-5;xmax=5;ymin=-2;ymax=2;zmin=-2;zmax=2;xscale=1;yscale=1;zscale=1;zcmin=-4;zcmax=4;zoom=0.45;xscalefactor=1;yscalefactor=1;zscalefactor=1'\
     +' width="90%">')
Out[6]: