{
"cells": [
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
"%matplotlib -- inline \n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"import sympy as sp\n",
"import math\n",
"sp.init_printing()"
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": false
},
"source": [
"# <div dir=rtl> עבודה על צמיגות </div>\n",
"___\n",
"## <div dir=rtl>מיכל בגם ואמיר שפר<div>"
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": false
},
"source": [
""
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
"m=sp.symbols('m') #mass of the ball\n",
"eta=sp.symbols('eta') #Viscosity of liquid\n",
"raw=sp.symbols('rho') #Density of liquid\n",
"g=sp.symbols('g') #Gravitational acceleration\n",
"R=sp.symbols('R') #ball's Radius\n",
"pi=sp.symbols('pi') #pi\n",
"F=sp.symbols('F') #total Force of the ball\n",
"t=sp.var('t')\n",
"x=sp.Function('x') #place\n",
"v=sp.Function('v') #Velocity\n",
"a=sp.Function('a') #Acceleration"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/latex": [
"$$F = - \\frac{4 R^{3} \\pi \\rho}{3} - 6 R \\eta \\pi v{\\left (t \\right )} + g m$$"
]
},
"execution_count": 6,
"metadata": {
},
"output_type": "execute_result"
}
],
"source": [
"F_of_the_ball_1=sp.Eq(F,m*g-4*pi*R**3*raw/3-6*pi*eta*R*v(t))\n",
"F_of_the_ball_1"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/latex": [
"$$m a{\\left (t \\right )} = - \\frac{4 R^{3} \\pi \\rho}{3} - 6 R \\eta \\pi v{\\left (t \\right )} + g m$$"
]
},
"execution_count": 7,
"metadata": {
},
"output_type": "execute_result"
}
],
"source": [
"F_of_the_ball_2=F_of_the_ball_1.subs(F,m*a(t))\n",
"F_of_the_ball_2"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/latex": [
"$$a{\\left (t \\right )} = - \\frac{4 R^{3} \\pi \\rho}{3 m} - \\frac{6 R \\eta \\pi v{\\left (t \\right )}}{m} + g$$"
]
},
"execution_count": 8,
"metadata": {
},
"output_type": "execute_result"
}
],
"source": [
"F_of_the_ball_3=sp.Eq(a(t),g-(4*pi*R**3*raw/3)/m-(6*pi*eta*R*v(t))/m)\n",
"F_of_the_ball_3"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/latex": [
"$$\\frac{d}{d t} v{\\left (t \\right )} = - \\frac{4 R^{3} \\pi \\rho}{3 m} - \\frac{6 R \\eta \\pi v{\\left (t \\right )}}{m} + g$$"
]
},
"execution_count": 9,
"metadata": {
},
"output_type": "execute_result"
}
],
"source": [
"F_of_the_ball_4=F_of_the_ball_3.subs([(a(t),v(t).diff())])\n",
"F_of_the_ball_4"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/latex": [
"$$v{\\left (t \\right )} = \\frac{- 4 R^{2} \\rho + \\frac{3 g m}{R \\pi} + \\frac{e^{R \\eta \\pi \\left(C_{1} - \\frac{6 t}{m}\\right)}}{R \\pi}}{18 \\eta}$$"
]
},
"execution_count": 10,
"metadata": {
},
"output_type": "execute_result"
}
],
"source": [
"F_of_the_ball_5=sp.dsolve(F_of_the_ball_4,v(t))\n",
"F_of_the_ball_5"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/latex": [
"$$x{\\left (t \\right )} = \\begin{cases} - \\frac{m e^{R \\eta \\pi \\left(C_{1} - \\frac{6 t}{m}\\right)}}{108 R^{2} \\eta^{2} \\pi^{2}} & \\text{for}\\: 108 R^{2} \\eta^{2} \\pi^{2} \\neq 0 \\\\t \\left(- \\frac{- 4 R^{3} \\pi \\rho + 3 g m}{18 R \\eta \\pi} + \\frac{- 4 R^{3} \\pi \\rho + 3 g m + 1}{18 R \\eta \\pi}\\right) & \\text{otherwise} \\end{cases} + \\frac{t \\left(- 4 R^{3} \\pi \\rho + 3 g m\\right)}{18 R \\eta \\pi}$$"
]
},
"execution_count": 11,
"metadata": {
},
"output_type": "execute_result"
}
],
"source": [
"F_of_the_ball_5_integral_x=sp.Eq(x(t),sp.integrate(F_of_the_ball_5.rhs,t))\n",
"F_of_the_ball_5_integral_x"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/latex": [
"$$\\frac{d^{2}}{d t^{2}} x{\\left (t \\right )} = - \\frac{4 R^{3} \\pi \\rho}{3 m} - \\frac{6 R \\eta \\pi \\frac{d}{d t} x{\\left (t \\right )}}{m} + g$$"
]
},
"execution_count": 12,
"metadata": {
},
"output_type": "execute_result"
}
],
"source": [
"F_of_the_ball_4_2=F_of_the_ball_3.subs([(a(t),x(t).diff().diff()),(v(t),x(t).diff())])\n",
"F_of_the_ball_4_2"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/latex": [
"$$x{\\left (t \\right )} = C_{1} - \\frac{2 R^{2} \\rho t}{9 \\eta} + \\left(C_{2} - \\begin{cases} - \\frac{R m \\rho e^{\\frac{6 R \\eta \\pi t}{m}}}{27 \\eta^{2} \\pi} + \\frac{g m^{2} e^{\\frac{6 R \\eta \\pi t}{m}}}{36 R^{2} \\eta^{2} \\pi^{2}} & \\text{for}\\: 108 R^{2} \\eta^{2} \\pi^{2} \\neq 0 \\\\- \\frac{2 R^{2} \\rho t}{9 \\eta} + \\frac{g m t}{6 R \\eta \\pi} & \\text{otherwise} \\end{cases}\\right) e^{- \\frac{6 R \\eta \\pi t}{m}} + \\frac{g m t}{6 R \\eta \\pi}$$"
]
},
"execution_count": 13,
"metadata": {
},
"output_type": "execute_result"
}
],
"source": [
"F_of_the_ball_5_2=sp.dsolve(F_of_the_ball_4_2,x(t))\n",
"F_of_the_ball_5_2"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
"####################################################################"
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
"#######################################################################"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
"m_1=2.04/1000 #mass of the ball\n",
"#eta= #Viscosity of liquid\n",
"g_1=9.823 #Gravitational acceleration\n",
"R_1=0.005 #ball's Radius\n",
"pi_1=math.pi #pi"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
"#######################################################################"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
"#######################################################################"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
"##### מטלות:\n",
"##### 1. לקחת את משוואת המהירות והמקום זמן ולהציב בהן את כל הנתונים הקבועים\n",
"##### 2. להציב גם את הצפיפות של אותה המדידה\n",
"##### להציב את הצמיגות שבודקים (או לולאת for)\n",
"##### 3. בעזרת V0 למצוא את הקבועה הראשון\n",
"##### 5. למצוא את הקבוע השני בעזרת x0\n",
"##### 6. ליצור רשימה ולהשוות לאמיתי"
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/latex": [
"$$a{\\left (t \\right )} = - \\frac{4 R^{3} \\pi \\rho}{3 m} - \\frac{6 R \\eta \\pi v{\\left (t \\right )}}{m} + g$$"
]
},
"execution_count": 31,
"metadata": {
},
"output_type": "execute_result"
}
],
"source": [
"F_of_the_ball_3"
]
},