{ "cells": [ { "cell_type": "code", "execution_count": null, "id": "a0d44cc6", "metadata": {}, "outputs": [], "source": [ "# ] add Elliptic" ] }, { "cell_type": "code", "execution_count": null, "id": "92d7682d", "metadata": {}, "outputs": [], "source": [ "using Elliptic\n", "using PyPlot" ] }, { "cell_type": "code", "execution_count": null, "id": "8cb74d27", "metadata": {}, "outputs": [], "source": [ "\"\"\"\n", "Analytic solution of the pendulum ode\n", "\n", "theta'' + sin(theta) = 0\n", "\n", "theta(0) = 0, max(theta) = thetamax;\n", "theta'(0) = sqrt(2*(1 - cos(thetamax))) - from the conservation of energy\n", "\"\"\"\n", "function pendulum_analytics(t, thetamax)\n", " m = sin(thetamax / 2.)\n", " th = 2 * asin(m * Jacobi.sn(t, m))\n", " thd = 2 * m * Jacobi.cn(t, m)\n", " (th, thd)\n", "end" ] }, { "cell_type": "code", "execution_count": null, "id": "c5bd6343", "metadata": {}, "outputs": [], "source": [ "? pendulum_analytics" ] }, { "cell_type": "code", "execution_count": null, "id": "10a50a66", "metadata": {}, "outputs": [], "source": [ "tmax = 4*pi\n", "np = 100\n", "t = range(0.0, tmax, length=np)\n", "thetamax = pi/10\n", "\n", "theta = zeros(np)\n", "thetadot = zeros(np)\n", "\n", "theta[1] = 0.0\n", "thetadot[1] = sqrt(2*(1.0 - cos(thetamax)))\n", "\n", "for i = 2:np\n", " theta[i], thetadot[i] = pendulum_analytics(t[i], thetamax)\n", "end\n", "\n", "plot(t, theta, label=L\"\\theta\")\n", "plot(t, thetadot, label=L\"\\dot{\\theta}\")\n", "grid(true)\n", "legend()" ] }, { "cell_type": "code", "execution_count": null, "id": "bef9bc8f", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Julia 1.6.2", "language": "julia", "name": "julia-1.6" }, "language_info": { "file_extension": ".jl", "mimetype": "application/julia", "name": "julia", "version": "1.6.2" } }, "nbformat": 4, "nbformat_minor": 5 }