<commit_before>{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/ash/anaconda2/envs/python3/lib/python3.5/site-packages/IPython/extensions/sympyprinting.py:31: UserWarning: The sympyprinting extension has moved to `sympy`, use `from sympy import init_printing; init_printing()`\n",
      "  warnings.warn(\"The sympyprinting extension has moved to `sympy`, \"\n"
     ]
    }
   ],
   "source": [
    "%load_ext sympyprinting\n",
    "%matplotlib inline\n",
    "import matplotlib.pyplot as plt\n",
    "import sympy\n",
    "from IPython.display import display\n",
    "sympy.init_printing(use_unicode=False, wrap_line=False, no_global=True)\n",
    "import scipy.constants\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Equation of motion - SDE to be solved"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### $\\ddot{q}(t) + \\Gamma_0\\dot{q}(t) + \\Omega_0^2 q(t) -  \\dfrac{1}{m} F(t) = 0 $\n",
    "\n",
    "#### where q = x, y or z\n",
    "\n",
    "Where $F(t) = \\mathcal{F}_{fluct}(t) + F_{feedback}(t)$\n",
    "\n",
    "Taken from page 46 of 'Dynamics of optically levitated nanoparticles in high vacuum' - Thesis by <NAME> "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Using $\\mathcal{F}_{fluct}(t) = \\sqrt{2mΓ_0 k_B T_0}\\dfrac{dW(t)}{dt}$\n",
    "\n",
    "and $F_{feedback}(t) = \\Omega_0 \\eta q^2 \\dot{q}$\n",
    "\n",
    "Taken from page 49 of 'Dynamics of optically levitated nanoparticles in high vacuum' - Thesis by <NAME> \n",
    "\n",
    "we get the following SDE:"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$\\dfrac{d^2q(t)}{dt^2} + (\\Gamma_0 - \\Omega_0 \\eta q(t)^2)\\dfrac{dq(t)}{dt} + \\Omega_0^2 q(t) - \\sqrt{\\dfrac{2\\Gamma_0 k_B T_0}{m}} \\dfrac{dW(t)}{dt} = 0$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "split into 2 first order ODE/SDE s"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "letting $v = \\dfrac{dq}{dt}$\n",
    "\n",
    "$\\dfrac{dv(t)}{dt} + (\\Gamma_0 - \\Omega_0 \\eta q(t)^2)v + \\Omega_0^2 q(t) - \\sqrt{\\dfrac{2\\Gamma_0 k_B T_0}{m}} \\dfrac{dW(t)}{dt} = 0$\n",
    "\n",
    "therefore\n",
    "\n",
    "$\\dfrac{dv(t)}{dt} = -(\\Gamma_0 - \\Omega_0 \\eta q(t)^2)v - \\Omega_0^2 q(t) + \\sqrt{\\dfrac{2\\Gamma_0 k_B T_0}{m}} \\dfrac{dW(t)}{dt} $\n",
    "\n",
    "$v = \\dfrac{dq}{dt}$ therefore $dq = v~dt$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\\begin{align}\n",
    "dq&=v\\,dt\\\\\n",
    "dv&=[-(Γ_0−Ω_0ηq(t)^2)p - Ω^2_0v(t)]\\,dt + \\sqrt{\\frac{2Γ_0k_BT_0}m}\\,dW\n",
    "\\end{align}\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Apply Milstein Method to solve"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Consider the autonomous Itō stochastic differential equation\n",
    "\n",
    "${\\mathrm  {d}}X_{t}=a(X_{t})\\,{\\mathrm  {d}}t+b(X_{t})\\,{\\mathrm  {d}}W_{t}$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Taking $X_t = q_t$ for the 1st equation above (i.e. $dq = v~dt$) we get:\n",
    "\n",
    "$$ a(q_t) = v $$\n",
    "$$ b(q_t) = 0 $$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Taking $X_t = v_t$ for the 2nd equation above (i.e. $dv = ...$) we get:\n",
    "\n",
    "$$a(v_t) = -(\\Gamma_0−\\Omega_0\\eta q(t)^2)v - \\Omega_0^2 q(t)$$ \n",
    "$$b(v_t) = \\sqrt{\\dfrac{2\\Gamma_0 k_B T_0}m}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "${\\displaystyle b'(v_{t})=0}$ therefore the diffusion term does not depend on ${\\displaystyle v_{t}}$ , the Milstein's method in this case is therefore equivalent to the Euler–Maruyama method."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We then construct these functions in python:"
   ]<commit_msg>fixed unknown chars in notebook<commit_after>{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/ash/anaconda2/envs/python3/lib/python3.5/site-packages/IPython/extensions/sympyprinting.py:31: UserWarning: The sympyprinting extension has moved to `sympy`, use `from sympy import init_printing; init_printing()`\n",
      "  warnings.warn(\"The sympyprinting extension has moved to `sympy`, \"\n"
     ]
    }
   ],
   "source": [
    "%load_ext sympyprinting\n",
    "%matplotlib inline\n",
    "import matplotlib.pyplot as plt\n",
    "import sympy\n",
    "from IPython.display import display\n",
    "sympy.init_printing(use_unicode=False, wrap_line=False, no_global=True)\n",
    "import scipy.constants\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Equation of motion - SDE to be solved"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### $\\ddot{q}(t) + \\Gamma_0\\dot{q}(t) + \\Omega_0^2 q(t) -  \\dfrac{1}{m} F(t) = 0 $\n",
    "\n",
    "#### where q = x, y or z\n",
    "\n",
    "Where $F(t) = \\mathcal{F}_{fluct}(t) + F_{feedback}(t)$\n",
    "\n",
    "Taken from page 46 of 'Dynamics of optically levitated nanoparticles in high vacuum' - Thesis by <NAME> "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Using $\\mathcal{F}_{fluct}(t) = \\sqrt{2m \\Gamma_0 k_B T_0}\\dfrac{dW(t)}{dt}$\n",
    "\n",
    "and $F_{feedback}(t) = \\Omega_0 \\eta q^2 \\dot{q}$\n",
    "\n",
    "Taken from page 49 of 'Dynamics of optically levitated nanoparticles in high vacuum' - Thesis by <NAME> \n",
    "\n",
    "we get the following SDE:"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$\\dfrac{d^2q(t)}{dt^2} + (\\Gamma_0 - \\Omega_0 \\eta q(t)^2)\\dfrac{dq(t)}{dt} + \\Omega_0^2 q(t) - \\sqrt{\\dfrac{2\\Gamma_0 k_B T_0}{m}} \\dfrac{dW(t)}{dt} = 0$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "split into 2 first order ODE/SDE s"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "letting $v = \\dfrac{dq}{dt}$\n",
    "\n",
    "$\\dfrac{dv(t)}{dt} + (\\Gamma_0 - \\Omega_0 \\eta q(t)^2)v + \\Omega_0^2 q(t) - \\sqrt{\\dfrac{2\\Gamma_0 k_B T_0}{m}} \\dfrac{dW(t)}{dt} = 0$\n",
    "\n",
    "therefore\n",
    "\n",
    "$\\dfrac{dv(t)}{dt} = -(\\Gamma_0 - \\Omega_0 \\eta q(t)^2)v - \\Omega_0^2 q(t) + \\sqrt{\\dfrac{2\\Gamma_0 k_B T_0}{m}} \\dfrac{dW(t)}{dt} $\n",
    "\n",
    "$v = \\dfrac{dq}{dt}$ therefore $dq = v~dt$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\\begin{align}\n",
    "dq&=v\\,dt\\\\\n",
    "dv&=[-(\\Gamma_0−\\Omega_0 \\eta q(t)^2)p - \\Omega_0^2 v(t)]\\,dt + \\sqrt{\\frac{2\\Gamma_0 k_B T_0}m}\\,dW\n",
    "\\end{align}\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Apply Milstein Method to solve"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Consider the autonomous Itō stochastic differential equation\n",
    "\n",
    "${\\mathrm  {d}}X_{t}=a(X_{t})\\,{\\mathrm  {d}}t+b(X_{t})\\,{\\mathrm  {d}}W_{t}$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Taking $X_t = q_t$ for the 1st equation above (i.e. $dq = v~dt$) we get:\n",
    "\n",
    "$$ a(q_t) = v $$\n",
    "$$ b(q_t) = 0 $$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Taking $X_t = v_t$ for the 2nd equation above (i.e. $dv = ...$) we get:\n",
    "\n",
    "$$a(v_t) = -(\\Gamma_0-\\Omega_0\\eta q(t)^2)v - \\Omega_0^2 q(t)$$ \n",
    "$$b(v_t) = \\sqrt{\\dfrac{2\\Gamma_0 k_B T_0}m}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "${\\displaystyle b'(v_{t})=0}$ therefore the diffusion term does not depend on ${\\displaystyle v_{t}}$ , the Milstein's method in this case is therefore equivalent to the Euler–Maruyama method."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We then construct these functions in python:"
   ]
{'fraction_non_alphanumeric': 0.24794359576968272, 'fraction_numerical': 0.01645123384253819, 'mean_word_length': 2.564070351758794, 'pattern_counts': {'":': 98, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6692282', 'n_tokens_mistral': 3670, 'n_tokens_neox': 3527, 'n_words': 704}