{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Function " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Projectile" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\\begin{equation}\n", "R=\\frac{u^2\\sin 2\\theta}{g}\n", "\\end{equation}" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\\begin{equation}\n", "TF=\\frac{2u\\sin \\theta}{g}\n", "\\end{equation}" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\\begin{equation}\n", "H=\\frac{u^2\\sin^2\\theta}{2g}\n", "\\end{equation}" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import numpy as np # from numpy import* not required to write np\n", "import pandas as pd # from pandas import* \n", "import matplotlib.pyplot as pltfrom # from matplotlib import*\n", "%matplotlib inline" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "def projectile(u,theta): \n", " g=9.8 # acceleration due to gravity\n", " R = u**2*np.sin(2*np.pi*theta/180)/g # range\n", " H= u**2*np.sin(np.pi*theta/180)**2/(2*g) # max. height\n", " TF = 2*u*np.sin(np.pi*theta/180)/g # time of flight \n", " return [R,H,TF] " ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[883.699391616774, 382.6530612244897, 17.67398783233548]" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p=projectile(100,60)\n", "p" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "Angle=[] #list for angle\n", "R=[] #list for range\n", "H=[] # list for height\n", "TF=[] #list for time of flight\n", "for angle in range(1,91):\n", " a=projectile(100,angle)\n", " Angle.append(angle)\n", " R.append(a[0]) # added element in list R\n", " H.append(a[1]) # added element in list H\n", " TF.append(a[2]) # added element in list TF " ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "ename": "NameError", "evalue": "name 'plt' is not defined", "output_type": "error", "traceback": [ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)", "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mplt\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mplot\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mAngle\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mR\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;34m'g-.'\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mlabel\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m'Range'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 2\u001b[0m \u001b[0mplt\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mplot\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mAngle\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mH\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;34m'b^'\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mlabel\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m'Max.height'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 3\u001b[0m \u001b[0mplt\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mxlabel\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'Angle(degree)'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 4\u001b[0m \u001b[0mplt\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mylabel\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'Distance(m)'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 5\u001b[0m \u001b[0mplt\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mtitle\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'Projectile'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", "\u001b[1;31mNameError\u001b[0m: name 'plt' is not defined" ] } ], "source": [ "plt.plot(Angle,R,'g-.',label='Range')\n", "plt.plot(Angle,H,'b^',label='Max.height')\n", "plt.xlabel('Angle(degree)')\n", "plt.ylabel('Distance(m)')\n", "plt.title('Projectile')\n", "plt.legend()\n", "plt.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plt.plot(Angle,TF,'k*')\n", "plt.xlabel('Angle(degree)')\n", "plt.ylabel('Time of flight(sec)')\n", "plt.title('Projectile')\n", "plt.savefig('projective.eps')\n", "plt.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "data={} # dictionary\n", "data.update({\"Angle\":Angle,\"Range\":R ,\"Time of flight\":TF,\"Max.Height\": H})" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "DF = pd.DataFrame(data)\n", "DF" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "DF.to_csv(\"projectile.csv\") #save data in csv format in excel" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.6" } }, "nbformat": 4, "nbformat_minor": 4 }