
{
"cell_type": "code",
"execution_count": 32,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/latex": [
"$$\\frac{d}{d t} v{\\left (t \\right )} = - \\frac{4 R^{3} \\pi \\rho}{3 m} - \\frac{6 R \\eta \\pi v{\\left (t \\right )}}{m} + g$$"
]
},
"execution_count": 32,
"metadata": {
},
"output_type": "execute_result"
}
],
"source": [
"F_of_the_ball_4"
]
},
{
"cell_type": "code",
"execution_count": 33,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/latex": [
"$$v{\\left (t \\right )} = \\frac{- 4 R^{2} \\rho + \\frac{3 g m}{R \\pi} + \\frac{e^{R \\eta \\pi \\left(C_{1} - \\frac{6 t}{m}\\right)}}{R \\pi}}{18 \\eta}$$"
]
},
"execution_count": 33,
"metadata": {
},
"output_type": "execute_result"
}
],
"source": [
"#1\n",
"F_of_the_ball_5"
]
},
{
"cell_type": "code",
"execution_count": 34,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Eq(x(t), Piecewise((-m*exp(R*eta*pi*(C1 - 6*t/m))/(108*R**2*eta**2*pi**2), Ne(108*R**2*eta**2*pi**2, 0)), (t*(-(-4*R**3*pi*rho + 3*g*m)/(18*R*eta*pi) + (-4*R**3*pi*rho + 3*g*m + 1)/(18*R*eta*pi)), True)) + t*(-4*R**3*pi*rho + 3*g*m)/(18*R*eta*pi))\n"
]
},
{
"data": {
"text/latex": [
"$$x{\\left (t \\right )} = \\begin{cases} - \\frac{m e^{R \\eta \\pi \\left(C_{1} - \\frac{6 t}{m}\\right)}}{108 R^{2} \\eta^{2} \\pi^{2}} & \\text{for}\\: 108 R^{2} \\eta^{2} \\pi^{2} \\neq 0 \\\\t \\left(- \\frac{- 4 R^{3} \\pi \\rho + 3 g m}{18 R \\eta \\pi} + \\frac{- 4 R^{3} \\pi \\rho + 3 g m + 1}{18 R \\eta \\pi}\\right) & \\text{otherwise} \\end{cases} + \\frac{t \\left(- 4 R^{3} \\pi \\rho + 3 g m\\right)}{18 R \\eta \\pi}$$"
]
},
"execution_count": 34,
"metadata": {
},
"output_type": "execute_result"
}
],
"source": [
"print(F_of_the_ball_5_integral_x)\n",
"F_of_the_ball_5_integral_x"
]
},
{
"cell_type": "code",
"execution_count": 35,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/latex": [
"$$x{\\left (t \\right )} = C_{2} + \\frac{t \\left(- 4 R^{3} \\pi \\rho + 3 g m\\right)}{18 R \\eta \\pi} - \\frac{e^{R \\eta \\pi \\left(C_{1} - \\frac{6 t}{m}\\right)} m}{108 R^{2} \\eta^{2} \\pi^{2}}$$"
]
},
"execution_count": 35,
"metadata": {
},
"output_type": "execute_result"
}
],
"source": [
"e=sp.symbols('e') #math.e\n",
"c1=sp.symbols('C1') #c1\n",
"c2=sp.symbols('C2') #c2\n",
"F_of_the_ball_x_last=sp.Eq(x(t),(-m*e**(R*eta*pi*(c1 - 6*t/m))/(108*R**2*eta**2*pi**2)+t*(-4*R**3*pi*raw + 3*g*m)/(18*R*eta*pi))+c2)\n",
"F_of_the_ball_x_last"
]
},
{
"cell_type": "code",
"execution_count": 36,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/latex": [
"$$v{\\left (t \\right )} = \\frac{- 4 R^{2} \\rho + \\frac{3 g m}{R \\pi} + \\frac{e^{R \\eta \\pi \\left(C_{1} - \\frac{6 t}{m}\\right)}}{R \\pi}}{18 \\eta}$$"
]
},
"execution_count": 36,
"metadata": {
},
"output_type": "execute_result"
}
],
"source": [
"F_of_the_ball_v_last=F_of_the_ball_5\n",
"F_of_the_ball_v_last"
]
},
{
"cell_type": "code",
"execution_count": 37,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/latex": [
"$$v{\\left (t \\right )} = \\frac{- 0.0001 \\rho + 63.6619772367581 e^{0.015707963267949 \\eta \\left(C_{1} - 2941.17647058824 t\\right)} + 3.82715180666765}{18 \\eta}$$"
]
},
"execution_count": 37,
"metadata": {
},
"output_type": "execute_result"
}
],
"source": [
"F_of_the_ball_v_last_sub1=F_of_the_ball_v_last.subs([(g,g_1),(m,m_1),(R,R_1),(pi,pi_1)])\n",
"F_of_the_ball_v_last_sub1"
]
},
{
"cell_type": "code",
"execution_count": 38,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/latex": [
"$$x{\\left (t \\right )} = C_{2} - \\frac{0.076553783196433 e^{0.015707963267949 \\eta \\left(C_{1} - 2941.17647058824 t\\right)}}{\\eta^{2}} + \\frac{3.53677651315323 t \\left(- 1.5707963267949 \\cdot 10^{-6} \\rho + 0.06011676\\right)}{\\eta}$$"
]
},
"execution_count": 38,
"metadata": {
},
"output_type": "execute_result"
}
],
"source": [
"F_of_the_ball_x_last_sub1=F_of_the_ball_x_last.subs([(g,g_1),(m,m_1),(R,R_1),(pi,pi_1)])\n",
"F_of_the_ball_x_last_sub1"
]
},
{
"cell_type": "code",
"execution_count": 39,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
"####### Example for water: eta=1.8"
]
},
{
"cell_type": "code",
"execution_count": 40,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/latex": [
"$$v{\\left (t \\right )} = 1.76838825657661 e^{0.0314159265358979 C_{1} - 92.3997839291116 t} + 0.103576439074101$$"
]
},
"execution_count": 40,
"metadata": {
},
"output_type": "execute_result"
}
],
"source": [
"#2\n",
"raw_1=0.246/0.00025 #Density of liquid\n",
"#raw_1=998\n",
"F_of_the_ball_v_example_1=F_of_the_ball_v_last_sub1.subs([(raw,raw_1),(eta,2)])\n",
"F_of_the_ball_v_example_1"
]
},
{
"cell_type": "code",
"execution_count": 41,
"metadata": {
"collapsed": false
},
"outputs": [
{
"ename": "NameError",
"evalue": "name 'F_of_the_ball_v_3' is not defined",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-41-6f7d2a97f343>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0;31m#v0=0.1303\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0;31m#(0,0.1303)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 5\u001b[0;31m \u001b[0mc1_example\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0msp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msolve\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mF_of_the_ball_v_3\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msubs\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mv\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mt\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m0.1303\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mt\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m'C1'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 6\u001b[0m \u001b[0mc1_example\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mc1_example\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 7\u001b[0m \u001b[0mc1_example\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mNameError\u001b[0m: name 'F_of_the_ball_v_3' is not defined"
]
}
],
"source": [
"#3\n",
"#C1 is related to v0:\n",
"#v0=0.1303\n",
"#(0,0.1303)\n",
"c1_example=sp.solve(F_of_the_ball_v_3.subs([(v(t),0.1303),(t,0)]),'C1')\n",
"c1_example=c1_example[0]\n",
"c1_example"
]
},
{
"cell_type": "code",
"execution_count": 42,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/latex": [
"$$x{\\left (t \\right )} = C_{2} - 0.0191384457991082 e^{0.0314159265358979 C_{1} - 92.3997839291116 t} + 0.103576439074101 t$$"
]
},
"execution_count": 42,
"metadata": {
},
"output_type": "execute_result"
}
],
"source": [
"F_of_the_ball_x_example_1=F_of_the_ball_x_last_sub1.subs([(raw,raw_1),(eta,2)])\n",
"F_of_the_ball_x_example_1"
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
"F_of_the_ball_x_example_2=F_of_the_ball_x_example_1.subs([(c1,c1_example)])\n",
"F_of_the_ball_x_example_2"
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
"#4\n",
"#C2 is related to x0:\n",
"#x0=0\n",
"#(0,0)\n",
"c2_example=sp.solve(F_of_the_ball_x_example_2.subs([(x(t),0),(t,0),(e,math.e)]),c2)\n",
"c2_example"
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
"F_of_the_ball_x_example_3=F_of_the_ball_x_example_2.subs([(c2,c2_example[0]),(e,math.e)])\n",
"F_of_the_ball_x_example_3"
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"collapsed": false,
"scrolled": true
},
"outputs": [
],
"source": [
"t_list=[]\n",
"x_list=np.array([])\n",
"for i in np.arange(0,61*0.05,0.05):\n",
" t_list.append(i)\n",
" x_list=np.append(x_list,[F_of_the_ball_x_example_3.rhs.subs([(t,i)])])\n",
"plt.plot(t_list,x_list)"
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
"x_list[-1]"
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
"t_list_example_real=[]\n",
"x_list_example_real=np.array([-0.001309,0.002946,0.007528,0.012111,0.016039,0.019967,0.023567,0.027168,0.030769,0.034042,0.037642,0.041243,0.044844,0.048117,0.05139,0.054336,0.057282,0.060555,0.063828,0.066774,0.06972,0.072994,0.076267,0.079213,0.085432,0.088705,0.091978,0.094924,0.09787,0.101143,0.104744,0.10769,0.110636,0.113909,0.117182,0.119474,0.122747,0.126348,0.130275,0.133221,0.136822,0.140423,0.143041,0.145332,0.148606,0.151552,0.155152,0.154825,0.157443,0.161044,0.163335,0.166609,0.169554,0.172173,0.175119,0.179702,0.182647,0.184611,0.188539,0.190831,0.193777])\n",
"\n",
"for i in range(0,len(x_list_example_real)):\n",
" t_list_example_real.append(i*(1/3))\n",
"\n",
"plt.plot(t_list_example_real,x_list_example_real)"
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
"x_list_example_real[-1]"
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
"len(x_list)"
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
"error_present=(x_list_example_real-x_list)**2\n",
"sum(error_present)"
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
"##################################################################################"
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
"######################################################################################"
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
"#עכשיו \"נגלה\" מה צמיגות המים:"
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
"F_of_the_ball_3"
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
"F_of_the_ball_4"
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
"##בוא נציב ונמצא את משוואת המהירות זמן:"
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
"##נתונים קבועיים לכל המדידות\n",
"m_1=2.04/1000 #mass of the ball\n",
"g_1=9.823 #Gravitational acceleration\n",
"R_1=0.005 #ball's Radius\n",
"pi_1=math.pi #pi"
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
"#1\n",
"F_of_the_ball_v_1=F_of_the_ball_4.subs([(g,g_1),(m,m_1),(R,R_1),(pi,pi_1)])\n",
"F_of_the_ball_v_1"
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
"#!#\n",
"## נתון של המדידה הנוכחית:\n",
"raw_1=0.246/0.00025 # ץ(מסת החומר חלקי הנפח שלה) צפיפות החומר "
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
"\n",
"F_of_the_ball_v_1_2=F_of_the_ball_v_1.subs([(raw,raw_1)])\n",
"F_of_the_ball_v_1_2 #חסר רק צמיגות משוואה דיפרנציאלית עם פונקציית מהירות זמן מוצבת"
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
"print(F_of_the_ball_5_integral_x)\n",
"F_of_the_ball_5_integral_x"
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
"e=sp.symbols('e') #math.e\n",
"c1=sp.symbols('C1') #c1\n",
"c2=sp.symbols('C2') #c2\n",
"F_of_the_ball_x_last=sp.Eq(x(t),(-m*e**(R*eta*pi*(c1 - 6*t/m))/(108*R**2*eta**2*pi**2)+t*(-4*R**3*pi*raw + 3*g*m)/(18*R*eta*pi))+c2)\n",
"F_of_the_ball_x_last ### פונקציית מקום זמן סופי עם פרמטרים"
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
"F_of_the_ball_x_last_sub1=F_of_the_ball_x_last.subs([(g,g_1),(m,m_1),(R,R_1),(pi,pi_1)])\n",
"F_of_the_ball_x_last_sub1 ## עדיין אין צפיפות וצמיגות פונקציית מקום זמן עם הנתונים הקבועיים"
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
"F_of_the_ball_x_last_sub2=F_of_the_ball_x_last_sub1.subs([(raw,raw_1)])\n",
"F_of_the_ball_x_last_sub2 #חסר רק צמיגות ושני הקבועיים פונקציית מקום זמן מוצבת"
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
"####3\n",
"F_of_the_ball_v_2=F_of_the_ball_v_1_2.subs([(eta,2)])\n",
"F_of_the_ball_v_2\n",
"##4\n",
"F_of_the_ball_v_3=sp.dsolve(F_of_the_ball_v_2)\n",
"F_of_the_ball_v_3"
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
"#!#\n",
"#בוא נמצא את הקבוע בעזרת המהירות ההתחלתית של המדידה הנוכחית\n",
"#C1 is related to v0:\n",
"#(0,0.1303)\n",
"v0=0.1303"
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
"c1_example=sp.solve(F_of_the_ball_v_3.subs([(v(t),v0),(t,0)]),'C1')\n",
"c1_example=c1_example[0]\n",
"c1_example\n",
"F_of_the_ball_x_last_sub3=F_of_the_ball_x_last_sub2.subs([(eta,2)])\n",
"F_of_the_ball_x_last_sub3 #צמיגות בו, רק שני הקבועים חסרים\n",
"F_of_the_ball_x_last_sub4=F_of_the_ball_x_last_sub3.subs([(c1,c1_example)])\n",
"F_of_the_ball_x_last_sub4 #\n",
"F_of_the_ball_x_last_sub4"
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
"#4\n",
"#C2 is related to x0:\n",
"#x0=0\n",
"#(0,0)\n",
"c2_example=sp.solve(F_of_the_ball_x_last_sub4.subs([(x(t),0),(t,0),(e,math.e)]),c2)\n",
"c2_example\n",
"F_of_the_ball_x_last_last=F_of_the_ball_x_last_sub4.subs([(c2,c2_example[0]),(e,math.e)])\n",
"F_of_the_ball_x_last_last"
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
"t_list=[]\n",
"x_list=np.array([])\n",
"for i in np.arange(0,61*0.05,0.05):\n",
" t_list.append(i)\n",
" x_list=np.append(x_list,[F_of_the_ball_x_last_last.rhs.subs([(t,i)])])\n",
"t_list_example_real=[]\n",
"x_list_example_real=np.array([-0.001309,0.002946,0.007528,0.012111,0.016039,0.019967,0.023567,0.027168,0.030769,0.034042,0.037642,0.041243,0.044844,0.048117,0.05139,0.054336,0.057282,0.060555,0.063828,0.066774,0.06972,0.072994,0.076267,0.079213,0.085432,0.088705,0.091978,0.094924,0.09787,0.101143,0.104744,0.10769,0.110636,0.113909,0.117182,0.119474,0.122747,0.126348,0.130275,0.133221,0.136822,0.140423,0.143041,0.145332,0.148606,0.151552,0.155152,0.154825,0.157443,0.161044,0.163335,0.166609,0.169554,0.172173,0.175119,0.179702,0.182647,0.184611,0.188539,0.190831,0.193777])\n",
"\n",
"for i in range(0,len(x_list_example_real)):\n",
" t_list_example_real.append(i*(1/3))\n",
"error_present=(x_list_example_real-x_list)**2\n",
"sum(error_present)"
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
"best_eta=0\n",
"min_error=1000\n",
"for eta_1 in np.arange(1.8,2.2,0.1):\n",
" ####3\n",
" F_of_the_ball_v_2=F_of_the_ball_v_1_2.subs([(eta,eta_1)])\n",
" F_of_the_ball_v_2\n",
" ##4\n",
" F_of_the_ball_v_3=sp.dsolve(F_of_the_ball_v_2)\n",
" F_of_the_ball_v_3\n",
" #!#\n",
" #בוא נמצא את הקבוע בעזרת המהירות ההתחלתית של המדידה הנוכחית\n",
" #C1 is related to v0:\n",
" #(0,0.1303)\n",
" v0=0.1303\n",
" c1_example=sp.solve(F_of_the_ball_v_3.subs([(v(t),v0),(t,0)]),'C1')\n",
" c1_example=c1_example[0]\n",
" c1_example\n",
" F_of_the_ball_x_last_sub3=F_of_the_ball_x_last_sub2.subs([(eta,eta_1)])\n",
" F_of_the_ball_x_last_sub3 #צמיגות בו, רק שני הקבועים חסרים\n",
" F_of_the_ball_x_last_sub4=F_of_the_ball_x_last_sub3.subs([(c1,c1_example)])\n",
" F_of_the_ball_x_last_sub4 #קבוע המהירות הוחלף\n",
" #4\n",
" #C2 is related to x0:\n",
" #x0=0\n",
" #(0,0)\n",
" c2_example=sp.solve(F_of_the_ball_x_last_sub3.subs([(x(t),0),(t,0),(e,math.e)]),c2)\n",
" c2_example\n",
" F_of_the_ball_x_last_last=F_of_the_ball_x_last_sub4.subs([(c2,c2_example[0]),(e,math.e)])\n",
" F_of_the_ball_x_last_last\n",
" t_list=[]\n",
" x_list=np.array([])\n",
" for i in np.arange(0,61*0.05,0.05):\n",
" t_list.append(i)\n",
" x_list=np.append(x_list,[F_of_the_ball_x_last_last.rhs.subs([(t,i)])])\n",
" t_list_example_real=[]\n",
" x_list_example_real=np.array([-0.001309,0.002946,0.007528,0.012111,0.016039,0.019967,0.023567,0.027168,0.030769,0.034042,0.037642,0.041243,0.044844,0.048117,0.05139,0.054336,0.057282,0.060555,0.063828,0.066774,0.06972,0.072994,0.076267,0.079213,0.085432,0.088705,0.091978,0.094924,0.09787,0.101143,0.104744,0.10769,0.110636,0.113909,0.117182,0.119474,0.122747,0.126348,0.130275,0.133221,0.136822,0.140423,0.143041,0.145332,0.148606,0.151552,0.155152,0.154825,0.157443,0.161044,0.163335,0.166609,0.169554,0.172173,0.175119,0.179702,0.182647,0.184611,0.188539,0.190831,0.193777])\n",
"\n",
" for i in range(0,len(x_list_example_real)):\n",
" t_list_example_real.append(i*(1/3))\n",
" error_present=(x_list_example_real-x_list)**2\n",
" final_error=sum(error_present)\n",
" if(final_error<min_error):\n",
" min_error=final_error\n",
" best_eta=eta_1\n",
"best_eta"
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
"####################################################################################"
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
"F_of_the_ball_v_last"
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
"F_of_the_ball_v_lastF_subs1"
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
"F_of_the_ball_4"
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
"F_of_the_ball_4\n",
"F_of_the_ball_4_2=sp.dsolve(F_of_the_ball_4,v(t))"
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
"F_of_the_ball_4_2.subs([(g,g_1),(m,m_1),(R,R_1),(pi,pi_1),(raw,raw_1),(eta,2)])"
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
"(0,1.303)\n",
"c1=sp.solve(F_of_the_ball_v_3.subs([(v(t),1.303),(t,0)]),'C1')\n",
"c1"
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
"F_of_the_ball_v_4=F_of_the_ball_v_3.subs([('C1',c1[0])])\n",
"F_of_the_ball_v_4"
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
"#5\n",
"sp.integrate(F_of_the_ball_v_4,t)"
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
"F_of_the_ball_x_from_v_1=sp.Eq(x(t),sp.integrate(F_of_the_ball_v_4.rhs,t))\n",
"F_of_the_ball_x_from_v_1"
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"collapsed": false,
"scrolled": true
},
"outputs": [
],
"source": [
"t_list=[]\n",
"x_list=[]\n",
"for i in np.arange(0,5,0.05):\n",
" t_list.append(i)\n",
" x_list.append(F_of_the_ball_x_from_v_1.rhs.subs([(t,i)]))\n",
"plt.plot(t_list,x_list)"
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"collapsed": false,
"scrolled": true
},
"outputs": [
],
"source": [
"x_list[t_list.index(0.5)]"
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
"#The eq:\n",
"F_of_the_ball_v_1"
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (Ubuntu Linux)",
"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.6.5"
}
},
"nbformat": 4,
"nbformat_minor": 0
}