diff options
46 files changed, 18564 insertions, 0 deletions
diff --git a/Basic_mechanical_engineering_by_Basant_Agrawal_,_C.M_Agrawal/README.txt b/Basic_mechanical_engineering_by_Basant_Agrawal_,_C.M_Agrawal/README.txt new file mode 100644 index 00000000..c09b9946 --- /dev/null +++ b/Basic_mechanical_engineering_by_Basant_Agrawal_,_C.M_Agrawal/README.txt @@ -0,0 +1,10 @@ +Contributed By: Reshma Ustad +Course: be +College/Institute/Organization: Anjuman-I-Islam's, Kalsekar Technical Campus,Panvel-410206 +Department/Designation: Electronics & telecommunication +Book Title: Basic mechanical engineering +Author: Basant Agrawal , C.M Agrawal +Publisher: Wiley India pvt ltd , new delhi-110002 +Year of publication: 2008 +Isbn: 978-81-265-1878-4 +Edition: first
\ No newline at end of file diff --git a/Numerical_Methods_by_E._Balaguruswamy/chapter10.ipynb b/Numerical_Methods_by_E._Balaguruswamy/chapter10.ipynb new file mode 100644 index 00000000..7de04b99 --- /dev/null +++ b/Numerical_Methods_by_E._Balaguruswamy/chapter10.ipynb @@ -0,0 +1,282 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Chapter 10 - Curve fitting regression" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 10_01 Pg No. 326" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "b = [-1 -1 0 0 1]\n", + "a = [ 3 3 1 1 -2]\n", + "y= [-x + 3 -x + 3 1 1 x - 2]\n" + ] + } + ], + "source": [ + "from numpy import array\n", + "from sympy.abc import x\n", + "#Fitting a Straight Line\n", + "\n", + "X = range(1,6)\n", + "Y = array([[ 3, 4, 5 ,6 ,8 ]])\n", + "n = len(X)#\n", + "X=array(X)\n", + "b = ( n*sum(X*Y) - sum(X)*sum(Y) )/( n*sum(X*X) - (sum(X))**2 )\n", + "a = sum(Y)/n - b*sum(X)/n\n", + "print 'b = ',b\n", + "print 'a = ',a\n", + "y = a + b*x\n", + "print 'y=',y" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 10_02 Pg No. 331" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "b = 2.0\n", + "lna = -0.69314718056\n", + "a = 0.5\n", + "\n", + " The power function equation obtained is \n", + " y = 0.5x**2\n" + ] + } + ], + "source": [ + "from numpy import array,log,exp\n", + "from sympy.abc import x\n", + "\n", + "#Fitting a Power-Function model to given data\n", + "\n", + "X = array(range(1,6))\n", + "Y = [ 0.5, 2 ,4.5 ,8 ,12.5 ]\n", + "Xnew = log(X)\n", + "Ynew = log(Y)\n", + "n = len(Xnew)\n", + "b = ( n*sum(Xnew*Ynew) - sum(Xnew)*sum(Ynew) )/( n*sum(Xnew*Xnew) - ( sum(Xnew) )**2 )\n", + "lna = sum(Ynew)/n - b*sum(Xnew)/n\n", + "a = exp(lna)\n", + "print 'b = ',b\n", + "print 'lna = ',lna\n", + "print 'a = ',a\n", + "print '\\n The power function equation obtained is \\n y = %.4Gx**%.4G'%(a,b)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 10_03 Pg No. 332" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "b = 37.6294062985\n", + "a = 20.9234245534\n", + "The relationship between T and t is \n", + "T = 37.63*e**(t/4) + 20.92 \n", + "\n", + "The temperature at t = 6 is 189.566723485\n" + ] + } + ], + "source": [ + "from numpy import array,log,exp\n", + "time = array(range(1,5))\n", + "T = [ 70 ,83 ,100 ,124 ]\n", + "t = 6\n", + "Fx = exp(time/4.0)\n", + "n = len(Fx)\n", + "Y = T #\n", + "b = ( n*sum(Fx*Y) - sum(Fx)*sum(Y) )/( n*sum(Fx*Fx) - (sum(Fx))**2 )\n", + "a = sum(Y)/n - b*sum(Fx)/n\n", + "print 'b = ',b\n", + "print 'a = ',a\n", + "print 'The relationship between T and t is \\nT = %.4G*e**(t/4) + %.4G \\n'%(b,a)\n", + "#deff('T = T(t)'%('T = b*exp(t/4) + a '\n", + "def T(t):\n", + " tt=b*exp(t/4.0)+a\n", + " return tt\n", + " \n", + "T_6 = T(6)\n", + "print 'The temperature at t = 6 is',T_6" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 10_04 Pg NO. 335" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Using CA = B form , we get\n", + "B [ 6. 62. 190.]\n", + "C [[ 1. 1. 4.]\n", + " [ 1. 4. 10.]\n", + " [ 4. 10. 30.]]\n", + "A = [[ 20. 103.33333333 -190. ]\n", + " [ 10. 144.66666667 -190. ]\n", + " [ -6. -62. 95. ]]\n", + "Therefore the least sqaures polynomial is\n", + " y = 1J + 1J*x + 1J*x**2 \n", + "[ 20. 103.33333333 -190. ]\n", + "[ 10. 144.66666667 -190. ]\n", + "[ -6. -62. 95.]\n" + ] + } + ], + "source": [ + "from numpy import array,ones,identity\n", + "from numpy.linalg import inv\n", + "\n", + "#Curve Fitting\n", + "\n", + "x = array(range(1,5))\n", + "y = [6, 11, 18, 27 ]\n", + "n = len(x) #Number of data points\n", + "m = 2+1 #Number of unknowns\n", + "print 'Using CA = B form , we get'\n", + "C=identity(m)\n", + "B=ones(m)\n", + "for j in range(0,m):\n", + " for k in range(0,m):\n", + " C[j,k] = sum(x**(j+k-2))\n", + " \n", + " B[j] = sum( y*( x**( j-1 ) ) )\n", + "\n", + "print 'B',B\n", + "print 'C',C\n", + "A = inv(C)*B\n", + "print 'A = ',A\n", + "print 'Therefore the least sqaures polynomial is\\n y = 1J + 1J*x + 1J*x**2 \\n',(A[0])\n", + "print A[1]\n", + "print A[2]" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 10_05 Pg No. 342" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "C=\n", + "[[ 4. 10. 6.]\n", + " [ 10. 30. 20.]\n", + " [ 6. 20. 14.]]\n", + "B=\n", + "[ 84. 240. 156.]\n", + "\n", + " The regression plane is \n", + " y = 5 + 6*x + 0*z \n", + "\n" + ] + } + ], + "source": [ + "from numpy import array,ones,identity,arange,vstack,transpose\n", + "from scipy.sparse.linalg import lsqr\n", + "#Plane Fitting\n", + "\n", + "x = range(1,5)\n", + "z = range(0,4)\n", + "y = arange(12,31,6)\n", + "n = len(x) #Number of data points\n", + "m = 3 #Number of unknowns\n", + "G = vstack([ones(n),x,z])\n", + "H = transpose(G)\n", + "C = G.dot(H)\n", + "B = y.dot(H)\n", + "D = lsqr(C,B)\n", + "print 'C=\\n',C\n", + "print 'B=\\n',B\n", + "print '\\n The regression plane is \\n y = %d + %.f*x + %d*z \\n'%(D[0][0],D[0][1],D[0][2])\n" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.9" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Numerical_Methods_by_E._Balaguruswamy/chapter11.ipynb b/Numerical_Methods_by_E._Balaguruswamy/chapter11.ipynb new file mode 100644 index 00000000..c717bdbd --- /dev/null +++ b/Numerical_Methods_by_E._Balaguruswamy/chapter11.ipynb @@ -0,0 +1,428 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Chapter 11 - Numerical differentiation" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 11_01 Pg No. 348" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "h\ty\terr\n", + "0.2 \t2.2 \t0.2\n", + "0.1 \t2.1 \t0.1\n", + "0.05 \t2.05 \t0.05\n", + "0.01 \t2.01 \t0.01\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from scipy.misc import derivative\n", + "\n", + "#First order forward difference\n", + "\n", + "def f(x):\n", + " F=x**2\n", + " return F\n", + " \n", + "\n", + "def df(x,h):\n", + " DF=(f(x+h)-f(x))/h\n", + " return DF\n", + "\n", + "dfactual = derivative(f,1)\n", + "h = [0.2, 0.1, 0.05, 0.01 ]\n", + "print 'h\\ty\\terr'\n", + "for hh in h:\n", + " y = df(1,hh)\n", + " err = y - dfactual\n", + " print hh,'\\t',y,'\\t',err" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 11_02 Pg No. 350" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "h\ty\terr\n", + "0.2 \t2.0 \t-4.4408920985e-16\n", + "0.1 \t2.0 \t4.4408920985e-16\n", + "0.05 \t2.0 \t4.4408920985e-16\n", + "0.01 \t2.0 \t1.7763568394e-15\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from scipy.misc import derivative\n", + "\n", + "#Three-Point Formula\n", + "\n", + "def f(x):\n", + " F = x**2\n", + " return F\n", + "def df(x,h):\n", + " DF = (f(x+h)-f(x-h))/(2*h)\n", + " return DF\n", + "dfactual = derivative(f,1)\n", + "h = [0.2, 0.1, 0.05, 0.01 ]\n", + "print 'h\\ty\\terr'\n", + "for hh in h:\n", + " y = df(1,hh)\n", + " err = y - dfactual\n", + " print hh,'\\t',y,'\\t',err\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 11_03 Pg No. 353" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "h\ty\t\terr\n", + "0.01 \t0.898257285429 \t-0.00218981692372\n", + "0.015 \t0.897151155627 \t-0.00329594672573\n", + "0.02 \t0.896037563392 \t-0.00440953896077\n", + "0.025 \t0.894916522709 \t-0.00553057964367\n", + "0.03 \t0.893788047675 \t-0.00665905467759\n", + "0.035 \t0.892652152498 \t-0.00779494985432\n", + "0.04 \t0.891508851498 \t-0.00893825085448\n", + "\n", + "M2 = 2.061e-08 & hopt = 4.706e-01\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from scipy.misc import derivative\n", + "from numpy import arange,sin,cos,sqrt\n", + "x = 0.45#\n", + "def f(x):\n", + " F = sin(x)\n", + " return F\n", + "def df(x,h):\n", + " DF = (f(x+h) - f(x))/h\n", + " return DF\n", + "dfactual = cos(x)#\n", + "h = arange(0.01,0.005+0.04,0.005)\n", + "n = len(h)#\n", + "print 'h\\ty\\t\\terr'\n", + "for hh in h:\n", + " y = df(x,hh)\n", + " err = y - dfactual \n", + " print hh,'\\t',y,'\\t',err\n", + "\n", + "#using 16 significant digits so the bound for roundoff error is 0.5*10**(-16)\n", + "e = 0.5*10**(-16)\n", + "M2 = max(sin(x+h))#\n", + "hopt = 2*sqrt(e/M2)#\n", + "print '\\nM2 = %.3e & hopt = %.3e'%(hopt,M2)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 11_04 Pg No. 354" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " d2fexact = -0.732 \n", + " err = -6.097e-06 \n", + " y = -0.732 \n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from numpy import arange,sin,cos,sqrt\n", + "\n", + "#Approximate second derivative\n", + "\n", + "x = 0.75#\n", + "h = 0.01#\n", + "def f(x):\n", + " F = cos(x)\n", + " return F\n", + "def d2f(x,h):\n", + " D2F = ( f(x+h) - 2*f(x) + f(x-h) )/h**2\n", + " return D2F\n", + "y = d2f(0.75,0.01)#\n", + "d2fexact = -cos(0.75)\n", + "err = d2fexact - y #\n", + "print ' d2fexact = %.3f \\n err = %.3e \\n y = %.3f '%(d2fexact,err,y)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 11_05 Pg No. 358" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "v(5) = 4.25\n", + "v(7) = 5.5\n", + "v(9) = 6.75\n" + ] + } + ], + "source": [ + "#Differentiation of tabulated data\n", + "\n", + "T = range(5,10)\n", + "s = [10, 14.5, 19.5, 25.5 , 32 ]\n", + "h = T[1]-T[0]\n", + "n = len(T)\n", + "def v(t):\n", + " if t in T and T.index(t) == 0:\n", + " V = (-3*s[T.index(t) ] + 4*s[T.index(t+h)] - s[T.index(t+2*h) ] ) /(2*h) #Three point forward difference formula\n", + " elif t in T and T.index(t) == n-1:\n", + " V = ( 3*s[T.index(t)] - 4*s[ T.index(t-h)] + s[T.index(t-2*h) ] )/(2*h) #Backward difference formula\n", + " else:\n", + " V = ( s[T.index(t+h)] - s[T.index(t-h)] )/(2*h) #Central difference formula\n", + " return V\n", + "\n", + "v_5 = v(5)\n", + "v_7 = v(7)\n", + "v_9 = v(9)\n", + "\n", + "print 'v(5) = ',v_5\n", + "print 'v(7) = ',v_7\n", + "print 'v(9) = ',v_9\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 11_06 Pg No. 359" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "a(7) = 0.5\n" + ] + } + ], + "source": [ + "T = range(5,10)\n", + "s = [10, 14.5 , 19.5 , 25.5, 32 ]\n", + "h = T[1]-T[0]\n", + "def a(t):\n", + " A = ( s[T.index(t+h) ] - 2*s[ T.index(t) ] + s[T.index(t-h) ] )/h**2\n", + " return A\n", + "a_7 = a(6)\n", + "\n", + "print 'a(7) = ',a_7" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 11_7 Pg No. 359" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "solving the above equations we get \n", + "\n", + " y1 = y(0.25) = -0.117562 \n", + " y2 = y(0.5) = -0.168475 \n", + " y3 = y(0.75) = -0.139088 \n", + " \n" + ] + } + ], + "source": [ + "from numpy import mat,divide,linalg\n", + "h = 0.25 #\n", + "#y''(x) = e**(x**2)\n", + "#y(0) = 0 , y(1) = 0\n", + "# y''(x) = y(x+h) - 2*y(x) + y(x-h)/h**2 = e**(x**2)\n", + "#( y(x + 0.25) - 2*y(x) + y(x-0.25) )/0.0625 = e**(x**2)\n", + "#y(x+0.25) - 2*y(x) + y(x - 0.25) = 0.0624*e**(x**2)\n", + "#y(0.5) - 2*y(0.25) + y(0) = 0.0665\n", + "#y(0.75) - 2*y(0.5) + y(0.25) = 0.0803\n", + "#y(1) - 2*y(0.75) + y(0.5) = 0.1097\n", + "#given y(0) = y(1) = 0\n", + "#\n", + "#0 + y2 - 2y1 = 0.06665\n", + "#y3 - 2*y2 + y1 = 0.0803\n", + "#-2*y3 + y2 + 0 = 0.1097\n", + "#Therefore\n", + "A = mat([[0, 1, -2],[1, -2, 1],[-2, 1, 0 ]])\n", + "B = mat([[ 0.06665],[0.0803] ,[0.1097 ]])\n", + "C = linalg.solve(A,B)\n", + "print 'solving the above equations we get \\n\\n y1 = y(0.25) = %f \\n y2 = y(0.5) = %f \\n y3 = y(0.75) = %f \\n '%(C[2],C[1],C[0])" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 11_08 Pg No. 362" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "richardsons technique -\n", + "\n", + "df(0.5) = 1.64850499031\n", + "D(rh) = D(0.25) = 1.71828182846\n", + "D(0.5) = 1.66594919985\n", + "Exact df(0.5) = 1.93757920531\n", + "The result by richardsons technique is much better than other results\n", + "for r = 2\n", + "df(x) = 1.64518270284\n", + "D(rh) = 1.93757920531\n" + ] + } + ], + "source": [ + "from numpy import arange,exp\n", + "from scipy.misc import derivative\n", + "\n", + "x = arange(-0.5,0.25+1.5,0.25)\n", + "h = 0.5 ;\n", + "r = 1.0/2 ;\n", + "\n", + "def f(x):\n", + " F = exp(x)\n", + " return F\n", + "def D(x,h):\n", + " D = (f(x + h) - f(x-h) )/(2*h) \n", + " return D\n", + "def df(x,h,r):\n", + " Df = (D(x,r*h) - r**2*D(x,h))/(1-r**2)\n", + " return Df\n", + "\n", + "df_05 = df(0.5,0.5,1.0/2);\n", + "print 'richardsons technique -\\n\\ndf(0.5) = ',df_05\n", + "print 'D(rh) = D(0.25) = ',D(0.5,0.5)\n", + "print 'D(0.5) = ',D(0.5,0.25)\n", + "\n", + "dfexact = derivative(f,0.5)\n", + "print 'Exact df(0.5) = ',dfexact\n", + "print 'The result by richardsons technique is much better than other results'\n", + "\n", + "#r = 2\n", + "print 'for r = 2'\n", + "print 'df(x) = ',df(0.5,0.5,2)\n", + "print 'D(rh) = ',D(0.5,2*0.5)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.9" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Numerical_Methods_by_E._Balaguruswamy/chapter12.ipynb b/Numerical_Methods_by_E._Balaguruswamy/chapter12.ipynb new file mode 100644 index 00000000..9bd54b00 --- /dev/null +++ b/Numerical_Methods_by_E._Balaguruswamy/chapter12.ipynb @@ -0,0 +1,518 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Chapter 12 - Numerical integration" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 12_01 Pg No. 373" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "case(a)\n", + "It = 5\n", + "Ett = 1.0\n", + "Iexact = 4.75\n", + "True error = 0.25 Here Error bound is an overestimate of true error\n", + "case(b)\n", + "It = 1.59375\n", + "Ett = 0.09375\n", + "Iexact = 1.515625\n", + "True error = 0.078125 Here Error bound is an overestimate of true error\n" + ] + } + ], + "source": [ + "from scipy.misc import derivative\n", + "from mpmath import quad\n", + "#Trapezoidal Rule\n", + "\n", + "def f(x):\n", + " F = x**3 + 1\n", + " return F\n", + "\n", + "#case(a)\n", + "a = 1#\n", + "b = 2 #\n", + "h = b - a #\n", + "It = (b-a)*(f(a)+f(b))/2\n", + "d2f = derivative(f,2,n=2)\n", + "Ett = h**3*d2f/12.0\n", + "Iexact = quad(f,[1,2])\n", + "Trueerror = It - Iexact\n", + "print 'case(a)'\n", + "print 'It = ',It\n", + "print 'Ett = ',Ett\n", + "print 'Iexact = ',Iexact\n", + "print 'True error = ',Trueerror,\n", + "print 'Here Error bound is an overestimate of true error'\n", + "\n", + "#case(b)\n", + "a = 1#\n", + "b = 1.5 #\n", + "h = b - a #\n", + "It = (b-a)*(f(a)+f(b))/2\n", + "Ett = h**3*derivative(f,1.5,n=2)/12\n", + "Iexact = quad(f,[1,1.5])\n", + "Trueerror = It - Iexact\n", + "print 'case(b)'\n", + "print 'It = ',It\n", + "print 'Ett = ',Ett\n", + "print 'Iexact = ',Iexact\n", + "print 'True error = ',Trueerror,\n", + "print 'Here Error bound is an overestimate of true error'\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 12_02 Pg No. 376" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "intergral for case(a),Ia = 2.54308063482\n", + "intergral for case(b),Ib = 0.0\n", + "exact integral,Iexact = 2.3504\n", + "n = 4 case is better than n = 2 case\n" + ] + } + ], + "source": [ + "from math import exp\n", + "#Tapezoidal rule\n", + "\n", + "\n", + "def f(x):\n", + " F = exp(x)\n", + " return F\n", + "a = -1 #\n", + "b = 1 #\n", + "\n", + "#case(a)\n", + "n = 2\n", + "h = (b-a)/n \n", + "I = 0\n", + "for i in range(1,n+1):\n", + " I = I + f(a+(i-1)*h)+f(a+i*h)\n", + "\n", + "I = h*I/2 #\n", + "print 'intergral for case(a),Ia = ',I\n", + "\n", + "#case(b)\n", + "n = 4\n", + "h = (b-a)/n \n", + "I = 0\n", + "for i in range(1,n+1):\n", + " I = I + f(a+(i-1)*h)+f(a+i*h)#\n", + "\n", + "I = h*I/2 #\n", + "Iexact = 2.35040\n", + "print 'intergral for case(b),Ib = ',I\n", + "print 'exact integral,Iexact = ',Iexact\n", + "print 'n = 4 case is better than n = 2 case'" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 12_03 Pg No. 381" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "h = 1\n", + "Integral for case(a) , Is1 = 2.36205375654\n", + "h = 0.785398163397\n", + "Integral for case(b),Is1 = 1.14238405466\n" + ] + } + ], + "source": [ + "from math import pi,sin,exp,sqrt\n", + "#Simpon's 1/3 rule\n", + "\n", + "#case(a)\n", + "def f(x):\n", + " F = exp(x)\n", + " return F\n", + "a = -1#\n", + "b = 1#\n", + "h = (b-a)/2 \n", + "x1 = a+h\n", + "Is1 = h*( f(a) + f(b) + 4*f(x1) )/3 \n", + "print 'h = ',h\n", + "print 'Integral for case(a) , Is1 = ',Is1\n", + "\n", + "#case(b)\n", + "def f(x):\n", + " F = sqrt(sin(x))\n", + " return F\n", + "a = 0\n", + "b = pi/2\n", + "h = (b-a)/2 \n", + "x1 = a+h\n", + "Is1 = h*( f(a) + f(b) + 4*f(x1) )/3\n", + "print 'h = ',h\n", + "print 'Integral for case(b),Is1 = ',Is1" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 12_04 Pg No.382" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "h = 0.392699081699\n", + "Integral value for n = 4 is 1.17822754435\n", + "h = 0.261799387799\n", + "Integral value for n = 6 is 1.18728120346\n" + ] + } + ], + "source": [ + "from math import pi,sin,exp,sqrt\n", + "#Simpon's 1/3 rule\n", + "\n", + "def f(x):\n", + " F = sqrt( sin(x) )\n", + " return F\n", + "x0 = 0 #\n", + "xa = pi/2 #\n", + "\n", + "#case(a) n = 4\n", + "n = 4 #\n", + "h = ( xa-x0 )/n\n", + "I = 0 \n", + "for i in range(1,n/2+1):\n", + " I = I + f(x0 + (2*i-2)*h) + 4*f(x0 + (2*i-1)*h) + f(x0 + 2*i*h) #\n", + "I = h*I/3\n", + "print 'h = ',h\n", + "print 'Integral value for n = 4 is',I \n", + "\n", + "#case(b) n = 6\n", + "n = 6\n", + "h = ( xa-x0 )/n\n", + "I = 0 \n", + "for i in range(1,n/2+1):\n", + " I = I + f(x0 + (2*i-2)*h) + 4*f(x0 + (2*i-1)*h) + f(x0 + 2*i*h) #\n", + "\n", + "I = h*I/3\n", + "print 'h = ',h\n", + "print 'Integral value for n = 6 is',I" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 12_05 Pg No. 386" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Integral of x**3 +1 from 1 to 2 : 0\n", + "Integral of sqrt(sin(x)) from 0 to pi/2: 1.16104132669\n" + ] + } + ], + "source": [ + "from math import pi,sin,exp,sqrt\n", + "\n", + "#Simpson's 3/8 rule\n", + "\n", + "#case(a)\n", + "def f(x):\n", + " F = x**3 + 1\n", + " return F\n", + "a = 1 #\n", + "b = 2 #\n", + "h = (b-a)/3 \n", + "x1 = a + h \n", + "x2 = a + 2*h\n", + "Is2 = 3*h*( f(a) + 3*f(x1) + 3*f(x2) + f(b) )/8 #\n", + "print 'Integral of x**3 +1 from 1 to 2 : ',Is2\n", + "#case(b)\n", + "def f(x):\n", + " F = sqrt( sin(x) )\n", + " return F\n", + "a = 0 #\n", + "b = pi/2 #\n", + "h = (b-a)/3 \n", + "x1 = a + h \n", + "x2 = a + 2*h\n", + "Is2 = 3*h*( f(a) + 3*f(x1) + 3*f(x2) + f(b) )/8 #\n", + "print 'Integral of sqrt(sin(x)) from 0 to pi/2:',Is2" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 12_06 Pg No. 387" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Ib = 1.18061711033\n" + ] + } + ], + "source": [ + "from math import sin,sqrt,pi\n", + "#Booles's Five-Point formula\n", + "\n", + "def f(x):\n", + " F = sqrt( sin(x) )\n", + " return F\n", + "x0 = 0#\n", + "xb = pi/2 #\n", + "n = 4 #\n", + "h = (xb - x0)/n\n", + "Ib = 2*h*(7*f(x0) + 32*f(x0+h) + 12*f(x0 + 2*h) + 32*f(x0+3*h) + 7*f(x0+4*h))/45#\n", + "print 'Ib = ',Ib" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 12_07 Pg No. 391" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "R(0,0) = 0.75\n", + "\n", + "R(1,0) = 0.333333 \n", + "\n", + "\n", + "R(2,0) = 0.342857 \n", + "\n", + "\n", + "R(1,1) = 0.194444 \n", + "\n", + "\n", + "R(2,1) = 0.346032 \n", + "\n", + "\n", + "R(2,2) = 0.356138 \n", + "\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from numpy import zeros\n", + "def f(x):\n", + " F = 1.0/x\n", + " return F\n", + "#since we can't have (0,0) element in matrix we start with (1,1)\n", + "a = 1 ;\n", + "b = 2 ;\n", + "h = b-a ;\n", + "R=zeros([3,3])\n", + "R[0,0] = h*(f(a)+f(b))/2 \n", + "print 'R(0,0) = ',R[0,0]\n", + "\n", + "h=[h]\n", + "for i in range(2,4):\n", + " h.append((b-a)/2**(i-1))\n", + " s = 0\n", + " for k in range(1,2**(i-2)+1):\n", + " s = s + f(a + (2*k - 1)*h[i-1]);\n", + " \n", + " R[i-1,0] = R[i-1,0]/2 + h[i-1]*s;\n", + " print '\\nR(%i,0) = %f \\n'%(i-1,R[i-1,0])\n", + "\n", + "for j in range(2,4):\n", + " for i in range(j,4):\n", + " R[i-1,j-1] = (4**(j-1)*R[i-1,j-2] - R[i-2,j-2])/(4**(j-1)-1);\n", + " print '\\nR(%i,%i) = %f \\n'%(i-1,j-1,R[i-1,j-1])" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 12_08 Pg No. 397" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "x1 = -0.57735026919\n", + "x2 = 0.57735026919\n", + "I = 2.34269608791\n" + ] + } + ], + "source": [ + "from math import sqrt,exp \n", + "#Two Point Gauss -Legedre formula\n", + "\n", + "def f(x):\n", + " F = exp(x)\n", + " return F\n", + "x1 = -1/sqrt(3)\n", + "x2 = 1/sqrt(3)\n", + "I = f(x1) + f(x2)\n", + "print 'x1 = ',x1\n", + "print 'x2 = ',x2\n", + "print 'I = ',I, " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 12_09 Pg No. 398" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " g(z) = exp(-(2.000000*z + 0.000000)/2) \n", + " C = 2.000000 \n", + " Ig = 4.685392 \n", + "\n" + ] + } + ], + "source": [ + "from math import sqrt,exp\n", + "#Gaussian two point formula\n", + "\n", + "a = -2 #\n", + "b = 2 #\n", + "def f(x):\n", + " F = exp(-x/2)\n", + " return F\n", + "A = (b-a)/2 \n", + "B = (a+b)/2\n", + "C = (b-a)/2\n", + "def g(z):\n", + " G = exp(-1*(A*z+B)/2)\n", + " return G\n", + "w1 = 1 #\n", + "w2 = 1 #\n", + "z1 = -1/sqrt(3)\n", + "z2 = 1/sqrt(3)\n", + "Ig = C*( w1*g(z1) + w2*g(z2) )\n", + "print ' g(z) = exp(-(%f*z + %f)/2) \\n C = %f \\n Ig = %f \\n'%(A,B,C,Ig)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.9" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Numerical_Methods_by_E._Balaguruswamy/chapter13.ipynb b/Numerical_Methods_by_E._Balaguruswamy/chapter13.ipynb new file mode 100644 index 00000000..2aa34503 --- /dev/null +++ b/Numerical_Methods_by_E._Balaguruswamy/chapter13.ipynb @@ -0,0 +1,911 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Chapter 13 - Numerical solution of ordinary differential equations" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 13_01 Pg No. 414" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " y(0.25) = 5.3125\n", + " y(0.5) = 7.40685424949\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from math import sqrt\n", + "#Taylor method\n", + "\n", + "def f(x,y):\n", + " F = x**2 + y**2\n", + " return F\n", + "def d2y(x,y):\n", + " D2Y = 2*x + 2*y*f(x,y)\n", + " return D2Y\n", + "def d3y(x,y):\n", + " D3Y = 2 + 2*y*d2y(x,y) + 2*f(x,y)**2\n", + " return D3Y\n", + "def y(x):\n", + " Y = 1 + f(0,1)*x + d2y(0,1)*x**2/2 + d3y(0,1)*sqrt(x)\n", + " return Y\n", + "print ' y(0.25) = ',y(0.25)\n", + "print ' y(0.5) = ',y(0.5)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 13_02 Pg No. 415" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " Iteration-1\n", + "\n", + " dy(0) = 0.000000\n", + " d2y(0) = 0.000000\n", + " d3y(0) = 2.000000\n", + " d4y(0) = 0.000000\n", + " \n", + "y(0) = 0.002667\n", + "\n", + "\n", + " Iteration-2\n", + "\n", + " dy(0) = 0.040007\n", + " d2y(0) = 0.400213\n", + " d3y(0) = 2.005336\n", + " d4y(0) = 0.106763\n", + " \n", + "y(0) = 0.021353\n", + "\n", + "\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from scipy.misc import factorial\n", + "#Recursive Taylor Method\n", + "\n", + "def f(x,y):\n", + " F = x**2 + y**2\n", + " return F\n", + "def d2y(x,y):\n", + " D2Y = 2*x + 2*y*f(x,y)\n", + " return D2Y\n", + "def d3y(x,y):\n", + " D3Y = 2 + 2*y*d2y(x,y) + 2*f(x,y)**2\n", + " return D3Y\n", + "def d4y(x,y):\n", + " D4Y = 6*f(x,y)*d2y(x,y) + 2*y*d3y(x,y)\n", + " return D4Y\n", + "h = 0.2 #\n", + "def y(x,y):\n", + " Y = y + f(x,y)*h + d2y(x,y)*h**2/2 + d3y(x,y)*h**3/6 + d4y(x,y)*h**4/factorial(4)\n", + " return Y\n", + "x0 = 0#\n", + "y0 = 0 #\n", + "y_=[]\n", + "for i in range(1,3):\n", + " y_.append(y(x0,y0))\n", + " print ' Iteration-%d\\n\\n dy(0) = %f\\n d2y(0) = %f\\n d3y(0) = %f\\n d4y(0) = %f\\n '%(i,f(x0,y0),d2y(x0,y0),d3y(x0,y0),d4y(x0,y0)) \n", + " x0 = x0 + i*h\n", + " y0 = y_[i-1]\n", + " print 'y(0) = %f\\n\\n'%(y_[i-1])" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 13_03 Pg No. 417" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "for dy(x) = x**2 + y**2 the results are :\n", + "y(0.1) = 0.000333334920635\n", + "y(0.2) = 0.00266686984127\n", + "y(1) = 0.349206349206\n", + "for dy(x) = x*e**y the results are \n", + "y(0.1) = 0.0050125208594\n", + "y(0.2) = 0.0202013400268\n", + "y(1) = 0.6487212707\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from math import exp \n", + "#Picard's Method\n", + "\n", + "#y'(x) = x**2 + y**2,y(0) = 0\n", + "#y(1) = y0 + integral(x**2 + y0**2,x0,x)\n", + "#y(1) = x**3/3\n", + "#y(2) = 0 + integral(xY2 + y1**2,x0,x)\n", + "# = integral(x**2 + x**6/9,0,x) = x**3/3 + x**7/63\n", + "#therefore y(x) = x**3 /3 + x**7/63\n", + "def y(x):\n", + " Y = x**3/3 + x**7/63 \n", + " return Y\n", + "print 'for dy(x) = x**2 + y**2 the results are :'\n", + "print 'y(0.1) = ',y(0.1)\n", + "print 'y(0.2) = ',y(0.2)\n", + "print 'y(1) = ',y(1)\n", + "\n", + "#y'(x) = x*e**y, y(0) = 0\n", + "#y0 = 0 , x0 = 0\n", + "#Y(1) = 0 + integral(x*e**0,0,x) = x**2/2\n", + "#y(2) = 0 + integral( x*e**( x**2/2 ) ,0,x) = e**(x**2/2)-1\n", + "#therefore y(x) = e**(x**2/2) - 1\n", + "def y(x):\n", + " Y = exp(x**2/2) - 1 \n", + " return Y\n", + "print 'for dy(x) = x*e**y the results are ' \n", + "print 'y(0.1) = ',y(0.1)\n", + "print 'y(0.2) = ',y(0.2)\n", + "print 'y(1) = ',y(1)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 13_04 Pg No. 417" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "for h = 0.500000\n", + "\n", + "y(1.500000) = 4.000000\n", + "\n", + "y(2.000000) = 7.875000\n", + "\n", + "\n", + "for h = 0.250000\n", + "\n", + "y(1.250000) = 3.000000\n", + "\n", + "y(1.500000) = 4.421875\n", + "\n", + "y(1.750000) = 6.359375\n", + "\n", + "y(2.000000) = 8.906250\n", + "\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "\n", + "#Euler's Method\n", + "\n", + "def dy(x):\n", + " DY = 3*x**2 + 1\n", + " return DY\n", + "x0 = 1\n", + "y = [0,2] #\n", + "#h = 0.5\n", + "h = 0.5\n", + "print 'for h = %f\\n'%(h)\n", + "for i in range(2,4):\n", + " y.append(y[i-1] + h*dy(x0+(i-2)*h))\n", + " print 'y(%f) = %f\\n'%(x0+(i-1)*h,y[i])\n", + "\n", + "#h = 0.25\n", + "h = 0.25\n", + "print '\\nfor h = %f\\n'%(h)\n", + "y = [0,2] #\n", + "for i in range(2,6):\n", + " y.append(y[i-1] + h*dy(x0+(i-2)*h))\n", + " print 'y(%f) = %f\\n'%(x0+(i-1)*h,y[i])" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 13_05 Pg No. 422" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + " Step 1 \n", + " x(1) = 1.500000\n", + " y(1.500000) = 4.000000\n", + "\n", + "\n", + " Et(1) = 0.875000\n", + "\n", + "\n", + " Step 2 \n", + " x(2) = 2.000000\n", + " y(2.000000) = 7.875000\n", + "\n", + "\n", + " Et(2) = 1.250000\n", + "\n", + "x Est y true y Et Globalerr\n", + "1.5 \t4.0 \t4.875 \t0.875 \t0.875\n", + "2.0 \t7.875 \t10.0 \t1.25 \t2.125\n" + ] + } + ], + "source": [ + "from numpy import nditer\n", + "from __future__ import division\n", + "#Error estimation in Euler's Method\n", + "\n", + "def dy(x):\n", + " DY = 3*x**2 + 1\n", + " return DY\n", + "def d2y(x):\n", + " D2Y = 6*x\n", + " return D2Y\n", + "def d3y(x):\n", + " D3Y = 6\n", + " return D3Y\n", + "def exacty(x):\n", + " Exacty = x**3 + x\n", + " return Exacty\n", + "x0 = 1\n", + "y = 2\n", + "h = 0.5\n", + "X=[];ESTY=[];TRUEY=[];ET=[];GERR=[];\n", + "for i in range(2,4):\n", + " x = x0 + (i-1)*h\n", + " y = y + h*dy(x0+(i-2)*h)\n", + " print '\\n Step %d \\n x(%d) = %f\\n y(%f) = %f\\n'%(i-1,i-1,x,x,y)\n", + " Et = d2y(x0+(i-2)*h)*h**2/2 + d3y(x0+(i-2)*h)*h**3/6\n", + " print '\\n Et(%d) = %f\\n'%(i-1,Et)\n", + " truey = exacty(x0+(i-1)*h)\n", + " gerr = truey - y\n", + " X.append(x)\n", + " ESTY.append(y)\n", + " TRUEY.append(truey)\n", + " ET.append(Et)\n", + " GERR.append(gerr)\n", + "\n", + "#table = [x y(2:3) truey Et gerr]\n", + "print 'x Est y true y Et Globalerr' \n", + "for a,b,c,d,e in nditer([X,ESTY,TRUEY,ET,GERR]):\n", + " print a,'\\t',b,'\\t',c,'\\t',d,'\\t',e" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 13_06 Pg No. 427" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "EULERS METHOD\n", + "y(1.250000) = 3.000000 \n", + " \n", + "y(1.500000) = 4.200000 \n", + " \n", + "y(1.750000) = 5.600000 \n", + " \n", + "y(2.000000) = 7.200000 \n", + " \n", + "HEUNS METHOD\n", + "\n", + "Iteration 1 \n", + " m1 = 4.000000\n", + " ye(1.250000) = 3.000000 \n", + " m2 = 4.800000 \n", + " y(1.250000) = 3.100000 \n", + "\n", + "\n", + "Iteration 2 \n", + " m1 = 4.960000\n", + " ye(1.500000) = 4.340000 \n", + " m2 = 5.786667 \n", + " y(1.500000) = 4.443333 \n", + "\n", + "\n", + "Iteration 3 \n", + " m1 = 5.924444\n", + " ye(1.750000) = 5.924444 \n", + " m2 = 6.770794 \n", + " y(1.750000) = 6.030238 \n", + "\n", + "\n", + "Iteration 4 \n", + " m1 = 6.891701\n", + " ye(2.000000) = 7.753163 \n", + " m2 = 7.753163 \n", + " y(2.000000) = 7.860846 \n", + "\n", + "x Eulers Heuns \t\tAnalytical\n", + "0.0 \t0.0 \t0.000000 \t0.0\n", + "1.0 \t2.0 \t2.000000 \t2.0\n", + "1.25 \t3.0 \t3.100000 \t2.2360679775\n", + "1.5 \t4.2 \t4.443333 \t2.44948974278\n", + "1.75 \t5.6 \t6.030238 \t2.64575131106\n", + "2.0 \t7.2 \t7.860846 \t2.82842712475\n" + ] + } + ], + "source": [ + "from numpy import nditer,sqrt\n", + "from __future__ import division\n", + "\n", + "#Heun's Method\n", + "\n", + "def f(x,y):\n", + " F = 2*y/x \n", + " return F\n", + "def exacty(x):\n", + " Exacty = 2*sqrt(x)\n", + " return Exacty\n", + "x = [0,1] #\n", + "y = [0,2] #\n", + "h = 0.25 #\n", + "#Euler's Method\n", + "print 'EULERS METHOD'\n", + "for i in range(2,6):\n", + " x.append(x[i-1] + h )\n", + " y.append(y[i-1] + h*f(x[i-1],y[i-1]))\n", + " print 'y(%f) = %f \\n '%(x[i],y[i])\n", + "\n", + "eulery = y\n", + "#Heun's Method\n", + "print 'HEUNS METHOD'\n", + "ye=[0,0]\n", + "y = [0,2] #\n", + "for i in range(2,6):\n", + " m1 = f(x[i-1],y[i-1]) #\n", + " ye.append(y[i-1] + h*f(x[(i-1)],y[(i-1)]))\n", + " m2 = f(x[(i)],ye[(i)]) \n", + " y.append(y[(i-1)] + h*(m1 + m2)/2)\n", + " print '\\nIteration %d \\n m1 = %f\\n ye(%f) = %f \\n m2 = %f \\n y(%f) = %f \\n'%(i-1,m1,x[(i)],ye[(i)],m2,x[(i)],y[(i)]) \n", + " \n", + " \n", + "truey = exacty(x) \n", + "print 'x Eulers Heuns \\t\\tAnalytical' \n", + "for a,b,c,d in nditer([x,eulery,y,truey]):\n", + " print a,'\\t',b,'\\t%.6f'%c,'\\t',d\n", + " " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 13_07 Pg NO. 433" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "y(1.250000) = 3.111111 \n", + " \n", + "y(1.500000) = 4.468687 \n", + " \n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "\n", + "#Polygon Method\n", + "\n", + "def f(x,y):\n", + " F = 2*y/x\n", + " return F\n", + "x=[1]\n", + "y=[2]\n", + "h = 0.25 #\n", + "for i in range(1,3):\n", + " x.append(x[(i-1)] + h )\n", + " y.append(y[(i-1)] + h*f( x[(i-1)]+ h/2 , y[(i-1)] + h*f( x[(i-1)] , y[(i-1)] )/2 ))\n", + " print 'y(%f) = %f \\n '%(x[(i)],y[(i)])\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 13_08 Pg No. 439" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Iteration - 1\n", + " m1 = 0.000000\n", + " m2 = 0.010000 \n", + " m3 = 0.010001 \n", + " m4 = 0.040004 \n", + " y(0.200000) = 0.002667 \n", + "\n", + "\n", + "Iteration - 2\n", + " m1 = 0.040007\n", + " m2 = 0.090044 \n", + " m3 = 0.090136 \n", + " m4 = 0.160428 \n", + " y(0.400000) = 0.021360 \n", + "\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "\n", + "#Classical Runge Kutta Method\n", + "\n", + "def f(x,y):\n", + " F = x**2 + y**2\n", + " return F\n", + "h = 0.2\n", + "x=[0]\n", + "y=[0]\n", + "\n", + "for i in range(0,2):\n", + " m1 = f( x[(i)] , y[(i)] ) #\n", + " m2 = f( x[i] + h/2 , y[(i)] + m1*h/2 ) #\n", + " m3 = f( x[(i)] + h/2 , y[(i)] + m2*h/2 ) #\n", + " m4 = f( x[(i)] + h , y[(i)] + m3*h ) #\n", + " x.append(x[(i)] + h )\n", + " y.append(y[(i)] + (m1 + 2*m2 + 2*m3 + m4)*h/6 )\n", + " \n", + " print '\\nIteration - %d\\n m1 = %f\\n m2 = %f \\n m3 = %f \\n m4 = %f \\n y(%f) = %f \\n'%(i+1,m1,m2,m3,m4,x[(i+1)],y[(i+1)])\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 13_09 Pg No. 444" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "for four decimal places\n", + "h = 0.0143668085653\n", + "for six decimal places\n", + "h = 0.00454318377739\n", + "Note-We can use h = 0.01 for four decimal places and h = 0.004 for six decimal places\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "\n", + "#Optimum step size\n", + "\n", + "x = 0.8 #\n", + "h1 = 0.05 #\n", + "y1 = 5.8410870 #\n", + "h2 = 0.025 #\n", + "y2 = 5.8479637 #\n", + "\n", + "#d = 4\n", + "h = ((h1**4 - h2**4)*10**(-4)/(2*(y2 - y1)))**(1/4)\n", + "print 'for four decimal places'\n", + "print 'h = ',h \n", + "\n", + "#d = 6\n", + "h = ((h1**4 - h2**4)*10**(-6)/(2*(y2 - y1)))**(1/4)\n", + "print 'for six decimal places'\n", + "print 'h = ' ,h\n", + "print 'Note-We can use h = 0.01 for four decimal places and h = 0.004 for six decimal places'" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 13_10 Pg NO. 446" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "yp4 = 8.00914285714\n", + "fp4 = 8.00914285714 yc4 = 8.00266666667\n", + "f4 = 8.00266666667\n", + "yc4 = 8.00212698413\n", + "Note- the exact solution is y(2) = 8\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "\n", + "#Milne-Simpson Predictor-Corrector method\n", + "\n", + "def f(x,y):\n", + " F = 2*y/x\n", + " return F\n", + "x0 = 1 #\n", + "y0 = 2 #\n", + "h = 0.25 #\n", + "#Assuming y1 ,y2 and y3(required for milne-simpson formula) are estimated using Fourth- order Runge kutta method\n", + "x1 = x0 + h \n", + "y1 = 3.13 #\n", + "x2 = x1 + h \n", + "y2 = 4.5 #\n", + "x3 = x2 + h\n", + "y3 = 6.13 #\n", + "#Milne Predictor formula\n", + "yp4 = y0 + 4*h*(2*f(x1,y1) - f(x2,y2) + 2*f(x3,y3))/3\n", + "x4 = x3 + h \n", + "fp4 = f(x4,yp4) #\n", + "print 'yp4 = ',yp4\n", + "print 'fp4 = ',fp4, \n", + "#Simpson Corrector formula\n", + "yc4 = y2 + h*( f(x2,y2) + 4*f(x3,y3) + fp4)/3 \n", + "f4 = f(x4,yc4)\n", + "print 'yc4 = ',yc4\n", + "print 'f4 = ',f4 \n", + "\n", + "yc4 = y2 + h*( f(x2,y2) + 4*f(x3,y3) + f4)/3 \n", + "print 'yc4 = ',yc4 \n", + "print 'Note- the exact solution is y(2) = 8'" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 13_11 Pg NO. 446" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Adams Predictor formula\n", + "yp4 = 8.01135714286\n", + "fp4 = 8.01135714286\n", + "\n", + "Adams Corrector formula\n", + "yc4 = 8.00727901786\n", + "f4 = 8.00727901786\n", + "\n", + "refined-yc4 = 8.00689669364\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "\n", + "#Adams-Bashforth-Moulton Method\n", + "\n", + "def f(x,y):\n", + " F = 2*y/x\n", + " return F\n", + "x0 = 1 #\n", + "y0 = 2 #\n", + "h = 0.25 #\n", + "x1 = x0 + h \n", + "y1 = 3.13 #\n", + "x2 = x1 + h \n", + "y2 = 4.5 #\n", + "x3 = x2 + h\n", + "y3 = 6.13 #\n", + "#Adams Predictor formula\n", + "yp4 = y3 + h*(55*f(x3,y3) - 59*f(x2,y2) + 37*f(x1,y1) - 9*f(x0,y0))/24\n", + "x4 = x3 + h \n", + "fp4 = f(x4,yp4) \n", + "print 'Adams Predictor formula'\n", + "print 'yp4 = ',yp4 \n", + "print 'fp4 = ',fp4 \n", + "#Adams Corrector formula\n", + "yc4 = y3 + h*( f(x1,y1) - 5*f(x2,y2) + 19*f(x3,y3) + 9*fp4 )/24 \n", + "f4 = f(x4,yc4)\n", + "print '\\nAdams Corrector formula'\n", + "print 'yc4 = ',yc4 \n", + "print 'f4 = ',f4 \n", + "\n", + "yc4 = y3 + h*( f(x1,y1) - 5*f(x2,y2) + 19*f(x3,y3) + 9*f4 )/24 \n", + "print '\\nrefined-yc4 = ',yc4" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 13_12 Pg No. 453" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + " y4p = 0.557351\n", + " f4p = -0.310640 \n", + " y4c = 0.555396 \n", + " Modifier Etc = 0.000067 \n", + " Modified y4c = 0.555464 \n", + "\n", + "\n", + " y5p = 0.500837\n", + " f5p = -0.250837 \n", + " y5c = 0.499959 \n", + " Modifier Etc = 0.000030 \n", + " Modified y5c = 0.499989 \n", + "\n", + "error = 1.11332736336e-05\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "\n", + "#Milne-Simpson Method using modifier\n", + "\n", + "def f(y):\n", + " F = -y**2\n", + " return F\n", + "x = [ 1 , 1.2 , 1.4 , 1.6 ] \n", + "y = [ 1 , 0.8333333 , 0.7142857 , 0.625 ] \n", + "h = 0.2 #\n", + "\n", + "for i in range(0,2):\n", + " yp = y[(i)] + 4*h*( 2*f( y[(i+1)] ) - f( y[(i+2)] ) + 2*f( y[(i+3)] ) )/3\n", + " fp = f(yp) #\n", + " yc = y[( i+2)] + h*(f( y[(i+2)] ) + 4*f( y[(i+3)] ) + fp )/3 \n", + " Etc = -(yc - yp)/29\n", + " y.append(yc + Etc)\n", + " print '\\n y%dp = %f\\n f%dp = %f \\n y%dc = %f \\n Modifier Etc = %f \\n Modified y%dc = %f \\n'%(i+4,yp,i+4,fp,i+4,yc,Etc,i+4,y[(i+4)])\n", + "exactanswer = 0.5 #\n", + "err = exactanswer - y[5] #\n", + "print 'error = ',err" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 13_13 Pg No. 455" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "m1(1) = 0.000000\n", + " m1(2) = 1.000000\n", + " m2(1) = 0.200000\n", + " m2(2) = 1.100000\n", + " m(1) = 0.100000\n", + " m(2) = 1.050000\n", + " y1(0.1) = 1.010000\n", + " y2(0.1) = -0.895000\n", + "\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "\n", + "#System of differetial Equations\n", + "\n", + "def f1(x,y1,y2):\n", + " F1 = x + y1 + y2 \n", + " return F1\n", + "def f2(x,y1,y2):\n", + " F2 = 1 + y1 + y2 \n", + " return F2\n", + "\n", + "x0 = 0 #\n", + "y10 = 1 #\n", + "y20 = -1 #\n", + "h = 0.1 #\n", + "m1= [f1( x0 , y10 , y20 )]\n", + "m1.append(f2( x0 , y10 , y20 ))\n", + "m2=[f1( x0+h , y10 + h*m1[0] , y20 + h*m1[1] )]\n", + "m2.append(f2( x0+h , y10 + h*m1[0] , y20 + h*m1[1] ))\n", + "m= [(m1[0] + m2[0])/2 ]\n", + "m.append((m1[1] + m2[1])/2)\n", + "\n", + "y1_0_1 = y10 + h*m[0]\n", + "y2_0_1 = y20 + h*m[1]\n", + "\n", + "print 'm1(1) = %f\\n m1(2) = %f\\n m2(1) = %f\\n m2(2) = %f\\n m(1) = %f\\n m(2) = %f\\n y1(0.1) = %f\\n y2(0.1) = %f\\n'%(m1[0],m1[1],m2[0],m2[1],m[0],m[1],y1_0_1,y2_0_1) " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 13_14 Pg No. 457" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "m1(1) = 1.000000\n", + " m1(2) = -2.000000\n", + " m2(1) = 0.600000\n", + " m2(2) = 0.600000\n", + " m(1) = 0.800000\n", + " m(2) = -0.700000\n", + " y1(0.1) = 0.160000\n", + " y2(0.1) = 0.860000\n", + "\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "#Higher Order Differential Equations\n", + "\n", + "x0 = 0\n", + "y10 = 0\n", + "y20 = 1\n", + "h = 0.2\n", + "m1 = [y20] #\n", + "m1.append(6*x0 + 3*y10 - 2*y20)\n", + "m2= [y20 + h*m1[1]]\n", + "m2.append(6*(x0+h) + 3*(y10 + h*m1[0]) - 2*(y20 + h*m1[1]) )\n", + "m = [(m1[0] + m2[0])/2 ]\n", + "m.append((m1[1] + m2[1])/2)\n", + "\n", + "y1_0_2 = y10 + h*m[0]\n", + "y2_0_2 = y20 + h*m[1]\n", + "\n", + "print 'm1(1) = %f\\n m1(2) = %f\\n m2(1) = %f\\n m2(2) = %f\\n m(1) = %f\\n m(2) = %f\\n y1(0.1) = %f\\n y2(0.1) = %f\\n'%(m1[0],m1[1],m2[0],m2[1],m[0],m[1],y1_0_2,y2_0_2) " + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.9" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Numerical_Methods_by_E._Balaguruswamy/chapter14.ipynb b/Numerical_Methods_by_E._Balaguruswamy/chapter14.ipynb new file mode 100644 index 00000000..dbc3001f --- /dev/null +++ b/Numerical_Methods_by_E._Balaguruswamy/chapter14.ipynb @@ -0,0 +1,374 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Chapter 14 - Boundary value and eigen value problems" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 14_01 Pg No. 467" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "B1 = 7.75\n", + "Since B1 is less than B , let z(1) = y(1) = 4*(M2)\n", + "B2 = 9.75\n", + "Since B2 is larger than B ,let us have third estimate of z(1) = M3 \n", + "B3 = 9.0\n", + "The solution is [2, 4.375, 9.0]\n" + ] + } + ], + "source": [ + "#Shooting Method\n", + "\n", + "def heun(f,x0,y0,z0,h,xf):\n", + " x = [x0] #\n", + " global y\n", + " y = [y0] #\n", + " z = [z0] #\n", + " n = (xf - x0)/h\n", + " m1=[0,0];m2=[0,0];m=[0,0]\n", + " for i in range(0,int(n)):\n", + " m1[0] = z[i] \n", + " m1[1] = f(x[i],y[i])\n", + " m2[0] = z[i] + h*m1[1]\n", + " m2[1] = f(x[i]+h,y[i]+h*m1[0])\n", + " m[0] = (m1[0] + m2[0])/2 \n", + " m[1] = ( m1[1] + m2[1] )/2\n", + " x.append(x[(i)] + h)\n", + " y.append(y[(i)] + h*m[0])\n", + " z.append(z[(i)] + h*m[1])\n", + " \n", + " B = y[int(n)]\n", + " return B\n", + "\n", + "\n", + "def f(x,y):\n", + " F = 6*x\n", + " return F\n", + "\n", + "x0 = 1 #\n", + "y0 = 2 #\n", + "h = 0.5 #\n", + "z0 = 2\n", + "M1 = z0 \n", + "xf = 2\n", + "B = 9\n", + "B1 = heun(f,x0,y0,z0,h,xf)\n", + "print 'B1 = ',B1\n", + "\n", + "if B1 != B:\n", + " print 'Since B1 is less than B , let z(1) = y(1) = 4*(M2)'\n", + " z0 = 4\n", + " M2 = z0\n", + " B2 = heun(f,x0,y0,z0,h,xf)\n", + " print 'B2 = ',B2\n", + " if B2 != B:\n", + " print 'Since B2 is larger than B ,let us have third estimate of z(1) = M3 '\n", + " M3 = M2 - (B2 - B)*(M2 - M1)/(B2 - B1)\n", + " z0 = M3 \n", + " B3= heun(f,x0,y0,z0,h,xf)\n", + " print 'B3 = ',B3\n", + " print 'The solution is ',y" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 14_02 Pg No. 470" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " \n", + " The solution is \n", + " y1 = y(0.25) = -0.100203 \n", + " y2 = y(0.5) = -0.137907 \n", + " y3 = y(0.75) = -0.109079 \n", + " \n" + ] + } + ], + "source": [ + "from numpy import array,exp,zeros,vstack,hstack,linalg\n", + "#Finite Difference Method\n", + "\n", + "def d2y(x):\n", + " D2Y = exp(x**2)\n", + " return D2Y\n", + "x_1 = 0#\n", + "y_0 = 0 #\n", + "y_1 = 0 #\n", + "h = 0.25\n", + "xf = 1\n", + "n = (xf-x_1)/h\n", + "A=zeros([int(n-1),int(n-1)])\n", + "B=zeros([int(n-1),1])\n", + "for i in range(0,int(n-1)):\n", + " A[i,:] = [1, -2, 1]\n", + " B[i,0] = exp((x_1 + i*h)**2)*h**2\n", + "\n", + "A[0,0] = 0 # #since we know y0 and y4\n", + "A[2,2] = 0 #\n", + "A[0,:] = hstack([ A[0,1:3], [0]]) #rearranging terms\n", + "A[2,0:3] = hstack([[ 0], A[2,0:2]]) \n", + "C=linalg.solve(A,B)\n", + "print ' \\n The solution is \\n y1 = y(0.25) = %f \\n y2 = y(0.5) = %f \\n y3 = y(0.75) = %f \\n '%(C[0],C[1],C[2]) " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 14_03 Pg No. 473" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + " The roots are \n", + " lamda1 = 4.000000 \n", + " lamda2 = 6.000000 \n", + " \n", + "X1 = Matrix([[1.00000000000000], [1]])\n", + "X2 = Matrix([[2.00000000000000], [1]])\n" + ] + } + ], + "source": [ + "#Eigen Vectors\n", + "from numpy import eye\n", + "from sympy import symbols,Matrix,det,solve\n", + "A = [[8 ,-4],[ 2, 2 ] ]\n", + "A=Matrix(A)\n", + "lamd = symbols('lamd')\n", + "p = det(A - lamd*eye(2))\n", + "root = solve(p,lamd)\n", + "print '\\n The roots are \\n lamda1 = %f \\n lamda2 = %f \\n '%(root[0],root[1])\n", + "A1 = A - root[0]*eye(2)\n", + "X1 = Matrix([[-1*A1[0,1]/A1[0,0]],[1]])\n", + "print 'X1 = ',X1\n", + "A2 = A - root[1]*eye(2)\n", + "X2 = Matrix([[-1*A2[0,1]/A2[0,0]],[ 1]])\n", + "print 'X2 = ',X2" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 14_04 Pg No. 474" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "A2 = \n", + "[[-5. 0. 0.]\n", + " [ 1. -8. 9.]\n", + " [ 0. 4. -9.]]\n", + "\n", + "p2 = -11.000000\n", + "\n", + "\n", + "A3 = \n", + "[[ -6. 0. 0.]\n", + " [ 1. -6. 27.]\n", + " [ 0. 8. -6.]]\n", + "\n", + "p3 = -6.000000\n", + "\n" + ] + } + ], + "source": [ + "from numpy import array,shape,trace,poly\n", + "#Fadeev - Leverrier method\n", + "\n", + "A = [[ -1, 0, 0],[ 1, -2, 3],[ 0, 2, -3 ]]\n", + "A=array(A)\n", + "r,c= shape(A)[0],shape(A)[1]\n", + "A1 = A\n", + "p= [trace(A1)]\n", + "for i in range(1,r):\n", + " A1 = A*( A1 - p[(i-1)]*eye(3))\n", + " p.append(trace(A1)/(i+1))\n", + " print '\\nA%d = '%(i+1)\n", + " print A1\n", + " print '\\np%d = %f\\n'%((i+1),p[i])" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 14_05 Pg No. 476" + ] + }, + { + "cell_type": "code", + "execution_count": 46, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + " Eigen vector - 1 \n", + " for lamda1 = 0.000000 \n", + " X1 = \n", + "[-inf nan nan]\n", + "\n", + " Eigen vector - 2 \n", + " for lamda2 = 0.000000 \n", + " X2 = \n", + "[ 0. 0. 0.]\n", + "\n", + " Eigen vector - 3 \n", + " for lamda3 = 0.000000 \n", + " X3 = \n", + "[ 0. 0. -1.]\n" + ] + } + ], + "source": [ + "import numpy as np\n", + "np.seterr(divide='ignore', invalid='ignore')\n", + "from __future__ import division\n", + "from numpy.linalg import eig\n", + "from numpy import array,diag\n", + "#Eigen Vectors\n", + "\n", + "A = [[ -1, 0, 0],[1, -2, 3],[0, 2, -3]]\n", + "A=array(A)\n", + "evectors,evalues = eig(A)\n", + "evectors=diag(evectors)\n", + "for i in range(0,3):\n", + " print '\\n Eigen vector - %d \\n for lamda%d = %f \\n X%d = '%(i+1,i+1,evalues[0,0],i+1)\n", + " evectors[:,0] = evectors[:,0]/evectors[1,i]\n", + " print evectors[:,i]" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 14_06 Pg No. 478" + ] + }, + { + "cell_type": "code", + "execution_count": 48, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Iterations:\n", + " 0 1 2 3 4 5 6 7 \n", + "X = [[ 0. 1. 0.8 1. 0.97560976 1.\n", + " 0.99726027 1. ]\n", + " [ 1. 0.5 1. 0.92857143 1. 0.99180328\n", + " 1. 0.99908592]\n", + " [ 0. 0. 0. 0. 0. 0. 0.\n", + " 0. ]]\n", + "\n", + "Y = [[None 2.0 2.0 2.8 2.8571428571428577 2.975609756097561 2.9836065573770494\n", + " 2.9972602739726026]\n", + " [None 1.0 2.5 2.6 2.928571428571429 2.951219512195122 2.9918032786885247\n", + " 2.9945205479452053]\n", + " [None 0.0 0.0 0.0 0.0 0.0 0.0 0.0]]\n" + ] + } + ], + "source": [ + "from numpy import array, zeros,expand_dims, dot, hstack\n", + "A = array([[ 1, 2, 0],[2, 1 ,0],[0, 0, -1 ]])\n", + "X=zeros([3,8])\n", + "Y=zeros([3,7])\n", + "X[:,0] =[0,1,0]\n", + "\n", + "for i in range(1,8):\n", + " Y[:,i-1] = [xx for xx in A.dot(expand_dims(X[:,i-1], axis=1))]\n", + " \n", + " X[:,i] = Y[:,i-1]/max(Y[:,i-1])\n", + "\n", + "print 'Iterations:\\n 0 1 2 3 4 5 6 7 '\n", + "print 'X = ',X\n", + "Y=hstack([[[None],[None],[None]],Y])\n", + "print '\\nY = ',Y\n" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.9" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Numerical_Methods_by_E._Balaguruswamy/chapter15.ipynb b/Numerical_Methods_by_E._Balaguruswamy/chapter15.ipynb new file mode 100644 index 00000000..0e991840 --- /dev/null +++ b/Numerical_Methods_by_E._Balaguruswamy/chapter15.ipynb @@ -0,0 +1,404 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Chapter 15 - Solution of partial differential equations" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 15_01 Pg No. 488" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + " The solution of the system is \n", + " f1 = 75 \n", + " f2 = 50 \n", + " f3 = 50 \n", + " f4 = 24 \n", + " \n" + ] + } + ], + "source": [ + "from numpy import zeros,mat\n", + "from numpy.linalg import solve\n", + "#Elliptic Equations\n", + "\n", + "l = 15\n", + "h = 5\n", + "n = 1 + 15/5\n", + "f=zeros([4,4])\n", + "f[0,0:3]=100\n", + "f[0:3,0]=100\n", + "\n", + "#At point 1 : f2 + f3 - 4f1 + 100 + 100 = 0\n", + "#At point 2 : f1 + f4 - 4f2 + 100 + 0 = 0\n", + "#At point 3 : f1 + f4 - 4f3 + 100 + 0 = 0\n", + "#At point 4 : f2 + f3 - 4f4 + 0 + 0 = 0\n", + "#\n", + "#Final Equations are\n", + "# -4f1 + f2 + f3 + 0 = -200\n", + "# f1 - 4f2 + 0 + f4 = -100\n", + "# f1 + 0 - 4f3 + f4 = -100\n", + "# 0 + f2 + f3 - 4f4 = 0\n", + "A = mat([[ -4, 1 ,1 ,0],[1, -4, 0 ,1],[1, 0 ,-4 ,1],[0, 1, 1, -4 ]])\n", + "B = mat([[-200],[-100],[-100],[0]])\n", + "C = solve(A,B)\n", + "print '\\n The solution of the system is \\n f1 = %d \\n f2 = %d \\n f3 = %d \\n f4 = %d \\n '%(C[0],C[1],C[2],C[3])" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 15_02 Pg No. 489" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "First row of below matrix represents iteration number:\n", + "[[ 0. 1. 2. 3. 4.]\n", + " [ 75. 75. 75. 75. 75.]\n", + " [ 0. 0. 0. 0. 0.]\n", + " [ 0. 0. 0. 0. 0.]\n", + " [ 0. 50. 50. 50. 50.]]\n" + ] + } + ], + "source": [ + "from numpy import zeros,mat\n", + "from numpy.linalg import solve\n", + "\n", + "#Liebmann's Iterative method\n", + "\n", + "f=zeros([4,4])\n", + "f[0,0:3]=100\n", + "f[0:3,0]=100\n", + "A=zeros([5,5])\n", + "A[0,0:5] = range(0,5)\n", + "for n in range(1,6):\n", + " for i in range(2,4):\n", + " for j in range(2,4):\n", + " if n == 1 and i == 2 and j == 2 :\n", + " f[i-1,j-1] = ( f[i,j] + f[i-2,j-2] + f[i-2,j] + f[i,j-2] )/4\n", + " else:\n", + " f[i,j] = ( f[i,j-1] + f[i-2,j-1] + f[i-1,j]+ f[i-1,j-2] )/4\n", + " A[1:5,n-1] = mat([f[1,1],f[1,2],f[2,1],f[2,2] ])\n", + "\n", + "\n", + "print 'First row of below matrix represents iteration number:\\n',A" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 15_03 Pg No. 490" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The solution is \n", + " f1 = -5.500000 \n", + " f2 = -10.750000 \n", + " f3 = -3.250000 \n", + " f4 = -5.500000 \n", + " \n" + ] + } + ], + "source": [ + "from numpy import zeros,mat\n", + "from numpy.linalg import solve\n", + "\n", + "#Poisson's Equation\n", + "\n", + "#D2f = 2*x**2 * y**2\n", + "# f = 0\n", + "# h = 1 \n", + "#Point 1 : 0 + 0 + f2 + f3 - 4f1 = 2(1)**2 * 2**2\n", + "# f2 + f3 - 4f1 = 8\n", + "#Point 2 : 0 + 0 + f1 + f4 -4f2 = 2*(2)**2*2**2\n", + "# f1 - 4f2 = f4 = 32\n", + "#Point 3 : 0 + 0 + f1 + f4 - 4f4 = 2*(1**2)*1**2\n", + "# f1 -4f3 + f4 = 2\n", + "#Point 4 : 0 + 0 + f2 + f3 - 4f4 = 2* 2**2 * 1**2\n", + "# f2 + f3 - 4f4 = 8\n", + "#Rearranging the equations\n", + "# -4f1 + f2 + f3 = 8\n", + "# f1 - 4f2 + f4 = 32\n", + "# f1 - 4f3 + f4 = 2\n", + "# f2 + f3 - 4f4 = 8\n", + "A = mat([[ -4, 1, 1, 0],[1, -4 ,0 ,1],[1, 0, -4, 1],[0, 1, 1, -4]])\n", + "B = mat([[ 8],[32],[2],[8 ]])\n", + "C = solve(A,B)\n", + "print 'The solution is \\n f1 = %f \\n f2 = %f \\n f3 = %f \\n f4 = %f \\n '%( C[0],C[1],C[2],C[3])" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 15_04 Pg No. 491" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + " Iteration 1\n", + " f1 = -2.000000, f2 = -9.000000, f3 = -2.000000, f4 = -2.000000\n", + "\n", + "\n", + " Iteration 2\n", + " f1 = -5.000000, f2 = -11.000000, f3 = -3.000000, f4 = -5.000000\n", + "\n", + "\n", + " Iteration 3\n", + " f1 = -6.000000, f2 = -11.000000, f3 = -4.000000, f4 = -6.000000\n", + "\n", + "\n", + " Iteration 4\n", + " f1 = -6.000000, f2 = -11.000000, f3 = -4.000000, f4 = -6.000000\n", + "\n" + ] + } + ], + "source": [ + "#Gauss-Seidel Iteration\n", + "\n", + "f2 = 0\n", + "f3 = 0\n", + "for i in range(1,5):\n", + " f1 = (f2 + f3 - 8)/4\n", + " f4 = f1 \n", + " f2 = (f1 + f4 -32)/4\n", + " f3 = (f1 + f4 - 2)/4\n", + " print '\\n Iteration %d\\n f1 = %f, f2 = %f, f3 = %f, f4 = %f\\n'%(i,f1,f2,f3,f4)\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 15_05 Pg No. 494" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The final results are \n", + "[[ 0. 150. 100. 50. 0. ]\n", + " [ 0. 50. 100. 50. 0. ]\n", + " [ 0. 50. 50. 50. 0. ]\n", + " [ 0. 25. 50. 25. 0. ]\n", + " [ 0. 25. 25. 25. 0. ]\n", + " [ 0. 12.5 25. 12.5 0. ]\n", + " [ 0. 12.5 12.5 12.5 0. ]]\n" + ] + } + ], + "source": [ + "from numpy import zeros,mat\n", + "\n", + "#Initial Value Problems\n", + "\n", + "h = 1 #\n", + "k = 2 #\n", + "tau = h**2/(2*k)\n", + "f=zeros([7,5])\n", + "for i in range(1,5):\n", + " f[0,i] = 50*( 4 - (i) )\n", + "\n", + "f[0:7,0] = 0\n", + "f[0:7,4] = 0 \n", + "for j in range(0,6):\n", + " for i in range(1,4):\n", + " f[j+1,i] = ( f[j,i-1] + f[j,i+1] )/2 \n", + "print 'The final results are \\n',f" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 15_06 Pg No. 497" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The final solution using crank nicholson implicit method is :\n", + "[[ 0. 150. 100. 50. 0. ]\n", + " [ 0. 42.85714286 71.42857143 42.85714286 0. ]\n", + " [ 0. 26.53061224 34.69387755 26.53061224 0. ]\n", + " [ 0. 13.70262391 20.11661808 13.70262391 0. ]\n", + " [ 0. 7.70512287 10.70387339 7.70512287 0. ]]\n" + ] + } + ], + "source": [ + "from numpy import zeros,mat,linalg\n", + "#Crank-Nicholson Implicit Method\n", + "\n", + "h = 1 #\n", + "k = 2 #\n", + "tau = h**2/(2*k)\n", + "f=zeros([5,5])\n", + "for i in range(1,4):\n", + " f[0,i] = 50*( 4 - (i) )\n", + "f[0:5,0] = 0 \n", + "f[0:5,4] = 0 \n", + "A = mat([[4, -1, 0 ],[-1 , 4 , -1 ],[0 , -1 , 4]])\n", + "B=zeros([3,1])\n", + "for j in range(0,4):\n", + " for i in range(1,4):\n", + " B[i-1,0] = f[j,i-1] + f[j,i+1]\n", + " \n", + " C = linalg.solve(A,B)\n", + " f[j+1,1] = C[0]\n", + " f[j+1,2] = C[1]\n", + " f[j+1,3] = C[2]\n", + "\n", + "print 'The final solution using crank nicholson implicit method is :\\n',f" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 15_07 Pg No. 500" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The values estimated are :\n", + "[[ 0. 4. 6. 6. 4. 0.]\n", + " [ 0. 3. 5. 5. 3. 0.]\n", + " [ 0. 1. 2. 2. 1. 0.]\n", + " [ 0. -1. -2. -2. -1. 0.]\n", + " [ 0. -3. -5. -5. -3. 0.]\n", + " [ 0. -4. -6. -6. -4. 0.]]\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from numpy import sqrt\n", + "#Hyperbolic Equations\n", + "\n", + "h = 1\n", + "Tbyp = 4\n", + "tau = sqrt(h**2 /4)\n", + "r = int(1+(2.5 - 0)/tau)\n", + "c = int(1+(5 - 0)/h)\n", + "\n", + "f=zeros([6,6])\n", + "for i in range(1,int(c)-1):\n", + " f[0,i] = (i)*(5 - (i) )\n", + "\n", + "f[0:r-1,0] = 0\n", + "f[0:r-1,c-1] = 0\n", + "g=[]\n", + "for i in range(1,c-1):\n", + " g.append(0)\n", + " f[1,i] = (f[0,i+1] + f[0,i-1])/2 + tau*g[i-1] \n", + "\n", + "for j in range(1,r-1):\n", + " for i in range(1,c-1):\n", + " f[j+1,i] = -f[j-1,i] + f[j,i+1] + f[j,i-1]\n", + " \n", + "\n", + "print 'The values estimated are :\\n',f" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.9" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Numerical_Methods_by_E._Balaguruswamy/chapter3.ipynb b/Numerical_Methods_by_E._Balaguruswamy/chapter3.ipynb new file mode 100644 index 00000000..d4901132 --- /dev/null +++ b/Numerical_Methods_by_E._Balaguruswamy/chapter3.ipynb @@ -0,0 +1,1170 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Chapter 3 - Computer codes and arithmetic" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 3_01 Pg No. 45" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Decimal value = 13.8125\n" + ] + } + ], + "source": [ + "#Binary to decimal\n", + "\n", + "b = '1101.1101'\n", + "def parse_bin(s):\n", + " t = s.split('.')\n", + " return int(t[0], 2) + int(t[1], 2) / 2.**len(t[1])\n", + "\n", + "d = parse_bin(b) # #Integral and fractional parts\n", + "print 'Decimal value = ',d" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 3_02 Pg No. 46" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Decimal value = 4783\n" + ] + } + ], + "source": [ + "#hexadecimal to decimal\n", + "\n", + "h = '12AF' \n", + "d=int(h,16)\n", + "print 'Decimal value = ',d" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 3_03 Pg No. 47" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Binary equivalent = 101011.011\n" + ] + } + ], + "source": [ + "#Decimal to Binary\n", + "\n", + "d = 43.375 #\n", + "\n", + "def parse_float(num):\n", + " exponent=0\n", + " shifted_num=num\n", + " while shifted_num != int(shifted_num): \n", + " shifted_num*=2\n", + " exponent+=1\n", + " if exponent==0:\n", + " return '{0:0b}'.format(int(shifted_num))\n", + " binary='{0:0{1}b}'.format(int(shifted_num),exponent+1)\n", + " integer_part=binary[:-exponent]\n", + " fractional_part=binary[-exponent:].rstrip('0')\n", + " return '{0}.{1}'.format(integer_part,fractional_part)\n", + "\n", + "b = parse_float(d) \n", + "print 'Binary equivalent = ',b" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 3_04 Pg No. 48" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Octal number = 243\n" + ] + } + ], + "source": [ + "#Decimal to Octal\n", + "\n", + "d = 163 #\n", + "def base10toN(num, base):\n", + " \"\"\"Change ``num'' to given base\n", + " Upto base 36 is supported.\"\"\"\n", + "\n", + " converted_string, modstring = \"\", \"\"\n", + " currentnum = num\n", + " if not 1 < base < 37:\n", + " raise ValueError(\"base must be between 2 and 36\")\n", + " if not num:\n", + " return '0'\n", + " while currentnum:\n", + " mod = currentnum % base\n", + " currentnum = currentnum // base\n", + " converted_string = chr(48 + mod + 7*(mod > 10)) + converted_string\n", + " return converted_string\n", + "\n", + "\n", + "\n", + "Oct = base10toN(d,8)\n", + "print 'Octal number = ',Oct" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 3_05 Pg No. 48" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Binary equivalent = 0.10100110011001100110011001100110011001100110011001101\n" + ] + } + ], + "source": [ + "#Decimal to binary\n", + "\n", + "d = 0.65\n", + "\n", + "def parse_float(num):\n", + " exponent=0\n", + " shifted_num=num\n", + " while shifted_num != int(shifted_num): \n", + " shifted_num*=2\n", + " exponent+=1\n", + " if exponent==0:\n", + " return '{0:0b}'.format(int(shifted_num))\n", + " binary='{0:0{1}b}'.format(int(shifted_num),exponent+1)\n", + " integer_part=binary[:-exponent]\n", + " fractional_part=binary[-exponent:].rstrip('0')\n", + " return '{0}.{1}'.format(integer_part,fractional_part)\n", + "\n", + "\n", + "b=parse_float(d) # binary equibvalent\n", + "print 'Binary equivalent = ',b" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 3_06 Pg No. 49 " + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Hexadecimal equivalent of octal number 243 is : a3\n" + ] + } + ], + "source": [ + "#Octal to Hexadecimal \n", + "\n", + "Oct = '243' \n", + "dec=int(Oct,8)\n", + "h = hex(dec)[2:]\n", + "\n", + "print 'Hexadecimal equivalent of octal number 243 is :',h" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 3_07 Pg No. 49" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Octal number equivalent of Hexadecimal number 39.B8 is: 57.71875\n" + ] + } + ], + "source": [ + "#Hexadecimal to Octal \n", + "\n", + "\n", + "h = '39.B8' #\n", + " \n", + " \n", + "def float_to_binary(num):\n", + " exponent=0\n", + " shifted_num=num\n", + " while shifted_num != int(shifted_num): \n", + " shifted_num*=2\n", + " exponent+=1\n", + " if exponent==0:\n", + " return '{0:0b}'.format(int(shifted_num))\n", + " binary='{0:0{1}b}'.format(int(shifted_num),exponent+1)\n", + " integer_part=binary[:-exponent]\n", + " fractional_part=binary[-exponent:].rstrip('0')\n", + " return '{0}.{1}'.format(integer_part,fractional_part)\n", + "\n", + "def floathex_to_binary(floathex):\n", + " num = float.fromhex(floathex)\n", + " return float_to_binary(num)\n", + "\n", + "b= floathex_to_binary(h)\n", + "def parse_bin(s):\n", + " t = s.split('.')\n", + " return int(t[0], 2) + int(t[1], 2) / 2.**len(t[1])\n", + "\n", + "d = parse_bin(b) # #Integral and fractional parts\n", + "print 'Octal number equivalent of Hexadecimal number 39.B8 is:',d\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 3_08 Pg No. 50" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Binary equivalent of -13 is : 10011\n" + ] + } + ], + "source": [ + "## -ve Integer to binary\n", + "\n", + "negint = -13\n", + "def to_twoscomplement(bits, value):\n", + " if value < 0:\n", + " value = ( 1<<bits ) + value\n", + " formatstring = '{:0%ib}' % bits\n", + " return formatstring.format(value)\n", + "\n", + "compl_2 = to_twoscomplement(5, negint)\n", + "\n", + "print 'Binary equivalent of -13 is :',compl_2" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 3_09 Pg No. 51" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Binary equivalent of -32768 in a 16 bit word is: 1000000000000000\n" + ] + } + ], + "source": [ + "#Binary representation\n", + "\n", + "n = -32768\n", + "\n", + "def to_twoscomplement(bits, value):\n", + " if value < 0:\n", + " value = ( 1<<bits ) + value\n", + " formatstring = '{:0%ib}' % bits\n", + " return formatstring.format(value)\n", + "\n", + "binfinal = to_twoscomplement(16, n)\n", + "\n", + "\n", + "print 'Binary equivalent of -32768 in a 16 bit word is:',binfinal " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 3_10 Pg No. 52" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + " 0.00596 is expressed as 0.596000*10**-2 \n", + "\n", + "\n", + " 65.7452 is expressed as 0.657452*10**2 \n", + "\n", + "\n", + " -486.8 is expressed as -0.486800*10**3 \n", + "\n" + ] + } + ], + "source": [ + "#Floating Point Notation\n", + "\n", + "def float_notation(n):\n", + " m = n #\n", + " for i in range(1,17):\n", + " if abs(m) >= 1:\n", + " m = n/10**i\n", + " e = i\n", + " elif abs(m) < 0.1:\n", + " m = n*10**i\n", + " e = -i\n", + " else:\n", + " if i == 1:\n", + " e = 0\n", + " \n", + " break \n", + " return [m,e]\n", + " \n", + "\n", + "[m,e] = float_notation(0.00596)\n", + "print '\\n 0.00596 is expressed as %f*10**%d \\n'%(m,e)\n", + "[m,e] = float_notation(65.7452)\n", + "print '\\n 65.7452 is expressed as %f*10**%d \\n'%(m,e)\n", + "[m,e] = float_notation(-486.8)\n", + "print '\\n -486.8 is expressed as %f*10**%d \\n'%(m,e)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 3_11 Pg No. 53" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "25+12 = 37\n", + "25-12 = 13\n", + "12-25 = -13\n", + "25*12 = 300\n", + "25/12 = 2\n", + "12/25 = 0\n" + ] + } + ], + "source": [ + "#Interger Arithmetic\n", + "\n", + "print '25+12 =',int(25 + 12)\n", + "print '25-12 =',int(25 - 12) \n", + "print '12-25 =',int(12 - 25)\n", + "print '25*12 =',int(25*12)\n", + "print '25/12 =',int(25/12)\n", + "print '12/25 =',int(12/25)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 3_12 Pg No. 53" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "(a+b)/c = 4 \n", + " a/c + b/c = 3\n", + "The results are not identical.This is because the remainder of an integer division is always truncated\n" + ] + } + ], + "source": [ + "#Integer Arithmetic\n", + "\n", + "a = 5 #\n", + "b = 7 #\n", + "c = 3 #\n", + "Lhs = int((a + b)/c)\n", + "Rhs = int(a/c) + int(b/c)\n", + "print '(a+b)/c = ',Lhs,'\\n a/c + b/c = ',Rhs\n", + "if Lhs != Rhs:\n", + " print 'The results are not identical.This is because the remainder of an integer division is always truncated'\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 3_13 Pg No. 54" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Ez= 5 \n", + " fy= 0.000964572 \n", + " fz= 0.587315572\n", + "\n", + " z = 0.587316 E5 \n", + "\n" + ] + } + ], + "source": [ + "#Floating Point Arithmetic\n", + "\n", + "fx = 0.586351 #\n", + "Ex = 5 #\n", + "fy = 0.964572 #\n", + "Ey = 2 #\n", + "v=[Ex,Ey]\n", + "Ez= max(v)\n", + "n=v.index(Ez)+1\n", + "if n == 1:\n", + " fy = fy*10**(Ey-Ex)\n", + " fz = fx + fy\n", + " if fz > 1:\n", + " fz = fz*10**(-1) \n", + " Ez = Ez + 1\n", + " \n", + " print 'Ez=',Ez,'\\n fy=',fy,'\\n fz=',fz\n", + "else:\n", + " fx = fx*10**(Ex - Ey)\n", + " fz = fx + fy\n", + " if fz > 1:\n", + " fz = fz*10**(-1)\n", + " Ez = Ez + 1\n", + " \n", + " print 'Ez=',Ez,'\\n fy=',fy,'\\n fz=',fz\n", + "\n", + "print '\\n z = %f E%d \\n'%(fz,Ez)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 3_14 Pg No. 54" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Ez= 5 \n", + " fy= 0.635742 \n", + " fz= 0.1371558\n", + "\n", + " z = 0.137156 E5 \n", + "\n" + ] + } + ], + "source": [ + "#Floating Point Arithmetic\n", + "\n", + "fx = 0.735816 #\n", + "Ex = 4 #\n", + "fy = 0.635742 #\n", + "Ey = 4 #\n", + "v=[Ex,Ey]\n", + "Ez= max(v)\n", + "n=v.index(Ez)+1\n", + "if n == 1:\n", + " fy = fy*10**(Ey-Ex)\n", + " fz = fx + fy\n", + " if fz > 1:\n", + " fz = fz*10**(-1)\n", + " Ez = Ez + 1\n", + " \n", + " print 'Ez=',Ez,'\\n fy=',fy,'\\n fz=',fz\n", + "else:\n", + " fx = fx*10**(Ex - Ey)\n", + " fz = fx + fy\n", + " if fz > 1:\n", + " fz = fz*10**(-1) \n", + " Ez = Ez + 1\n", + " \n", + " print 'Ez=',Ez,'\\n fy=',fy,'\\n fz=',fz\n", + "\n", + "print '\\n z = %f E%d \\n'%(fz,Ez)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 3_15 Pg No. 54" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Ez = -3 fz = 0.005082\n", + "\n", + " z = 0.005082 E-3 \n", + "\n", + "\n", + " z = 0.005082 E-3 (normalised) \n", + "\n" + ] + } + ], + "source": [ + "#Floating Point Arithmetic\n", + "\n", + "fx = 0.999658 #\n", + "Ex = -3 #\n", + "fy = 0.994576 #\n", + "Ey = -3 #\n", + "Ez = max(Ex,Ey)\n", + "fy = fy*10**(Ey-Ex)\n", + "fz = fx - fy\n", + "print 'Ez =',Ez,'fz =',fz\n", + "print '\\n z = %f E%d \\n'%(fz,Ez)\n", + "if fz < 0.1 :\n", + " fz = fz*10**6 #Since we are using 6 significant digits\n", + " n = len(str(fz))\n", + " fz = fz/10**n\n", + " Ez = Ez + n - 6\n", + " print '\\n z = %f E%d (normalised) \\n'%(fz,Ez)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 3_16 Pg No. 55" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + " fz = 0.080000 \n", + " Ez = 2 \n", + " z = 0.080000 E2 \n", + "\n", + "\n", + " z = 0.800000 E1 (normalised) \n", + "\n" + ] + } + ], + "source": [ + "#Floating Point Arithmetic\n", + "\n", + "fx = 0.200000 #\n", + "Ex = 4 #\n", + "fy = 0.400000 #\n", + "Ey = -2 #\n", + "fz = fx*fy\n", + "Ez = Ex + Ey \n", + "print '\\n fz = %f \\n Ez = %d \\n z = %f E%d \\n'%(fz,Ez,fz,Ez)\n", + "if fz < 0.1:\n", + " fz = fz*10\n", + " Ez = Ez - 1\n", + " print '\\n z = %f E%d (normalised) \\n'%(fz,Ez)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 3_17 Pg No. 55" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + " fz = 4.382715 \n", + " Ez = -2 \n", + " z = 4.382715 E-2 \n", + "\n", + "\n", + " z = 0.438271 E-1 (normalised) \n", + "\n" + ] + } + ], + "source": [ + "#Floating Point Arithmetic\n", + "\n", + "fx = 0.876543 #\n", + "Ex = -5 #\n", + "fy = 0.200000 #\n", + "Ey = -3 #\n", + "fz = fx/fy\n", + "Ez = Ex - Ey \n", + "print '\\n fz = %f \\n Ez = %d \\n z = %f E%d \\n'%(fz,Ez,fz,Ez)\n", + "\n", + "if fz > 1:\n", + " fz = fz/10\n", + " Ez = Ez + 1\n", + " print '\\n z = %f E%d (normalised) \\n'%(fz,Ez)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 3_18 Pg No. 56" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Ez = 2 \n", + " fx = 50000000.0\n", + "\n", + " fz = 5000000.010000 \n", + " z = 5000000.010000 E2 \n", + "\n" + ] + } + ], + "source": [ + "#Floating Point Arithmetic\n", + "\n", + "fx = 0.500000 #\n", + "Ex = 1 #\n", + "fy = 0.100000 #\n", + "Ey = -7 #\n", + "Ez= max([Ex,Ey])\n", + "n=[Ex,Ey].index(Ez)\n", + "if n == 1:\n", + " fy = fy*10**(Ey-Ex)\n", + " fz = fx + fy\n", + " if fz > 1:\n", + " fz = fz*10**(-1) \n", + " Ez = Ez + 1\n", + " \n", + " print 'Ez =',Ez,'\\n fy =',fy\n", + "else:\n", + " fx = fx*10**(Ex - Ey)\n", + " fz = fx + fy\n", + " if fz > 1:\n", + " fz = fz*10**(-1)\n", + " Ez = Ez + 1\n", + " \n", + " print 'Ez =',Ez,'\\n fx =',fx\n", + "\n", + "print '\\n fz = %f \\n z = %f E%d \\n'%(fz,fz,Ez)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 3_19 Pg No. 56" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + " fz = 0.175000 \n", + " Ez = 110 \n", + " z = 0.175000 E110 \n", + "\n" + ] + } + ], + "source": [ + "#Floating Point Arithmetic\n", + "\n", + "fx = 0.350000 #\n", + "Ex = 40 #\n", + "fy = 0.500000 #\n", + "Ey = 70 #\n", + "fz = fx*fy\n", + "Ez = Ex + Ey \n", + "print '\\n fz = %f \\n Ez = %d \\n z = %f E%d \\n'%(fz,Ez,fz,Ez)\n", + "if fz < 0.1:\n", + " fz = fz*10\n", + " Ez = Ez - 1\n", + " print '\\n z = %f E%d (normalised) \\n'%(fz,Ez)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 3_20 Pg No. 56" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + " fz = 4.375000 \n", + " Ez = -113 \n", + " z = 4.375000 E-113 \n", + "\n", + "\n", + " z = 0.437500 E-112 (normalised) \n", + "\n" + ] + } + ], + "source": [ + "#Floating Point Arithmetic\n", + "\n", + "fx = 0.875000 #\n", + "Ex = -18 #\n", + "fy = 0.200000 #\n", + "Ey = 95 #\n", + "fz = fx/fy\n", + "Ez = Ex - Ey \n", + "print '\\n fz = %f \\n Ez = %d \\n z = %f E%d \\n'%(fz,Ez,fz,Ez)\n", + "\n", + "if fz > 1:\n", + " fz = fz/10\n", + " Ez = Ez + 1\n", + " print '\\n z = %f E%d (normalised) \\n'%(fz,Ez)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 3_21 Pg No. 57" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Ez = 0 \n", + " fz = 2e-06\n", + "\n", + " z = 0.000002 E0 \n", + "\n", + "\n", + " z = 0.002000 E-3 (normalised) \n", + "\n" + ] + } + ], + "source": [ + "#Floating Point Arithmetic\n", + "\n", + "fx = 0.500000 #\n", + "Ex = 0 #\n", + "fy = 0.499998 #\n", + "Ey = 0 #\n", + "Ez = 0 #\n", + "fz = fx - fy\n", + "print 'Ez =',Ez,'\\n fz =',fz\n", + "print '\\n z = %f E%d \\n'%(fz,Ez)\n", + "if fz < 0.1 :\n", + " fz = fz*10**6\n", + " n = len(str(fz))\n", + " fz = fz/10**n\n", + " Ez = Ez + n - 6\n", + " print '\\n z = %f E%d (normalised) \\n'%(fz,Ez)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 3_22 Pg No. 57" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " fxy = 2.480183\n", + " Exy = 1 \n", + " fxy_z = 24.553832\n", + " Exy_z = 1 \n", + " fyz = -1.000000 \n", + " Eyz = -2 \n", + " fx_yz = -1.000000 \n", + " Ex_yz = 0 \n", + "\n", + " (x+y) + z != x + (y+z)\n" + ] + } + ], + "source": [ + "#Laws of Arithmetic\n", + "\n", + "def add_sub(fx,Ex,fy,Ey): #addition and subtraction fuction\n", + " if fx*fy >= 0:\n", + " #Addition\n", + " Ez = max([Ex,Ey])\n", + " n=[Ex,Ey].index(Ez)\n", + " if n == 1:\n", + " fy = fy*10**(Ey-Ex)\n", + " fz = fx + fy\n", + " if fz > 1:\n", + " fz = fz*10**(-1)\n", + " Ez = Ez + 1\n", + " \n", + " else:\n", + " fx = fx*10**(Ex - Ey)\n", + " fz = fx + fy\n", + " if fz > 1:\n", + " fz = fz*10**(-1) \n", + " Ez = Ez + 1\n", + " \n", + " \n", + " \n", + " else:\n", + " #Subtraction\n", + " Ez = max([Ex,Ey])\n", + " n=[Ex,Ey].index(Ez)\n", + " if n == 1:\n", + " fy = fy*10**(Ey-Ex)\n", + " fz = fx + fy\n", + " if abs(fz) < 0.1:\n", + " fz = fz*10**6\n", + " fz = floor(fz)\n", + " nfz = len(str(abs(fz)))\n", + " fz = fz/10**nfz\n", + " Ez = nfz - 6 \n", + " \n", + " else:\n", + " fx = fx*10**(Ex - Ey)\n", + " fz = fx + fy\n", + " if fz < 0.1:\n", + " fz = fz*10**6\n", + " fz = int(fz)\n", + " nfz = len(str(abs(fz)))\n", + " fz = fz/10**nfz\n", + " Ez = nfz - 6\n", + " \n", + " \n", + " \n", + " return [fz,Ez]\n", + "\n", + "fx = 0.456732\n", + "Ex = -2\n", + "fy = 0.243451\n", + "Ey = 0\n", + "fz = -0.24800\n", + "Ez = 0\n", + "\n", + "[fxy,Exy] = add_sub(fx,Ex,fy,Ey)\n", + "[fxy_z,Exy_z] = add_sub(fxy,Exy,fz,Ez)\n", + "[fyz,Eyz] = add_sub(fy,Ey,fz,Ez)\n", + "[fx_yz,Ex_yz] = add_sub(fx,Ex,fyz,Eyz)\n", + "print ' fxy = %f\\n Exy = %d \\n fxy_z = %f\\n Exy_z = %d \\n fyz = %f \\n Eyz = %d \\n fx_yz = %f \\n Ex_yz = %d \\n'%(fxy,Exy,fxy_z,Exy_z,fyz,Eyz,fx_yz,Ex_yz)\n", + "\n", + "if fxy_z != fx_yz | Exy_z != Ex_yz:\n", + " print ' (x+y) + z != x + (y+z)' " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 3_23 Pg No. 58" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "In book they have considered the maximum exponent can be only 99, since 110 is greater than 99 the result is erroneous\n", + "but in scilab the this value is much larger than 110 so we get a correct result \n", + "xy_z = 6e+78\n", + "x_yz = 6e+78\n" + ] + } + ], + "source": [ + "#Associative law\n", + "x = 0.400000*10**40\n", + "y = 0.500000*10**70\n", + "z = 0.300000*10**(-30)\n", + "print 'In book they have considered the maximum exponent can be only 99, since 110 is greater than 99 the result is erroneous'\n", + "print 'but in scilab the this value is much larger than 110 so we get a correct result '\n", + "print 'xy_z = ',(x*y)*z\n", + "print 'x_yz = ',x*(y*z)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 3_24 Pg No. 58" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "x_yz = 4e-06\n", + "xy_xz = 0.0\n" + ] + } + ], + "source": [ + "from math import floor\n", + "#Distributive law\n", + "x = 0.400000*10**1 #\n", + "fx = 0.400000\n", + "Ex = 1\n", + "y = 0.200001*10**0 #\n", + "z = 0.200000*10**0 #\n", + "x_yz = x*(y-z)\n", + "x_yz = x_yz*10**6\n", + "x_yz = floor(x_yz) #considering only six significant digits\n", + "n = len(str(x_yz))\n", + "fx_yz = x_yz/10**n\n", + "Ex_yz = n - 6\n", + "x_yz = fx_yz *10**Ex_yz\n", + "print 'x_yz = ',x_yz\n", + "\n", + "fxy = fx*y\n", + "fxy = fxy*10**6\n", + "fxy = floor(fxy) #considering only six significant digits\n", + "n = len(str(fxy))\n", + "fxy = fxy/10**n\n", + "Exy = n - 6\n", + "xy = fxy * 10**Exy\n", + "\n", + "fxz = fx*z\n", + "fxz = fxz*10**6\n", + "fxz = floor(fxz) #considering only six significant digits\n", + "n = len(str(fxz))\n", + "fxz = fxz/10**n\n", + "Exz = n - 6\n", + "xz = fxz * 10**Exz\n", + "\n", + "xy_xz = xy - xz\n", + "print 'xy_xz = ',xy_xz" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.9" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Numerical_Methods_by_E._Balaguruswamy/chapter4.ipynb b/Numerical_Methods_by_E._Balaguruswamy/chapter4.ipynb new file mode 100644 index 00000000..832b55d6 --- /dev/null +++ b/Numerical_Methods_by_E._Balaguruswamy/chapter4.ipynb @@ -0,0 +1,891 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Chapter 4 - Approximations and errors in computing" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 4_01 Pg No. 63" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + " 4.3201 has a precision of 10**-4\n", + "\n", + "\n", + " 4.32 has a precision of 10**-2\n", + "\n", + "\n", + " 4.320106 has a precision of 10**-6\n", + "\n", + "\n", + " The number with highest precision is 4.320106\n", + "\n" + ] + } + ], + "source": [ + "#Greatest precision\n", + "\n", + "a = '4.3201'\n", + "b = '4.32'\n", + "c = '4.320106'\n", + "na = len(a)-(a.index('.')+1)\n", + "print '\\n %s has a precision of 10**-%d\\n'%(a,na)\n", + "nb = len(b)-(b.index('.')+1)\n", + "print '\\n %s has a precision of 10**-%d\\n'%(b,nb)\n", + "nc = len(c)-c.index('.')-1\n", + "print '\\n %s has a precision of 10**-%d\\n'%(c,nc)\n", + "e = max(na,nb,nc)\n", + "if e ==na:\n", + " print '\\n The number with highest precision is %s\\n'%(a)\n", + "elif e == nb:\n", + " print '\\n The number with highest precision is %s\\n'%(b)\n", + "else:\n", + " print '\\n The number with highest precision is %s\\n'%(c)\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 4_02 Pg No. 63" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "95.763 has 5 significant digits\n", + "\n", + "0.008472 has 7 significant digits.The leading or higher order zeros are only place holders\n", + "\n", + "0.0456000 has 8 significant digits\n", + "\n", + "36.0 has 3 significant digits\n", + "\n", + "3600.00 has 6 significant digits\n", + "\n" + ] + } + ], + "source": [ + "#Accuracy of numbers\n", + "\n", + "def sd(x):\n", + " nd = x.index('.') #position of point\n", + " num = [ord(c) for c in x] #str2code(x)\n", + " if (nd)==None and num(length(x)) == 0:\n", + " print 'Accuracy is not specified\\n'\n", + " n = 0 #\n", + " else:\n", + " if num[0]>= 1 and (nd==None):\n", + " n = len(x)\n", + " elif num[1] >= 1 and not((nd==None)):\n", + " n = len(x) - 1\n", + " else:\n", + " for i in range(0,len(x)):\n", + " if num[i] >= 1 and num[i] <= 9:\n", + " break;\n", + " \n", + " \n", + " n = len(x)- i + 1\n", + " return n\n", + " \n", + " \n", + "\n", + "a = '95.763'\n", + "na = sd(a)\n", + "print '%s has %d significant digits\\n'%(a,na)\n", + "b = '0.008472'\n", + "nb = sd(b)\n", + "print '%s has %d significant digits.The leading or higher order zeros are only place holders\\n'%(b,nb)\n", + "c = '0.0456000'\n", + "nc = sd(c)\n", + "print '%s has %d significant digits\\n'%(c,nc)\n", + "d = '36.0'\n", + "nd = sd(d)\n", + "print '%s has %d significant digits\\n'%(d,nd)\n", + "e = '3600.0'\n", + "sd(e)\n", + "f = '3600.00'\n", + "nf = sd(f)\n", + "print '%s has %d significant digits\\n'%(f,nf)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 4_03 Pg No. 64" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + " 0.1_10 = 0.[0.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0] \n", + " 0.4_10 = 0.[0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0] \n", + " \n", + "sum = 0.9921875\n", + "Note : The answer should be 0.5, but it is not so.This is due to the error in conversion from decimal to binary form.\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from math import floor\n", + "from numpy import arange,zeros\n", + "a = 0.1\n", + "b = 0.4\n", + "afrac=[];bfrac=[];\n", + "for i in range(0,8):\n", + " afrac.append(floor(a*2))\n", + " a = a*2 - floor(a*2)\n", + " bfrac.append(floor(b*2))\n", + " b = b*2 - floor(b*2)\n", + "\n", + "afrac_s = '0' + '.' +(str(afrac)) #string form binary equivalent of a i.e 0.1\n", + "bfrac_s = '0' + '.' +(str(bfrac))\n", + "print '\\n 0.1_10 = %s \\n 0.4_10 = %s \\n '%( afrac_s , bfrac_s)\n", + " \n", + "summ=zeros(8)\n", + "for j in arange(7,0,-1):\n", + " summ[j] = afrac[j] + bfrac[j]\n", + " if summ[j] > 1:\n", + " summ[j] = summ[j]-2\n", + " afrac[(j-1)] = afrac[(j-1)] + 1\n", + "summ_dec = 0\n", + "for k in arange(7,0,-1):\n", + " summ_dec = summ_dec + summ[k]\n", + " summ_dec = summ_dec*1.0/2 \n", + "\n", + "print 'sum =',summ_dec\n", + "print 'Note : The answer should be 0.5, but it is not so.This is due to the error in conversion from decimal to binary form.' " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 4_04 Pg No. 66" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + " Chooping Method : \n", + " Approximate x = 0.7526*10**3 \n", + " Error = 0.0835 \n", + " \n", + "\n", + " Symmetric Rounding :\n", + " Approximate x = 0.7527*10**3 \n", + " Error = -0.0165 \n", + " \n" + ] + } + ], + "source": [ + "#Rounding-Off\n", + "\n", + "fx = 0.7526\n", + "E =3\n", + "gx = 0.835\n", + "d = E - (-1)\n", + "#Chopping Method\n", + "Approx_x = fx*10**E\n", + "Err = gx*10**(E-d)\n", + "print '\\n Chooping Method : \\n Approximate x = %.4f*10**%d \\n Error = %.4f \\n '%(fx,E,Err)\n", + "#Symmetric Method\n", + "if gx >= 0.5:\n", + " Err = (gx -1)*10**(-1)\n", + " Approx_x = (fx + 10**(-d))*10**E\n", + "else:\n", + " Approx_x = fx*10**E\n", + " Err = gx * 10**(E-d)\n", + "\n", + "print '\\n Symmetric Rounding :\\n Approximate x = %.4f*10**%d \\n Error = %.4f \\n '%(fx + 10**(-d),E,Err)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 4_05 Pg No. 68" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + " a) When first three terms are used \n", + " Truncation error = 1.402756E-03 \n", + " \n", + "\n", + " b) When first four terms are used \n", + " Truncation error = 6.942222E-05 \n", + " \n", + "\n", + " c) When first five terms are used \n", + " Truncation error = 2.755556E-06 \n", + " \n" + ] + } + ], + "source": [ + "from scipy.misc import factorial\n", + "#Truncation Error\n", + "\n", + "x = 1.0/5\n", + "#When first three terms are used\n", + "Trunc_err = x**3/factorial(3) + x**4/factorial(4) + x**5/factorial(5) + x**6/factorial(6)\n", + "print '\\n a) When first three terms are used \\n Truncation error = %.6E \\n '%(Trunc_err)\n", + "\n", + "#When four terms are used\n", + "Trunc_err = x**4/factorial(4) + x**5/factorial(5) + x**6/factorial(6)\n", + "print '\\n b) When first four terms are used \\n Truncation error = %.6E \\n '%(Trunc_err)\n", + "\n", + "#When Five terms are used\n", + "Trunc_err = x**5/factorial(5) + x**6/factorial(6)\n", + "print '\\n c) When first five terms are used \\n Truncation error = %.6E \\n '%(Trunc_err)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 4_06 Pg No. 68" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + " a) When first three terms are used \n", + " Truncation error = -1.269244E-03 \n", + " \n", + "\n", + " b) When first four terms are used \n", + " Truncation error = 6.408889E-05 \n", + " \n", + "\n", + " c) When first five terms are used \n", + " Truncation error = -2.577778E-06 \n", + " \n" + ] + } + ], + "source": [ + "from scipy.misc import factorial\n", + "\n", + "#Truncation Error\n", + "\n", + "x = -1.0/5\n", + "#When first three terms are used\n", + "Trunc_err = x**3/factorial(3) + x**4/factorial(4) + x**5/factorial(5) + x**6/factorial(6)\n", + "print '\\n a) When first three terms are used \\n Truncation error = %.6E \\n '%(Trunc_err)\n", + "\n", + "#When four terms are used\n", + "Trunc_err = x**4/factorial(4) + x**5/factorial(5) + x**6/factorial(6)\n", + "print '\\n b) When first four terms are used \\n Truncation error = %.6E \\n '%(Trunc_err)\n", + "\n", + "#When Five terms are used\n", + "Trunc_err = x**5/factorial(5) + x**6/factorial(6)\n", + "print '\\n c) When first five terms are used \\n Truncation error = %.6E \\n '%(Trunc_err)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 4_07 Pg No. 71" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + " For Building : \n", + " Absolute error, e1 = 5 \n", + " Relative error , e1_r = 0.17 percent \n", + " \n", + "\n", + " For Beam : \n", + " Absolute error, e2 = 5 \n", + " Relative error , e2_r = 17 percent \n", + " \n" + ] + } + ], + "source": [ + "#Absolute and Relative Errors\n", + "\n", + "h_bu_t = 2945 #\n", + "h_bu_a = 2950 #\n", + "h_be_t = 30 #\n", + "h_be_a = 35 #\n", + "e1 = abs(h_bu_t - h_bu_a)\n", + "e1_r = e1/h_bu_t\n", + "e2 = abs(h_be_t - h_be_a)\n", + "e2_r = e2/h_be_t\n", + "print '\\n For Building : \\n Absolute error, e1 = %d \\n Relative error , e1_r = %.2f percent \\n '%(e1,e1_r*100) \n", + "print '\\n For Beam : \\n Absolute error, e2 = %d \\n Relative error , e2_r = %.2G percent \\n '%(e2,e2_r*100)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 4_08 Pg No. 72" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "q = 7.9 \n", + " We can say that the computer can store numbers with 7 significant decimal digits \n", + " \n" + ] + } + ], + "source": [ + "from math import log10\n", + "#Machine Epsilon\n", + "\n", + "def Q(p):\n", + " q = 1 + (p-1)*log10(2)\n", + " return q\n", + "p = 24\n", + "q = Q(p)\n", + "print 'q = %.1f \\n We can say that the computer can store numbers with %d significant decimal digits \\n '%(q,q)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 4_09 Pg No. 75" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + " |er_x| <= 0.05 o/o\n", + " |er_y| <= 0.05o/o \n", + " ex = 0.617 \n", + " ey = 0.616 \n", + " |ez| = 1.233 \n", + " |er_z| = 61.65o/o \n", + "\n" + ] + } + ], + "source": [ + "#Propagation of Error\n", + "\n", + "x = 0.1234*10**4\n", + "y = 0.1232*10**4\n", + "d = 4\n", + "er_x = 10**(-d + 1)/2\n", + "er_y = 10**(-d + 1)/2\n", + "ex = x*er_x\n", + "ey = y*er_y\n", + "ez = abs(ex) + abs(ey)\n", + "er_z = abs(ez)/abs(x-y)\n", + "\n", + "print '\\n |er_x| <= %.2f o/o\\n |er_y| <= %.2fo/o \\n ex = %.3f \\n ey = %.3f \\n |ez| = %.3f \\n |er_z| = %.2fo/o \\n'%(er_x *100,er_y*100,ex,ey,ez,er_z*100)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 4_10 Pg No. 77" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + " ex = 0.01175 \n", + " ey = 0.03370 \n", + " ez = 0.01725 \n", + " exy = 0.15839 \n", + " ew = 0.17564 \n", + "\n" + ] + } + ], + "source": [ + "#Errors in Sequence of Computations\n", + "\n", + "x_a = 2.35 #\n", + "y_a = 6.74 #\n", + "z_a = 3.45 #\n", + "ex = abs(x_a)*10**(-3+1)/2\n", + "ey = abs(y_a)*10**(-3+1)/2\n", + "ez = abs(z_a)*10**(-3+1)/2\n", + "exy = abs(x_a)*ey + abs(y_a)*ex\n", + "ew = abs(exy) + abs(ez)\n", + "print '\\n ex = %.5f \\n ey = %.5f \\n ez = %.5f \\n exy = %.5f \\n ew = %.5f \\n'%(ex,ey,ez,exy,ew)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 4_11 Pg No. 77" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "w = 10000.0\n", + "True w = 10444\n", + "ew = 444.0\n", + "er,w = 0.0425124473382\n" + ] + } + ], + "source": [ + "from math import floor\n", + "#Addition of Chain of Numbers\n", + "\n", + "x = 9678 #\n", + "y = 678 #\n", + "z = 78 #\n", + "d = 4 # #length of mantissa\n", + "fx = x/10**4\n", + "fy = y/10**4\n", + "fu = fx + fy\n", + "Eu = 4\n", + "if fu >= 1:\n", + " fu = fu/10\n", + " Eu = Eu + 1\n", + "\n", + "#since length of mantissa is only four we need to maintain only four places in decimal, so\n", + "fu = floor(fu*10**4)/10**4\n", + "u = fu * 10**Eu\n", + "w = u + z\n", + "n = len(str(w))\n", + "w = floor(w/10**(n-4))*10**(n-4) #To maintain length of mantissa = 4\n", + "print 'w =',w\n", + "True_w = 10444\n", + "ew = True_w - w\n", + "er_w = (True_w - w)/True_w\n", + "print 'True w =',True_w\n", + "print 'ew =',ew\n", + "print 'er,w =',er_w " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 4_12 Pg No. 77" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "w = 10430.0\n", + "True w = 10444\n", + "ew = 14.0\n", + "er,w = 0.00134048257373\n" + ] + } + ], + "source": [ + "#Addition of chain Numbers\n", + "\n", + "x = 9678 #\n", + "y = 678 #\n", + "z = 78 #\n", + "d = 4 # #length of mantissa\n", + "n = max(len( str(y) ) , len(str(z)))\n", + "fy = y/10**n\n", + "fz = z/10**n\n", + "fu = fy + fz\n", + "Eu = n\n", + "if fu >= 1:\n", + " fu = fu/10\n", + " Eu = Eu + 1\n", + "\n", + "u = fu * 10**Eu\n", + "n = max(len( str(x) ) , len(str(u)))\n", + "fu = u/10**4\n", + "fx = x/10**4\n", + "fw = fu + fx\n", + "Ew = 4\n", + "if fw >= 1:\n", + " fw = fw/10\n", + " Ew = Ew + 1\n", + "\n", + "#since length of mantissa is only four we need to maintain only four places in decimal, so\n", + "fw = floor(fw*10**4)/10**4\n", + "w = fw*10**Ew\n", + "print 'w =',w\n", + "True_w = 10444\n", + "ew = True_w - w\n", + "er_w = (True_w - w)/True_w\n", + "print 'True w =',True_w\n", + "print 'ew =',ew \n", + "print 'er,w =',er_w" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 4_14 Pg No. 79" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + " ex = 5E-04 \n", + " df(xa) = 1.25 \n", + " ef = 6.26E-04 \n", + " er,f = 1.04E-04 \n", + "\n" + ] + } + ], + "source": [ + "from math import sqrt\n", + "from scipy.misc import derivative\n", + "#Absolute & Relative Errors\n", + "\n", + "xa = 4.000\n", + "def f(x):\n", + " f = sqrt(x) + x\n", + " return f\n", + "#Assuming x is correct to 4 significant digits\n", + "ex = 0.5 * 10**(-4 + 1)\n", + "df_xa = derivative(f,4)\n", + "ef = ex * df_xa\n", + "er_f = ef/f(xa)\n", + "print '\\n ex = %.0E \\n df(xa) = %.2f \\n ef = %.2E \\n er,f = %.2E \\n'%( ex,df_xa,ef,er_f)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 4_15 Pg No. 80" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ef = 0.07\n" + ] + } + ], + "source": [ + "#Error Evaluation\n", + "\n", + "x = 3.00 #\n", + "y = 4.00 #\n", + "def f(x,y):\n", + " f = x**2 + y**2\n", + " return f\n", + "def df_x(x):\n", + " df_x = 2*x\n", + " return df_x\n", + "def df_y(y):\n", + " df_y = 2*y\n", + " return df_y\n", + "ex = 0.005\n", + "ey = 0.005\n", + "ef = df_x(x)*ex + df_y(y)*ey\n", + "print 'ef =',ef" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 4_16 Pg No. 82" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "x = 400.0\n", + "y = 807.0\n", + "Changing m2 from 2.01 to 2.005\n", + "\n", + " x = 800 \n", + " y = 1607 \n", + " From the above results we can see that for small change in m2 results in almost 100 percent change in the values of x and y.Therefore, the problem is absolutely ill-conditioned \n", + "\n" + ] + } + ], + "source": [ + "#Condition and Stability\n", + "\n", + "C1 = 7.00 #\n", + "C2 = 3.00 #\n", + "m1 = 2.00 #\n", + "m2 = 2.01 #\n", + "x = (C1 - C2)/(m2 - m1)\n", + "y = m1*((C1 - C2)/(m2 - m1)) + C1\n", + "print 'x =',x\n", + "print 'y =',y\n", + "print 'Changing m2 from 2.01 to 2.005'\n", + "m2 = 2.005\n", + "x = (C1 - C2)/(m2 - m1)\n", + "y = m1*((C1 - C2)/(m2 - m1)) + C1\n", + "print '\\n x = %d \\n y = %d \\n From the above results we can see that for small change in m2 results in almost 100 percent change in the values of x and y.Therefore, the problem is absolutely ill-conditioned \\n'%(x,y)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 4_18 Pg No. 84" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "z = sqrt(x) - sqrt(y) = 0.0\n", + "z = ( x-y )/( sqrt(x) + sqrt(y) ) = 0.022\n" + ] + } + ], + "source": [ + "from math import sqrt, floor\n", + "#Difference of Square roots\n", + "\n", + "x = 497.0 #\n", + "y = 496.0 #\n", + "sqrt_x = sqrt(497)\n", + "sqrt_y = sqrt(496)\n", + "nx = len( str( floor( sqrt_x ) ) )\n", + "ny = len( str( floor( sqrt_y ) ) )\n", + "sqrt_x = floor(sqrt_x*10**(4-nx))/10**(4-nx)\n", + "sqrt_y = floor(sqrt_y*10**(4-ny))/10**(4-ny)\n", + "z1 = sqrt_x - sqrt_y\n", + "print 'z = sqrt(x) - sqrt(y) =',z1\n", + "z2 = ( x -y)/(sqrt_x + sqrt_y)\n", + "if z2 < 0.1:\n", + " z2 = z2*10**4\n", + " nz = len(str(floor(z2)))\n", + " z2 = floor(z2*10**(4-nz))/10**(8-nz)\n", + "\n", + "print 'z = ( x-y )/( sqrt(x) + sqrt(y) ) =',z2" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 4_21 Pg No. 85" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Truncation Error = 0.000505399929331\n", + "calculated e**x using roundoff = -0.000459999999793\n", + "actual e**x = 4.53999297625e-05\n", + "Here we can see the difference between calculated e**x and actual e**x this is due to trucation error (which is greater than final value of e**x ), so the roundoff error totally dominates the solution\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from math import exp,floor\n", + "x = -10\n", + "T_act=[1]\n", + "T_trc=[1]\n", + "e_x_cal = 1\n", + "TE=[]\n", + "for i in range(0,100):\n", + " T_act.append(T_act[i]*x/(i+1))\n", + " T_trc.append(floor(T_act[i+1]*10**5)/10**5)\n", + " TE.append(abs(T_act[i+1]-T_trc[i+1]))\n", + " e_x_cal = e_x_cal + T_trc[i+1]\n", + "e_x_act = exp(-10)\n", + "Sum=0\n", + "for s in TE:\n", + " Sum+=s\n", + "print 'Truncation Error =',Sum\n", + "print 'calculated e**x using roundoff =',e_x_cal\n", + "print 'actual e**x = ',e_x_act\n", + "print 'Here we can see the difference between calculated e**x and actual e**x this is due to trucation error (which is greater than final value of e**x ), so the roundoff error totally dominates the solution'" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.9" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Numerical_Methods_by_E._Balaguruswamy/chapter6.ipynb b/Numerical_Methods_by_E._Balaguruswamy/chapter6.ipynb new file mode 100644 index 00000000..76664ab7 --- /dev/null +++ b/Numerical_Methods_by_E._Balaguruswamy/chapter6.ipynb @@ -0,0 +1,1039 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Chapter 6 - Roots of non linear equations" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 6_01 Pg No. 126" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The largest possible root is x1 = [[4]]\n", + "No root can be larger than the value = [[4]]\n", + "\n", + "All real roots lie in the interval (-3.741657,3.741657)\n", + "\n", + "We can use these two points as initial guesses for the bracketing methods and one of them for open end methods\n" + ] + } + ], + "source": [ + "from numpy import mat,shape\n", + "from math import sqrt\n", + "\n", + "#Possible Initial guess values for roots\n", + "\n", + "A = mat([[ 2],[-8] ,[2],[12]]) # Coefficients of x terms in the decreasing order of power\n", + "n = shape(A)#\n", + "x1 = -A[1]/A[0]#\n", + "print 'The largest possible root is x1 =',x1\n", + "print 'No root can be larger than the value =',x1\n", + "\n", + "x = sqrt((A[1]/A[0])**2 - 2*(A[2]/A[0])**2)\n", + "\n", + "print '\\nAll real roots lie in the interval (-%f,%f)\\n'%(x,x)\n", + "print 'We can use these two points as initial guesses for the bracketing methods and one of them for open end methods'" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 6_03 Pg No. " + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "p(4) = 1\n", + "\n", + " p(3)= -2\n", + "\n", + "\n", + " p(2)= 1\n", + "\n", + "\n", + " f(2) = p(1) = 0\n" + ] + } + ], + "source": [ + "from numpy import mat,shape\n", + "from math import sqrt\n", + "#Evaluating Polynomial using Horner's rule\n", + "\n", + "#Coefficients of x terms in the increasing order of power\n", + "A = mat([[6],[1],[-4],[1]])\n", + "x = 2\n", + "N=shape(A)\n", + "n,c = N[0],N[1]\n", + "p=[0,0,0]\n", + "p.append(A[n-1])\n", + "print 'p(4) =',p[n-1][0,0]\n", + "for i in range(1,n-1):\n", + " p[n-i]= p[n-i+1-1]*x + A[n-i-1]\n", + " print '\\n p(%d)= %d\\n'%(n-i,p[n-i])\n", + "\n", + "print '\\n f(%d) = p(1) = %d'%(x,p[0])\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 6_04 Pg No. 132" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "First finding the interval that contains a root,this can be done by using Eq 6.10\n", + "\n", + " Both the roots lie in the interval (-6,6) \n", + "\n", + "\n", + " The root lies in the interval (5,5)\n", + "\n" + ] + } + ], + "source": [ + "from numpy import poly1d,polyval, sqrt\n", + "\n", + "#Root of a Equation Using Bisection Method\n", + "\n", + "#Coefficients in increasing order of power of x starting from 0\n", + "A = [-10 ,-4, 1]#\n", + "print 'First finding the interval that contains a root,this can be done by using Eq 6.10'\n", + "xmax = sqrt((A[1]/A[2])**2 - 2*(A[0]/A[2]))\n", + "print '\\n Both the roots lie in the interval (-%d,%d) \\n'%(xmax,xmax)\n", + "x = range(-6,7)\n", + "p= poly1d(A)# p = poly(A,'x'%('c'\n", + "\n", + "fx = [p(xx) for xx in x]#\n", + "for i in range(0,12):\n", + " if fx[i]*fx[i] < 0:\n", + " break \n", + " \n", + "\n", + "print '\\n The root lies in the interval (%d,%d)\\n'%(x[i],x[i])\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 6_05 Pg No. 139" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Iteration No. 1 \n", + "\n", + "x0 = 1.000000 \n", + "\n", + "Iteration No. 2 \n", + "\n", + "x0 = 1.000000 \n", + "\n", + "Iteration No. 3 \n", + "\n", + "x0 = 1.000000 \n", + "\n", + "Iteration No. 4 \n", + "\n", + "x0 = 1.000000 \n", + "\n", + "Iteration No. 5 \n", + "\n", + "x0 = 1.000000 \n", + "\n", + "Iteration No. 6 \n", + "\n", + "x0 = 1.000000 \n", + "\n", + "Iteration No. 7 \n", + "\n", + "x0 = 1.000000 \n", + "\n", + "Iteration No. 8 \n", + "\n", + "x0 = 1.000000 \n", + "\n", + "Iteration No. 9 \n", + "\n", + "x0 = 1.000000 \n", + "\n", + "Iteration No. 10 \n", + "\n", + "x0 = 1.000000 \n", + "\n", + "Iteration No. 11 \n", + "\n", + "x0 = 1.000000 \n", + "\n", + "Iteration No. 12 \n", + "\n", + "x0 = 1.000000 \n", + "\n", + "Iteration No. 13 \n", + "\n", + "x0 = 1.000000 \n", + "\n", + "Iteration No. 14 \n", + "\n", + "x0 = 1.000000 \n", + "\n", + "Iteration No. 15 \n", + "\n", + "x0 = 1.000000 \n", + "\n" + ] + } + ], + "source": [ + "from numpy import poly1d,polyval\n", + "\n", + "#False Position Method\n", + "\n", + "#Coefficients of polynomial in increasing order of power of x\n", + "A = [-2 , -1, 1]\n", + "x1 = 1 #\n", + "x2 = 3 #\n", + "fx = poly1d(A)\n", + "for i in range(1,16):\n", + " print 'Iteration No. %d \\n'%(i)\n", + " fx1 = fx(x1)\n", + " fx2 = fx(x2)\n", + " x0 = x1 - fx1*(x2-x1)/(fx2-fx1) \n", + " print 'x0 = %f \\n'%(x0)#\n", + " fx0 = fx(x0)#\n", + " if fx1*fx0 < 0:\n", + " x2 = x0 \n", + " else:\n", + " x1 = x0 #\n", + " " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 6_07 Pg No. 147" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "x2 = 1.000000\n", + "\n", + "Since f(1.000000) = 0, the root closer to the point x = 0 is 1.000000 \n", + "\n" + ] + } + ], + "source": [ + "from numpy import poly1d,polyval,polyder\n", + "#Root of the Equation using Newton Raphson Method\n", + "\n", + "#Coefficients of polynomial in increasing order of power of x\n", + "A = [ 2, -3, 1]#\n", + "fx = poly1d(A)\n", + "dfx = polyder(fx)\n", + "\n", + "x=[0]\n", + "f=[]\n", + "df=[]\n", + "for i in range(1,11):\n", + " f.append(fx(x[i-1]))\n", + " if f[i-1] != 0:\n", + " df.append(dfx(x[i-1]))\n", + " x.append(x[i-1] - f[i-1]/df[i-1])\n", + " print 'x%d = %f\\n'%(i+1,x[i])# \n", + " else:\n", + " print 'Since f(%f) = 0, the root closer to the point x = 0 is %f \\n'%(x[i-1],x[i-1] )\n", + " break\n", + " " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 6_08 Pg No. 151" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "x2 = 3.342105\n", + "\n", + "x3 = 2.248631\n", + "\n", + "x4 = 1.535268\n", + "\n", + "x5 = 1.079139\n", + "\n", + "x6 = 0.797330\n", + "\n", + "x7 = 0.632716\n", + "\n", + "From the results we can see that number of correct digits approximately doubles with each iteration\n" + ] + } + ], + "source": [ + "from numpy import poly1d,polyval,polyder\n", + "\n", + "#Root of the Equation using Newton Raphson Method\n", + "\n", + "#Coefficients of polynomial in increasing order of power of x\n", + "A = [ 6, 1 , -4 , 1 ]\n", + "fx = poly1d(A)\n", + "dfx = polyder(fx)\n", + "f=[];df=[]\n", + "x = [5.0] #\n", + "for i in range(1,7):\n", + " f.append(fx(x[i-1]))\n", + " if f[i-1] != 0:\n", + " df.append(dfx(x[i-1]))\n", + " x.append(x[i-1] - f[i-1]/df[i-1])\n", + " print 'x%d = %f\\n'%(i+1,x[i])\n", + " \n", + "\n", + "print 'From the results we can see that number of correct digits approximately doubles with each iteration'" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 6_09 Pg No. 153" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + " For Iteration No. 1\n", + "\n", + "\n", + " x1 = 4.000000\n", + " x2 = 2.000000 \n", + " fx1 = -175.000000 \n", + " fx2 = -47.000000 \n", + " x3 = 1.265625 \n", + "\n", + "\n", + " For Iteration No. 2\n", + "\n", + "\n", + " x1 = 2.000000\n", + " x2 = 1.265625 \n", + " fx1 = -47.000000 \n", + " fx2 = -20.080566 \n", + " x3 = 0.717818 \n", + "\n", + "\n", + " For Iteration No. 3\n", + "\n", + "\n", + " x1 = 1.265625\n", + " x2 = 0.717818 \n", + " fx1 = -20.080566 \n", + " fx2 = -7.023891 \n", + " x3 = 0.423122 \n", + "\n", + "\n", + " For Iteration No. 4\n", + "\n", + "\n", + " x1 = 0.717818\n", + " x2 = 0.423122 \n", + " fx1 = -7.023891 \n", + " fx2 = -2.482815 \n", + " x3 = 0.261999 \n", + "\n", + "\n", + " For Iteration No. 5\n", + "\n", + "\n", + " x1 = 0.423122\n", + " x2 = 0.261999 \n", + " fx1 = -2.482815 \n", + " fx2 = -0.734430 \n", + " x3 = 0.194317 \n", + "\n", + "\n", + " For Iteration No. 6\n", + "\n", + "\n", + " x1 = 0.261999\n", + " x2 = 0.194317 \n", + " fx1 = -0.734430 \n", + " fx2 = -0.154860 \n", + " x3 = 0.176233 \n", + "\n", + "This can be still continued further for accuracy\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from numpy import poly1d\n", + "#Root of the equation using SECANT Method\n", + "\n", + "#Coefficients of polynomial in increasing order of power of x\n", + "A = [ -10, -4, 1]\n", + "x1 = 4 #\n", + "x2 = 2 #\n", + "fx = poly1d(A)\n", + "for i in range(1,7):\n", + " print '\\n For Iteration No. %d\\n'%(i)\n", + " fx1 = fx(x1)\n", + " fx2 = fx(x2)\n", + " x3 = x2 - fx2*(x2-x1)/(fx2-fx1) #\n", + " print '\\n x1 = %f\\n x2 = %f \\n fx1 = %f \\n fx2 = %f \\n x3 = %f \\n'%(x1,x2,fx1,fx2,x3) #\n", + " x1 = x2#\n", + " x2 = x3#\n", + "\n", + "print 'This can be still continued further for accuracy'" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 6_11 Pg No. 161" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + " x1 = -1.000000\n", + "\n", + "\n", + " x2 = 1.000000\n", + "\n", + "\n", + " x3 = 1.000000\n", + "\n", + "\n", + "1.000000 is root of the equation,since x3 - x2 = 0 \n", + "\n", + "\n", + "x1 = 1.000000\n", + "\n", + "\n", + "x2 = 1.000000\n", + "\n", + "\n", + " 1.000000 is root of the equation,since x2 - x1 = 0\n" + ] + } + ], + "source": [ + "from numpy import poly1d\n", + "from __future__ import division\n", + "#Fixed point method\n", + "\n", + "#Coefficients of polynomial in increasing order of power of x\n", + "A = [ -2, 1, 1 ]#\n", + "B = [ 2, 0, -1 ]#\n", + "gx = poly1d(B)\n", + "x = [0] ##initial guess x0 = 0\n", + "for i in range(2,11):\n", + " x.append (gx(x[i-2]))\n", + " print '\\n x%d = %f\\n'%(i-1,x[i-1])\n", + " if (x[i-1]-x[(i-2)]) == 0:\n", + " print '\\n%f is root of the equation,since x%d - x%d = 0 \\n'%(x[i-1],i-1,i-2)\n", + " break\n", + " \n", + "\n", + "#Changing initial guess x0 = -1\n", + "x[0] = -1 #\n", + "for i in range(2,11):\n", + " x[i-1]= gx(x[i-2])\n", + " print '\\nx%d = %f\\n'%(i-1,x[i-1])\n", + " if (x[i-1]-x[i-2]) == 0:\n", + " print '\\n %f is root of the equation,since x%d - x%d = 0'%(x[i-1],i-1,i-2)\n", + " break" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 6_12 Pg No. 162" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + " x0 = 1.000000 \n", + "\n", + " x1 = 2.500000 \n", + "\n", + " x2 = 1.666667 \n", + "\n", + " x3 = 1.250000 \n", + "\n", + " x4 = 1.000000 \n", + "\n", + "\n", + " x0 = 0.000000 \n", + "\n", + " x1 = 1.000000 \n", + "\n", + " x2 = 7.000000 \n", + "\n", + " x3 = 15.000000 \n", + "\n", + " x4 = 25.000000 \n", + "\n", + "\n", + " x0 = 1.000000 \n", + "\n", + " x1 = 2.250000 \n", + "\n", + " x2 = 2.333333 \n", + "\n", + " x3 = 2.625000 \n", + "\n", + " x4 = 3.000000 \n", + "\n", + " x5 = 3.416667 \n", + "\n", + " x6 = 3.857143 \n", + "\n" + ] + } + ], + "source": [ + "#Fixed point method\n", + "\n", + "A = [ -5, 0, 1 ]#\n", + "def g(x):\n", + " x = 5.0/x\n", + " return x\n", + "x = [1] #\n", + "print '\\n x0 = %f \\n'%(x[0])\n", + "for i in range(2,6):\n", + " x.append(g(i))\n", + " print ' x%d = %f \\n'%(i-1,x[i-1])\n", + " \n", + "\n", + "#Defining g(x) in different way\n", + "def g(x):\n", + " x = x**2 + x - 5\n", + " return x\n", + "x=[0]\n", + "print '\\n x0 = %f \\n'%(x[0])\n", + "for i in range(2,6):\n", + " x.append(g(i))\n", + " print ' x%d = %f \\n'%(i-1,x[i-1])\n", + "\n", + "#Third form of g(x)\n", + "def g(x):\n", + " x = (x + 5/x)/2\n", + " return x\n", + "x=[1]\n", + "print '\\n x0 = %f \\n'%(x[0])\n", + "for i in range(2,8):\n", + " x.append(g(i))\n", + " print ' x%d = %f \\n'%(i-1,x[i-1])" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 6_13 Pg No. 169" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " x**2 - y**2 = 3 \n", + " x**2 + x*y \n", + "\n", + "\n", + " x0 = 1.000000 \n", + " y0 = 1.000000 \n", + "\n", + "\n", + " x1 = 2.500000 \n", + " y1 = 5.000000 \n", + "\n", + "\n", + " x2 = 2.750000 \n", + " y2 = 1.000000 \n", + "\n", + "\n", + " x3 = 3.500000 \n", + " y3 = -1.000000 \n", + "\n" + ] + } + ], + "source": [ + "#Solving System of non-linear equations using FIXED POINT METHOD\n", + "\n", + "print ' x**2 - y**2 = 3 \\n x**2 + x*y \\n'\n", + "def f(x,y):\n", + " x = y + 3/(x+y)\n", + " return x\n", + "def g(x):\n", + " y = (6-x**2)/x\n", + " return y\n", + "x=[1]\n", + "y=[1]\n", + "print '\\n x0 = %f \\n y0 = %f \\n'%(x[0],y[0])\n", + "for i in range(2,5):\n", + " x.append(f((i-1),(i-1)))\n", + " y.append(g((i-1)))\n", + " print '\\n x%d = %f \\n y%d = %f \\n'%(i-1,x[i-1],i-1,y[i-1])" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 6_14 Pg No. 172" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "x**2 + x*y = 6 \n", + " x**2 - y**2 = 3 \n", + "\n", + "\n", + " x1 = 0.875000 \n", + " y1 = -0.625000 \n", + "\n", + "\n", + " x2 = -0.437500 \n", + " y2 = -2.687500 \n", + "\n" + ] + } + ], + "source": [ + "#Solving System of Non-linear equations using Newton Raphson Method\n", + "\n", + "\n", + "print 'x**2 + x*y = 6 \\n x**2 - y**2 = 3 \\n'#\n", + "def F(x,y):\n", + " f = x**2 + x*y - 6\n", + " return f\n", + "def G(x,y):\n", + " g = x**2 - y**2 -3\n", + " return g\n", + "def dFx(x,y):\n", + " f1 = 2*x + y\n", + " return f1\n", + "def dFy(x,y):\n", + " f2 = y\n", + " return f2\n", + "def dGx(x,y):\n", + " g1 = 2*x\n", + " return g1\n", + "def dGy(x,y):\n", + " g2 = -2*y\n", + " return g2\n", + "x=[1]\n", + "y=[1]\n", + "\n", + "for i in range(2,4):\n", + " Fval = F(i,i)\n", + " Gval = G(i,i)\n", + " f1 = dFx(i-1,i-1)\n", + " f2 = dFy(i-1,i-1)\n", + " g1 = dGx(i-1,i-1)\n", + " g2 = dGy(i-1,i-1)\n", + " D = f1*g2 - f2*g1 \n", + " \n", + " x.append(x[i-2] - (Fval*g2 - Gval*f2)/D )\n", + " y.append(y[i-2] - (Gval*f1 - Fval*g1)/D )\n", + " print '\\n x%d = %f \\n y%d = %f \\n'%(i-1,x[i-1],i-1,y[i-1]) " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 6_15 Pg No. 176" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "b3 = 0.000000\n", + "\n", + "b2 = 0.000000\n", + "\n", + "b1 = 0.000000\n", + "\n", + "Thus the polynomial is\n", + " 2\n", + "15 x - 7 x + 1\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from numpy import poly1d, arange\n", + "#Synthetic Division\n", + "\n", + "a = [-9 ,15 ,-7, 1]\n", + "b=[0,0,0,0]\n", + "for i in arange(3,0,-1):\n", + " b[i]= a[i] + b[i]*3\n", + " print 'b%d = %f\\n'%(i,b[i-1])\n", + "print 'Thus the polynomial is' \n", + "print poly1d(b)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 6_16 Pg No. 187" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "b3 = 1.000000 \n", + "\n", + "b2 = 1.800000 \n", + "\n", + "b1 = 3.240000 \n", + "\n", + "b0 = 14.032000 \n", + "\n", + "c3 = 1.000000 \n", + "\n", + "c2 = 1.800000 \n", + "\n", + "c1 = 3.240000 \n", + "\n", + "c0 = 14.032000 \n", + "\n", + "\n", + " D = 4.240000 \n", + " du = -0.694340 \n", + " dv = -5.250566 \n", + " u = 1.105660\n", + " v = -1.694340 \n", + "\n" + ] + } + ], + "source": [ + "#Quadratic factor of a polynomial using Bairstow's Method\n", + "\n", + "a = [ 10, 1 ,0 ,1]#\n", + "n = len(a)#\n", + "u = 1.8 #\n", + "v = -1 #\n", + "b=[];c=[]\n", + "for nn in range(n):\n", + " b.append(0)\n", + " c.append(0)\n", + "b[n-1] = a[n-1]\n", + "b[n-2] = a[n-2] + u*b[n-1]\n", + "c[n-1] = 0 \n", + "c[n-2] = b[n-1]\n", + "\n", + "\n", + "for i in range(n-2,0,-1):\n", + " b[i-1]= a[i-1]+ u*b[i] + v*b[i+1]\n", + " c[i-1]= b[i] + u*c[i] + v*c[i+1] \n", + "\n", + "\n", + "for i in range(n,0,-1):\n", + " print 'b%d = %f \\n'%(i-1,b[i-1])\n", + "\n", + "for i in range(n,0,-1):\n", + " print 'c%d = %f \\n'%(i-1,b[i-1])\n", + "\n", + "\n", + "D = c[1]*c[1] - c[0]*c[2]\n", + "du = -1*(b[1]*c[1] - c[0]*c[2])/D \n", + "dv = -1*(b[0]*c[1] - b[1]*c[0])/D \n", + "u = u + du #\n", + "v = v + du #\n", + "print '\\n D = %f \\n du = %f \\n dv = %f \\n u = %f\\n v = %f \\n'%(D,du,dv,u,v)\n", + " " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 6_17 Pg No. 197" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + " x1 = 0.000000\n", + " x2 = 1.000000\n", + " x3 = 2.000000\n", + " f1 = -20.000000\n", + " f2 = -7.000000\n", + " f3 = 16.000000\n", + " h1 = -2.000000\n", + " h2 = -1.000000\n", + " d1 = -36.000000\n", + " d2 = -23.000000\n", + " a0 = 16.000000\n", + " a1 = 28.000000\n", + " a2 = 5.000000\n", + " h4 = -0.645934\n", + " x4 = 1.354066\n", + " \n", + "\n", + " x1 = 1.000000\n", + " x2 = 2.000000\n", + " x3 = 1.354066\n", + " f1 = -7.000000\n", + " f2 = 16.000000\n", + " f3 = -0.309679\n", + " h1 = -0.354066\n", + " h2 = 0.645934\n", + " d1 = -6.690321\n", + " d2 = 16.309679\n", + " a0 = -0.309679\n", + " a1 = 21.145451\n", + " a2 = 6.354066\n", + " h4 = 0.014581\n", + " x4 = 1.368647\n", + " \n", + "\n", + " x1 = 2.000000\n", + " x2 = 1.354066\n", + " x3 = 1.368647\n", + " f1 = 16.000000\n", + " f2 = -0.309679\n", + " f3 = -0.003394\n", + " h1 = 0.631353\n", + " h2 = -0.014581\n", + " d1 = 16.003394\n", + " d2 = -0.306286\n", + " a0 = -0.003394\n", + " a1 = 21.103381\n", + " a2 = 6.722713\n", + " h4 = 0.000161\n", + " x4 = 1.368808\n", + " \n", + "\n", + " x1 = 1.354066\n", + " x2 = 1.368647\n", + " x3 = 1.368808\n", + " f1 = -0.309679\n", + " f2 = -0.003394\n", + " f3 = -0.000001\n", + " h1 = -0.014742\n", + " h2 = -0.000161\n", + " d1 = -0.309678\n", + " d2 = -0.003392\n", + " a0 = -0.000001\n", + " a1 = 21.096136\n", + " a2 = 6.091521\n", + " h4 = 0.000000\n", + " x4 = 1.368808\n", + " \n", + "root of the polynomial is x4 = 1.368808\n" + ] + } + ], + "source": [ + "from math import sqrt\n", + "#Solving Leonard's equation using MULLER'S Method\n", + "\n", + "def f(x):\n", + " y = x**3 + 2*x**2 + 10*x - 20\n", + " return y\n", + "x1 = 0 #\n", + "x2 = 1 #\n", + "x3 = 2 #\n", + "for i in range(1,11):\n", + " f1 = f(x1)\n", + " f2 = f(x2)\n", + " f3 = f(x3)\n", + " h1 = x1-x3 #\n", + " h2 = x2-x3 #\n", + " d1 = f1 - f3 #\n", + " d2 = f2 - f3 #\n", + " D = h1*h2*(h1-h2)#\n", + " a0 = f3 #\n", + " a1 = (d2*h1**2 - d1*h2**2)/D #\n", + " a2 = (d1*h2 - d2*h1)/D #\n", + " if abs(-2*a0/( a1 + sqrt( a1**2 - 4*a0*a2 ) )) < abs( -2*a0/( a1 - sqrt( a1**2 - 4*a0*a2 ) )):\n", + " h4 = -2*a0/(a1 + sqrt(a1**2 - 4*a0*a2))#\n", + " else:\n", + " h4 = -2*a0/(a1 - sqrt(a1**2 - 4*a0*a2))\n", + " \n", + " x4 = x3 + h4 #\n", + " print '\\n x1 = %f\\n x2 = %f\\n x3 = %f\\n f1 = %f\\n f2 = %f\\n f3 = %f\\n h1 = %f\\n h2 = %f\\n d1 = %f\\n d2 = %f\\n a0 = %f\\n a1 = %f\\n a2 = %f\\n h4 = %f\\n x4 = %f\\n '%(x1,x2,x3,f1,f2,f3,h1,h2,d1,d2,a0,a1,a2,h4,x4) #\n", + " relerr = abs((x4-x3)/x4)#\n", + " if relerr <= 0.00001:\n", + " print 'root of the polynomial is x4 = %f'%(x4)\n", + " break\n", + " \n", + " x1 = x2 #\n", + " x2 = x3 #\n", + " x3 = x4 #" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.9" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Numerical_Methods_by_E._Balaguruswamy/chapter7.ipynb b/Numerical_Methods_by_E._Balaguruswamy/chapter7.ipynb new file mode 100644 index 00000000..3dff4606 --- /dev/null +++ b/Numerical_Methods_by_E._Balaguruswamy/chapter7.ipynb @@ -0,0 +1,524 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Chapter 7 - Direct solutions of linear equations" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 7_01 Pg No. 211" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "A =\n", + "[[ 3 2 1 10]\n", + " [ 0 2 2 8]\n", + " [ 0 2 3 11]]\n", + "After transformation\n", + "A=\n", + "[[ 3 2 1 10]\n", + " [ 0 2 2 8]\n", + " [ 0 0 1 3]]\n", + "x = 1\n", + "y = 1\n", + "z = 3\n" + ] + } + ], + "source": [ + "from numpy import mat\n", + "#Elimination Process\n", + "\n", + "A = mat([[3, 2, 1, 10],[2, 3, 2, 14],[1, 2, 3, 14]])\n", + "A[1,:] = A[1,:] - A[0,:]*A[1,0]/A[0,0]\n", + "A[2,:] = A[2,:] - A[0,:]*A[2,0]/A[0,0]\n", + "print 'A =\\n',A\n", + "\n", + "print 'After transformation'\n", + "A[2,:] = A[2,:] - A[1,:]*A[2,1]/A[1,1]\n", + "print 'A=\\n',A\n", + "\n", + "z = A[2,3]/A[2,2]\n", + "y = (A[1,3] - A[1,2]*z)/A[1,1]\n", + "x = (A[0,3] - A[0,1]*y - A[0,2]*z)/A[0,0]\n", + "print 'x =',x \n", + "print 'y =',y \n", + "print 'z =',z " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 7_02 Pg No. 214" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[ 3 6 1 16]\n", + " [ 2 4 3 13]\n", + " [ 1 3 2 9]]\n", + "since Aug(2,2) = 0 elimination is not possible,so reordering the matrix\n", + "[[ 3 6 1 16]\n", + " [ 2 4 3 13]\n", + " [ 1 3 2 9]]\n", + "Elimination is complete and by back substitution the solution is\n", + "\n", + "x3 = 1, x2 = 2 , x1 = 1 \n" + ] + } + ], + "source": [ + "from numpy import mat,shape\n", + "#Basic Gauss Elimination\n", + "\n", + "\n", + "A = mat([[ 3, 6, 1],[ 2, 4 , 3],[ 1, 3, 2 ]])\n", + "B = [16, 13, 9]\n", + "S=shape(A)\n", + "ar1,ac1 = S[0],S[1]\n", + "Aug = mat([[3, 6 ,1 ,16],[2, 4, 3, 13],[1, 3, 2, 9]])\n", + "for i in range(1,ar1):\n", + " Aug[i,:] = Aug[i,:] - (Aug[i,0]/Aug[0,0])*Aug[0,:] \n", + "\n", + "print Aug\n", + "print 'since Aug(2,2) = 0 elimination is not possible,so reordering the matrix'\n", + "temp=A[2,:]\n", + "A[2,:]=A[1,:]\n", + "A[1,:]=temp\n", + "print Aug\n", + "print 'Elimination is complete and by back substitution the solution is\\n'\n", + "print 'x3 = 1, x2 = 2 , x1 = 1 '" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 7_03 Pg No. 220" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Gauss Elimination using partial pivoting : ans is\n", + "[ 9. -1. -10.]\n", + "\n", + " The solution can be obtained by back substitution \n", + " x1 = 4 \n", + " x2 = 0 \n", + " x3 = -4 \n", + "\n" + ] + } + ], + "source": [ + "from numpy import array , zeros, dot, diag\n", + "\n", + "A = array([[ 2., 2., 1.],[4., 2., 3.],[ 1., -1., 1.]])\n", + "B = array([[6.],[4.],[0.]])\n", + "\n", + "## Gauss Elimination using partial pivoting\n", + "\n", + "def GEPP(A, b):\n", + " '''\n", + " Gaussian elimination with partial pivoting.\n", + " % input: A is an n x n nonsingular matrix\n", + " % b is an n x 1 vector\n", + " % output: x is the solution of Ax=b.\n", + " % post-condition: A and b have been modified. \n", + " '''\n", + " n = len(A)\n", + " if b.size != n:\n", + " raise ValueError(\"Invalid argument: incompatible sizes between A & b.\", b.size, n)\n", + " # k represents the current pivot row. Since GE traverses the matrix in the upper \n", + " # right triangle, we also use k for indicating the k-th diagonal column index.\n", + " for k in xrange(n-1):\n", + " #Choose largest pivot element below (and including) k\n", + " maxindex = abs(A[k:,k]).argmax() + k\n", + " if A[maxindex, k] == 0:\n", + " raise ValueError(\"Matrix is singular.\")\n", + " #Swap rows\n", + " if maxindex != k:\n", + " A[[k,maxindex]] = A[[maxindex, k]]\n", + " b[[k,maxindex]] = b[[maxindex, k]]\n", + " for row in xrange(k+1, n):\n", + " multiplier = A[row][k]/A[k][k]\n", + " #the only one in this column since the rest are zero\n", + " A[row][k] = multiplier\n", + " for col in xrange(k + 1, n):\n", + " A[row][col] = A[row][col] - multiplier*A[k][col]\n", + " #Equation solution column\n", + " b[row] = b[row] - multiplier*b[k]\n", + " #print A ;print b\n", + " x = zeros(n)\n", + " k = n-1\n", + " x[k] = b[k]/A[k,k]\n", + " while k >= 0:\n", + " x[k] = (b[k] - dot(A[k,k+1:],x[k+1:]))/A[k,k]\n", + " k = k-1\n", + " return x\n", + "Aug=GEPP(A,B)\n", + "print 'Gauss Elimination using partial pivoting : ans is\\n',Aug\n", + "\n", + "#Back Substitution\n", + "def forward_elimination(A, b, n):\n", + " \"\"\"\n", + " Calculates the forward part of Gaussian elimination.\n", + " \"\"\"\n", + " for row in range(0, n-1):\n", + " for i in range(row+1, n):\n", + " factor = A[i,row] / A[row,row]\n", + " for j in range(row, n):\n", + " A[i,j] = A[i,j] - factor * A[row,j]\n", + "\n", + " b[i] = b[i] - factor * b[row]\n", + "\n", + " \n", + " return A, b\n", + "\n", + "def back_substitution(a, b, n):\n", + " \"\"\"\"\n", + " Does back substitution, returns the Gauss result.\n", + " \"\"\"\n", + " x = zeros((n,1))\n", + " x[n-1] = b[n-1] / a[n-1, n-1]\n", + " for row in range(n-2, -1, -1):\n", + " sums = b[row]\n", + " for j in range(row+1, n):\n", + " sums = sums - a[row,j] * x[j]\n", + " x[row] = sums / a[row,row]\n", + " return x\n", + "\n", + "def gauss(A, b):\n", + " \"\"\"\n", + " This function performs Gauss elimination without pivoting.\n", + " \"\"\"\n", + " n = A.shape[0]\n", + "\n", + " # Check for zero diagonal elements\n", + " if any(diag(A)==0):\n", + " raise ZeroDivisionError(('Division by zero will occur; '\n", + " 'pivoting currently not supported'))\n", + "\n", + " A, b = forward_elimination(A, b, n)\n", + " return back_substitution(A, b, n)\n", + "\n", + "x = gauss(A, B)\n", + "print ('\\n The solution can be obtained by back substitution \\n x1 = %i \\n x2 = %i \\n x3 = %i \\n'%(x[0], x[1], x[2]))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 7_04 Pg No. 228" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Aug = \n", + "[[ 2 4 -6 -8]\n", + " [ 1 3 1 10]\n", + " [ 2 -4 -2 -12]]\n", + "Aug = \n", + "[[ 1 2 -3 -4]\n", + " [ 1 3 1 10]\n", + " [ 2 -4 -2 -12]]\n", + "Aug = \n", + "[[ 1 2 -3 -4]\n", + " [ 0 1 4 10]\n", + " [ 0 -8 4 -12]]\n", + "Aug = \n", + "[[ 1 2 -3 -4]\n", + " [ 0 1 4 10]\n", + " [ 0 -8 4 -12]]\n", + "Aug = \n", + "[[ 1 0 -11 -4]\n", + " [ 0 1 4 10]\n", + " [ 0 0 36 -12]]\n", + "Aug = \n", + "[[ 1 0 -11 -4]\n", + " [ 0 1 4 10]\n", + " [ 0 0 1 -1]]\n", + "Aug = \n", + "[[ 1 0 0 -4]\n", + " [ 0 1 0 10]\n", + " [ 0 0 1 -1]]\n" + ] + } + ], + "source": [ + "from numpy import mat, shape\n", + "#Gauss Jordan Elimination\n", + "\n", + "A = mat([[ 2, 4, -6],[1, 3, 1],[2, -4, -2 ]])\n", + "B = mat([[ -8],[ 10],[ -12 ]])\n", + "S=shape(A)\n", + "ar, ac =S[0],S[1]\n", + "Aug = mat([[ 2, 4, -6, -8],[ 1, 3, 1, 10],[ 2, -4, -2, -12 ]])\n", + "print 'Aug = \\n',Aug\n", + "\n", + "\n", + "for i in range(0,ar):\n", + " Aug[i,i:ar+1] = Aug[i,i:ar+1]/Aug[i,i]\n", + " print 'Aug = \\n',Aug\n", + " for k in range(0,ar):\n", + " if k != i:\n", + " Aug[k,i:ar] = Aug[k,i:ar] - Aug[k,i]*Aug[i,i:ar]\n", + " \n", + "\n", + " print 'Aug = \\n',Aug" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 7_05 Pg No. 234" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "U = \n", + "[[ 3. 2. 1. ]\n", + " [ 0. 1.66666667 1.33333333]\n", + " [ 0. 0. 1.6 ]]\n", + "L = \n", + "[[ 1. 0. 0. ]\n", + " [ 0.66666667 1. 0. ]\n", + " [ 0.33333333 0.8 1. ]]\n", + "\n", + " z(1) = 10.000000 \n", + "\n", + "\n", + " z(2) = 14.000000 \n", + "\n", + "\n", + " z(3) = 10.666667 \n", + "\n", + "\n", + " x(3) = 6.666667 \n", + "\n", + "\n", + " x(2) = 8.400000 \n", + "\n", + "\n", + " x(1) = 1.111111 \n", + "\n" + ] + } + ], + "source": [ + "from numpy import array, arange, zeros\n", + "from scipy.linalg import lu\n", + "from __future__ import division\n", + "\n", + "#DoLittle LU Decomposition\n", + "\n", + "A = array([[ 3, 2, 1],[2 , 3 , 2],[1, 2, 3 ]])\n", + "B = array([[ 10],[14],[14 ]])\n", + "n,n = A.shape\n", + "L=lu(A)[1]\n", + "U=lu(A)[2]\n", + "print 'U = \\n',U\n", + "print 'L = \\n',L\n", + "\n", + "z=zeros([3,1])\n", + "#Forward Substitution\n", + "for i in range(0,n):\n", + " z[i,0] = B[i,0]\n", + " for j in range(0,i-1):\n", + " z[i,0] = z[i,0] - L[i,0]*z[j,0]; \n", + " \n", + " print '\\n z(%i) = %f \\n'%(i+1,z[i,0])\n", + "\n", + "x=zeros([3,1]) \n", + "#Back Substitution\n", + "for i in arange(n-1,-1,-1):\n", + " x[i,0] = z[i,0]\n", + " for j in arange(n-1,i+1,-1):\n", + " x[i,0] = x[i,0] - U[i,j]*x[j,0]\n", + " \n", + " x[i,0] = x[i,0]/U[i,i]\n", + " print '\\n x(%i) = %f \\n'%(i+1,x[i,0])" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 7_06 Pg No. 242" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "U =\n", + "[[ 1. 2. 3. ]\n", + " [ 0. 2.82842712 7.77817459]\n", + " [ 0. 0. 8.54400375]]\n" + ] + } + ], + "source": [ + "from numpy import sqrt, mat,shape, zeros\n", + "#Cholesky's Factorisation\n", + "\n", + "A = mat([[ 1, 2, 3],[2, 8 ,22],[3, 22, 82 ]])\n", + "n= shape(A)[0]\n", + "U=zeros([n,n])\n", + "\n", + "for i in range(0,n):\n", + " for j in range(0,n):\n", + " if i == j:\n", + " U[i,i] = A[i,i]\n", + " for k in range(0,i-1):\n", + " U[i,i] = U[i,i]-U[k,i]**2 \n", + " \n", + " U[i,i] = sqrt(U[i,i])\n", + " elif i < j:\n", + " U[i,j] = A[i,j]\n", + " for k in range(0,i-1):\n", + " U[i,j] = U[i,j] - U[k,i]*U[k,j]\n", + " \n", + " U[i,j] = U[i,j]/U[i,i]\n", + " \n", + "print 'U =\\n',U" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 7_07 Pg No. 245" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + " x(1) = 5.000000 \n", + " x(2) = 5.000000 \n", + "\n", + "\n", + " x(1) = -15.000000 \n", + " x(2) = -15.000000 \n", + "\n", + "x=\n", + "[[ 20.]\n", + " [-15.]]\n", + "r=\n", + "[[ -2.66453526e-12]\n", + " [ 1.00000000e-02]]\n" + ] + } + ], + "source": [ + "from numpy import mat\n", + "#Ill-Conditioned Systems\n", + "\n", + "A = mat([[ 2, 1],[2.001, 1]])\n", + "B = mat([[ 25],[25.01 ]])\n", + "x=[0,0]\n", + "x[0] = (25 - 25.01)/(2 - 2.001)\n", + "x[1] = (25.01*2 - 25*2.001)/(2*1 - 2.001*1)\n", + "print '\\n x(1) = %f \\n x(2) = %f \\n'%(x[1],x[1])\n", + "x[0] = (25 - 25.01)/(2 - 2.0005)#\n", + "x[1] = (25.01*2 - 25*2.0005)/(2*1 - 2.0005*1)#\n", + "print '\\n x(1) = %f \\n x(2) = %f \\n'%(x[1],x[1])\n", + "x=mat([[x[0]],[x[1]]])\n", + "r = A*(x)-B\n", + "print 'x=\\n',x\n", + "print 'r=\\n',r" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.9" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Numerical_Methods_by_E._Balaguruswamy/chapter8.ipynb b/Numerical_Methods_by_E._Balaguruswamy/chapter8.ipynb new file mode 100644 index 00000000..12e74ff2 --- /dev/null +++ b/Numerical_Methods_by_E._Balaguruswamy/chapter8.ipynb @@ -0,0 +1,317 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Chapter 8 - Iterative solutions of linear equations" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 8_01 Page No. 254" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "x1 = (5 - x2 - x3)/2 \n", + "x2 = (15 - 3x1 - 2x3)/5 \n", + "x3 = (8 - 2x1 - x2)/4\n", + "\n", + " Iteration Number : 1\n", + "\n", + " \n", + " x1 = 2.500000\n", + " x2 = 3.000000\n", + " x3 = 2.000000\n", + "\n", + "\n", + " Iteration Number : 2\n", + "\n", + " \n", + " x1 = 0.000000\n", + " x2 = 0.700000\n", + " x3 = 0.000000\n", + "\n", + "\n", + " Iteration Number : 3\n", + "\n", + " \n", + " x1 = 2.150000\n", + " x2 = 3.000000\n", + " x3 = 1.825000\n", + "\n", + "\n", + " Iteration Number : 4\n", + "\n", + " \n", + " x1 = 0.087500\n", + " x2 = 0.980000\n", + " x3 = 0.175000\n", + "\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from numpy import mat\n", + "#Gauss Jacobi\n", + "\n", + "A = mat([[ 2, 1 , 1] ,[3, 5, 2],[2, 1, 4]])\n", + "B = mat([[ 5],[ 15],[ 8]])\n", + "x1old = 0 ;x2old = 0 ; x3old = 0 #intial assumption of x1,x2 & x3\n", + "\n", + "print 'x1 = (5 - x2 - x3)/2 '\n", + "print 'x2 = (15 - 3x1 - 2x3)/5 '\n", + "print 'x3 = (8 - 2x1 - x2)/4'\n", + "\n", + "for i in range(1,5):\n", + " print '\\n Iteration Number : %d\\n'%(i)\n", + " \n", + " x1 = (5 - x2old - x3old)/2 #\n", + " x2 = (15 - 3*x1old - 2*x3old)/5 # \n", + " x3 = (8 - 2*x1old - x2old)/4 #\n", + " \n", + " print ' \\n x1 = %f\\n x2 = %f\\n x3 = %f\\n'%(x1,x2,x3)\n", + " \n", + " x1old = x1#\n", + " x2old = x2#\n", + " x3old = x3#\n", + " \n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 8_02 Page No.261" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "(x1 = 5 - x2 - x3)/2 \n", + "(x2 = 15 - 3x1 - 2x3)/5 \n", + "(x3 = 8 - 2x1 - x2)/4\n", + "\n", + " Iteration Number : 1\n", + " \n", + " x1 = 2.500000\n", + " x2 = 1.500000\n", + " x3 = 0.375000\n", + "\n", + "\n", + " Iteration Number : 2\n", + " \n", + " x1 = 1.562500\n", + " x2 = 1.912500\n", + " x3 = 0.740625\n", + "\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from numpy import mat\n", + "#Gauss Seidel\n", + "\n", + "A = mat([[ 2, 1 , 1] ,[3, 5, 2],[2, 1, 4]])\n", + "B = mat([[ 5],[ 15],[ 8]])\n", + "\n", + "x1old = 0 ;x2old = 0 ; x3old = 0 #intial assumption\n", + "\n", + "print '(x1 = 5 - x2 - x3)/2 '\n", + "print '(x2 = 15 - 3x1 - 2x3)/5 '\n", + "print '(x3 = 8 - 2x1 - x2)/4'\n", + " \n", + "for i in range(1,3):\n", + " \n", + " print '\\n Iteration Number : %d'%(i)\n", + " \n", + " x1 = (5 - x2old - x3old)/2 #\n", + " x1old = x1# \n", + " x2 = (15 - 3*x1old - 2*x3old)/5 #\n", + " x2old = x2# \n", + " x3 = (8 - 2*x1old - x2old)/4 #\n", + " x3old = x3#\n", + " \n", + " print ' \\n x1 = %f\\n x2 = %f\\n x3 = %f\\n'%(x1,x2,x3)\n", + " \n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 8_03 page no. 269" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Using a matrix to display the results after each iteration, first row represents initial assumption\n", + "x1 = (5-x2)/3\n", + "x2 = (x1 - 5)/3\n", + "The system converges to the solution ( 1.999949 , -1.000017 ) in 4 iterations\n", + "\n", + "Final Result is as : \n", + "0.0000000000 \t0.0000000000 \t1.9999491947 \t1.00001693509\n", + "-1.1111111111 \t1.6666666667 \t0.3332825281 \t0.111094176023\n", + "-0.9876543210 \t2.0370370370 \t0.0370878423 \t0.0123626141002\n", + "-1.0013717421 \t1.9958847737 \t0.0040644211 \t0.00135480702467\n", + "-0.9998475842 \t2.0004572474 \t0.0005080526 \t0.000169350878084\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from numpy import array,zeros,ones,nditer,vstack,hstack\n", + "\n", + "#Gauss Seidel\n", + "\n", + "\n", + "A = array([[ 3, 1],[ 1 ,-3]])\n", + "B = array([[ 5],[5 ]])\n", + "\n", + "X=zeros([6,2])\n", + "print ('Using a matrix to display the results after each iteration, first row represents initial assumption')\n", + "X[0,0] = 0; X[0,1] = 0 ;#initial assumption\n", + "\n", + "maxit = 1000;#Maximum number of iterations\n", + "err = 0.0003 ;\n", + "\n", + "print('x1 = (5-x2)/3');\n", + "print('x2 = (x1 - 5)/3');\n", + "\n", + "for i in range(1,maxit):\n", + " \n", + " X[i,0] = (5 - X[i-1,1])/3 ;\n", + " X[i,1] = (X[i,0] - 5)/3 ;\n", + " \n", + " #Error Calculations\n", + " err1 =abs((X[i,0] - X[i-1,0])/X[i,0]) \n", + " err2 =abs((X[i,1]- X[i-1,1])/X[i,1])\n", + " \n", + " #Terminating Condition \n", + " if err >= err1 and err >= err2:\n", + " print 'The system converges to the solution ( %f , %f ) in %d iterations\\n'%(X[i,0],X[i,1],i-1) \n", + " break\n", + " \n", + " \n", + "\n", + "#calcution of true error i.e. difference between final result and results from each iteration\n", + "trueerr1 = abs(X[:,0] - X[i,0]*ones([i+1,1])) ;\n", + "trueerr2 = abs(X[:,1] - X[i,1]*ones([i+1,1])) ;\n", + "\n", + "#displaying final results\n", + "print 'Final Result is as : '\n", + "for i in range(0,5):\n", + " print '%.10f'%X[i,:][1],'\\t%.10f'%X[i,:][0],'\\t%.10f'%trueerr1[0,i],'\\t',trueerr2[0,i]" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 8_04 Page No.261" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "x1 = 5 + 3*x2 \n", + "x2 = 5 - 3*x1 \n", + "\n", + " Iteration : 1 x1 = 5 and x2 = -10\n", + "\n", + "\n", + " Iteration : 2 x1 = -25 and x2 = 80\n", + "\n", + "\n", + " Iteration : 3 x1 = 245 and x2 = -730\n", + "\n", + "It is clear that the process do not converge towards the solution, rather it diverges.\n" + ] + } + ], + "source": [ + "from numpy import mat\n", + "#Gauss Seidel\n", + "\n", + "A = mat([[ 1, -3],[3, 1 ]])\n", + "B = mat([[ 5],[5] ])\n", + "x1old = 0 #intial assumption\n", + "x2old = 0 #intial assumption\n", + "\n", + "print 'x1 = 5 + 3*x2 '\n", + "print 'x2 = 5 - 3*x1 '\n", + " \n", + "for i in range(1,4):\n", + " x1 = 5 + 3*x2old \n", + " x1old = x1\n", + " x2 = 5 - 3*x1old \n", + " x2old = x2\n", + " \n", + " print '\\n Iteration : %d x1 = %d and x2 = %d\\n'%(i,x1,x2)\n", + " \n", + "print 'It is clear that the process do not converge towards the solution, rather it diverges.'" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.9" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Numerical_Methods_by_E._Balaguruswamy/chapter9.ipynb b/Numerical_Methods_by_E._Balaguruswamy/chapter9.ipynb new file mode 100644 index 00000000..539b10b0 --- /dev/null +++ b/Numerical_Methods_by_E._Balaguruswamy/chapter9.ipynb @@ -0,0 +1,798 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Chapter 9 - Curve fitting interpolation" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 9_01 Pg No.277" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "solving linear equations \n", + " a0 + 100a1 = 3/7 \n", + " a0 + 101a1 = -4/7 \n", + " we get\n", + " a0 = 100 \n", + " a1 = -1\n", + "\n", + " p(100) = 0 \n", + " p(101) = -1\n", + "\n" + ] + } + ], + "source": [ + "from numpy.linalg import solve\n", + "from numpy import mat\n", + "from sympy import Symbol\n", + "print 'solving linear equations \\n a0 + 100a1 = 3/7 \\n a0 + 101a1 = -4/7 \\n we get'#\n", + "C = mat([[ 1, 100],[1 ,101] ])\n", + "p = mat([[ 3/7],[-4/7] ])\n", + "a = solve(C,p )\n", + "print ' a0 = %.f \\n a1 = %.f'%(a[0],a[1])\n", + "\n", + "x = Symbol('x')\n", + "def horner(a,x):\n", + " px = a[0] + a[1]*x\n", + " return px\n", + "p100 = horner(a,100.0)\n", + "p101 = horner(a,101.0)\n", + "print '\\n p(100) = %.f \\n p(101) = %.f\\n'%(p100,p101)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 9_02 Page No. 278" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + " a0 = 0.428571 \n", + " a1 = -1.428571 \n", + "\n", + "\n", + " p(100) = 0.428571 \n", + " p(101) = -1.000000\n", + "\n" + ] + } + ], + "source": [ + "from numpy.linalg import solve\n", + "from numpy import mat\n", + "from sympy import Symbol\n", + "\n", + "C = mat([[1, 100-100],[1, 101-100]])\n", + "p = mat([[ 3.0/7],[-4/7] ])\n", + "a = solve(C,p)\n", + "print '\\n a0 = %f \\n a1 = %f \\n'%(a[0],a[1])\n", + "\n", + "x = Symbol('x')\n", + "def horner(a,x):\n", + " px = a[0]+ a[1]*(x - 100) \n", + " return px\n", + "p100 = horner(a,100)\n", + "p101 = horner(a,101)\n", + "print '\\n p(100) = %f \\n p(101) = %f\\n'%(p100,p101)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 9_03 Page No. 280" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2.5 lies between points 2 and 3\n", + "f(2.5) = 1.57315\n", + "error1 = 0.00795\n", + "The correct answer is 1.5811.The difference between results is due to use of a linear model to a nonlinear use\n", + "repeating the procedure using x1 = 2 and x2 = 4\n", + "error2 = 0.02045\n", + "f(2.5) = 1.56065\n", + "NOTE- The increase in error due to the increase in the interval between the interpolating data\n" + ] + } + ], + "source": [ + "x = range(0,6)\n", + "f = [0,1, 1.4142, 1.7321, 2, 2.2361]\n", + "n = 2.5\n", + "for i in range(1,6):\n", + " if n <= x[(i)]:\n", + " break;\n", + " \n", + "\n", + "print '%.1f lies between points %d and %d'%(n,x[(i-1)],x[(i)])\n", + "f2_5 = f[(i-1)] + ( n - x[(i-1)] )*( f[(i)] - f[(i-1)] )/( x[(i)] - x[(i-1)] )\n", + "err1 = 1.5811 - f2_5\n", + "print 'f(2.5) = ',f2_5\n", + "print 'error1 = ',err1\n", + "print 'The correct answer is 1.5811.The difference between results is due to use of a linear model to a nonlinear use'\n", + "print 'repeating the procedure using x1 = 2 and x2 = 4'\n", + "x1 = 2\n", + "x2 = 4\n", + "f2_5 = f[(x1)] + ( 2.5 - x1 )*( f[(x2)] - f[(x1)] )/( x2 - x1 )\n", + "err2 = 1.5811 - f2_5\n", + "print 'error2 = ',err2\n", + "print 'f(2.5) = ',f2_5\n", + "print 'NOTE- The increase in error due to the increase in the interval between the interpolating data'" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 9_04 Pg No. 282" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "For x = 2.5 we have,\n", + " L0(2.5) = 1.500000 \n", + " L1(2.5) = 0.250000 \n", + " L2(2.5) = 1.000000 \n", + " p(2.5) = 8.893756 \n", + "\n", + "The error is -7.312617\n" + ] + } + ], + "source": [ + "from sympy import Symbol\n", + "from math import sqrt\n", + "#Lagrange Interpolation- Second order\n", + "\n", + "X = [0, 1, 2 ,3 ,4 ,5]\n", + "Fx = [0, 1, 1.4142 ,1.7321 ,2, 2.2361]\n", + "X = X[2:5]\n", + "Fx = Fx[2:5]\n", + "x0 = 2.5 \n", + "x = Symbol('x')\n", + "p = 0\n", + "L=[0]\n", + "def horner(X,p,Fx,x,m):\n", + " for i in range(1,3):\n", + " L.append(1)\n", + " for j in range(1,3):\n", + " if j == i:\n", + " continue #\n", + " else:\n", + " L[(i)] = L[(i)]*( x - X[(j)] )/( X[(i)] - X[(j)] ) \n", + " \n", + " p = p + Fx[(i)]*L[(i)] \n", + " return [L[m],p]\n", + "\n", + "x=2.5\n", + "L0 = horner(X,p,Fx,x,1)[0]\n", + "L1 = horner(X,p,Fx,x,2)[0]\n", + "L2 = horner(X,p,Fx,x,3)[0]\n", + "p2_5 = horner(X,p,Fx,x,3)[1]\n", + "print 'For x = 2.5 we have,\\n L0(2.5) = %f \\n L1(2.5) = %f \\n L2(2.5) = %f \\n p(2.5) = %f \\n'%(L0,L1,L2,p2_5)\n", + "\n", + "err = sqrt(2.5) - p2_5 #\n", + "print 'The error is %f'%(err)# " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 9_05 Pg No. 283" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The Lagrange basis polynomials are:\n", + "(-x + 1)*(x - 3)*(x - 2)/6\n", + "x*(x - 3)*(x - 2)/2\n", + "-x*(x - 3)*(x - 1)/2\n", + "x*(x - 2)*(x - 1)/6\n", + "The interpolation polynomial is \n", + "0.85915*x*(x - 3)*(x - 2) - 3.19455*x*(x - 3)*(x - 1) + 3.18091666666667*x*(x - 2)*(x - 1)\n", + "The interpolation value at x = 1.5 is : 4.36756875000000 \n", + "e**1.5 = 3.367569\n" + ] + } + ], + "source": [ + "from sympy import Symbol\n", + "#Lagrange Interpolation\n", + "\n", + "i = [ 0, 1, 2, 3 ]\n", + "X = [ 0 ,1 ,2 ,3 ]\n", + "Fx = [ 0 ,1.7183 ,6.3891, 19.0855 ]\n", + "x = Symbol('x')\n", + "n = 3 #order of lagrange polynomial \n", + "p = 0\n", + "L=[]\n", + "for i in range(0,n+1):\n", + " L.append(1)\n", + " for j in range(0,n+1):\n", + " if j == i:\n", + " continue \n", + " else:\n", + " L[i] = L[i]*( x - X[j] )/( X[i] - X[j] ) \n", + " \n", + " \n", + " p = p + Fx[i]*L[i]\n", + "\n", + "print \"The Lagrange basis polynomials are:\"\n", + "for i in range(0,4):\n", + " print str(L[i])\n", + "\n", + "\n", + "print \"The interpolation polynomial is \"\n", + "print str(p)\n", + "\n", + "print 'The interpolation value at x = 1.5 is :', \n", + "\n", + "p1_5 = p.subs(x,1.5)\n", + "e1_5 = p1_5 + 1 #\n", + "print e1_5,'\\ne**1.5 = %f'%(p1_5)# \n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 9_06 Pg No. 288" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The coefficients of the polynomial are,\n", + " a0 = 0 \n", + " a1 = 0.301 \n", + " a2 = -0.06245 \n", + "\n", + "Polynomial is : 0.301*x - 0.06245*(1.0*x - 2)*(1.0*x - 1) - 0.301\n", + "p(2.5) = 0.4047 \n", + "\n" + ] + } + ], + "source": [ + "from numpy import zeros, prod, ones, array\n", + "from sympy.abc import x\n", + "i = [ 0, 1 ,2 ,3]\n", + "X = range(1,5)\n", + "Fx = [ 0, 0.3010, 0.4771, 0.6021] \n", + "X = range(1,4)\n", + "Fx = Fx[0:3]\n", + "#x = poly(0,'x');\n", + "#A = Fx'\n", + "A=zeros([3,3])\n", + "A[:,0]=Fx\n", + "for i in range(2,4):\n", + " for j in range(1,4-i+1):\n", + " A[j-1,i-1] = ( A[j+1-1,i-1-1]-A[j-1,i-1-1] )/(X[j+i-1-1]-X[j-1]) ;\n", + "\n", + "print 'The coefficients of the polynomial are,\\n a0 = %.4G \\n a1 = %.4G \\n a2 = %.4G \\n'%(A[0,0],A[0,1],A[0,2])\n", + "p = A[0,0]\n", + "\n", + "for i in range(2,4):\n", + " p = p +A[0,i-1]* prod(array([x*xx for xx in ones([1,i-1])]) - array(X[0:i-1]))\n", + "print 'Polynomial is : ',str(p)\n", + "x=2.5\n", + "p=A[0,0]\n", + "for i in range(2,4):\n", + " p = p +A[0,i-1]* prod(array([x*xx for xx in ones([1,i-1])]) - array(X[0:i-1]))\n", + "print 'p(2.5) = %.4G \\n'%p" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 9_07 Pg No. 291" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " p0(1.5) = 0.000000 \n", + " p1(1.5) = 3.500000 \n", + " p2(1.5) = 2.000000 \n", + " p3(1.5) = 2.375000 \n", + " p4(1.5) = 2.375000 \n", + "\n", + "The function value at x = 1.5 is : 2.375\n" + ] + } + ], + "source": [ + "from numpy import zeros, prod, ones, array\n", + "#Newton Divided Difference Interpolation\n", + "\n", + "i = range(0,5)\n", + "X = range(1,6)\n", + "Fx = [ 0, 7 ,26 ,63 ,124]\n", + "#x = Symbol('x')\n", + "A=zeros([5,7])\n", + "A[:,0]=i\n", + "A[:,1]=X\n", + "A[:,2]=Fx\n", + "\n", + "for i in range(4,8):\n", + " for j in range(1,9-i):\n", + " A[j-1,i-1] = ( A[j,i-2]-A[j-1,i-2] )/(X[j+i-4]-X[j-1]) \n", + " \n", + "\n", + "p = A[0,2]\n", + "p1_5 = [p,0,0,0,0,0,0,0] \n", + "x=1.5\n", + "for i in range(4,8):\n", + " p = p +A[0,i-1]* prod(array([x*xx for xx in ones([1,i-3])]) - array(X[0:i-3]))\n", + " p1_5[i-3] = p#horner(p,1.5)#\n", + "\n", + "print ' p0(1.5) = %f \\n p1(1.5) = %f \\n p2(1.5) = %f \\n p3(1.5) = %f \\n p4(1.5) = %f \\n'%(p1_5[0],p1_5[1],p1_5[2],p1_5[3],p1_5[4])\n", + "print 'The function value at x = 1.5 is : ',p1_5[4] " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 9_08 Pg No. 297" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "A = \n", + "[[ 1.00000000e+01 1.73600000e-01 1.68400000e-01 -1.04000000e-02\n", + " -4.80000000e-03 4.00000000e-04]\n", + " [ 2.00000000e+01 3.42000000e-01 1.58000000e-01 -1.52000000e-02\n", + " -4.40000000e-03 0.00000000e+00]\n", + " [ 3.00000000e+01 5.00000000e-01 1.42800000e-01 -1.96000000e-02\n", + " 0.00000000e+00 0.00000000e+00]\n", + " [ 4.00000000e+01 6.42800000e-01 1.23200000e-01 0.00000000e+00\n", + " 0.00000000e+00 0.00000000e+00]\n", + " [ 5.00000000e+01 7.66000000e-01 0.00000000e+00 0.00000000e+00\n", + " 0.00000000e+00 0.00000000e+00]]\n", + "\n", + " p1(s) = 0.3472 \n", + " p2(s) = 0.3472 \n", + " p3(s) = 0.3472 \n", + " p4(s) = 0.3472 \n", + "\n", + "Thus sin(25) = 0.3472 \n", + " \n" + ] + } + ], + "source": [ + "from numpy import diff, zeros, prod, array, ones\n", + "from scipy.misc import factorial\n", + "#Newton-Gregory forward difference formula\n", + "\n", + "X = [ 10, 20 ,30, 40, 50]\n", + "Fx = [ 0.1736, 0.3420 ,0.5000 ,0.6428, 0.7660]\n", + "#x = poly(0,'x'#\n", + "\n", + "A=zeros([5,6])\n", + "A[:,0]=X\n", + "A[:,1]=Fx\n", + "\n", + "\n", + "for i in range(3,7):\n", + " A[0:7-i,i-1] = diff(A[0:8-i,i-2])\n", + " \n", + "print 'A = \\n',A\n", + "\n", + "x0 = X[0]\n", + "h = X[1] - X[0] #\n", + "x1 = 25\n", + "s = (x1 - x0)/h #\n", + "p = [Fx[0]] \n", + "\n", + "for j in range(0,4):\n", + " p.append(p[j] + prod( array([s*xx for xx in ones([1,j+1])])-array([range(0,j+1)]) )*A[0,j+1]/factorial(j+1))\n", + "\n", + "print '\\n p1(s) = %.4G \\n p2(s) = %.4G \\n p3(s) = %.4G \\n p4(s) = %.4G \\n'%(p[1],p[2],p[3],p[4]) \n", + "print 'Thus sin(%d) = %.4G \\n '%(x1,p[4]) " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 9_09 Pg No. 299" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "A=\n", + "[[ 1.00000000e+01 1.73600000e-01 0.00000000e+00 0.00000000e+00\n", + " 0.00000000e+00 0.00000000e+00]\n", + " [ 2.00000000e+01 3.42000000e-01 1.68400000e-01 0.00000000e+00\n", + " 0.00000000e+00 0.00000000e+00]\n", + " [ 3.00000000e+01 5.00000000e-01 1.58000000e-01 -1.04000000e-02\n", + " 0.00000000e+00 0.00000000e+00]\n", + " [ 4.00000000e+01 6.42800000e-01 1.42800000e-01 -1.52000000e-02\n", + " -4.80000000e-03 0.00000000e+00]\n", + " [ 5.00000000e+01 7.66000000e-01 1.23200000e-01 -1.96000000e-02\n", + " -4.40000000e-03 4.00000000e-04]]\n", + "\n", + " s = -3\n", + "\n", + "\n", + " p1(s) = 0.3964 \n", + " p2(s) = 0.2788 \n", + " p3(s) = 0.3228 \n", + " p4(s) = 0.3288 \n", + "\n", + " Thus sin(25) = 0.3288 \n", + " \n" + ] + } + ], + "source": [ + "from numpy import diff, prod, array, ones, zeros\n", + "from scipy.misc import factorial\n", + "#Newton Backward difference formula\n", + "\n", + "X = [ 10, 20, 30 ,40, 50]\n", + "Fx = [ 0.1736, 0.3420, 0.5000, 0.6428, 0.7660]\n", + "#x = poly(0,'x'#\n", + "#A = [X' Fx']#\n", + "A=zeros([5,6])\n", + "A[:,0]=X\n", + "A[:,1]=Fx\n", + "\n", + "\n", + "for i in range(2,6):\n", + " A[i-1:5,i] = diff(A[i-2:5,i-1])\n", + "\n", + "print 'A=\\n',A\n", + "\n", + "xn = X[4]\n", + "h = 10 #\n", + "xuk = 25#\n", + "s = (xuk - xn)/h #\n", + "print '\\n s =',s\n", + "p = [Fx[4]]\n", + "\n", + "for j in range(1,5):\n", + " p.append(p[j-1] + prod(array([s*xx for xx in ones([1,j])]-array([range(0,j)])))*A[4,j+1]/factorial(j) )\n", + " \n", + "print '\\n\\n p1(s) = %.4G \\n p2(s) = %.4G \\n p3(s) = %.4G \\n p4(s) = %.4G \\n'%(p[1],p[2],p[3],p[4]) \n", + "print ' Thus sin(%d) = %.4G \\n '%(xuk,p[4]) " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 9_10 Pg No. 301" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "case 1:\n", + "The piecewise polynomials are continuous and f(x) is a linear spline\n", + "case 2:\n", + "The 1th derivative of polynomial is not continuours\n", + "case 3\n", + "The polynomial is continuous and its derivatives from 1 to 1 are continuous, f(x) is a 2th degree polynomial\n" + ] + } + ], + "source": [ + "from sympy import symbols, degree\n", + "from sympy.polys.polyfuncs import horner\n", + "\n", + "x = symbols('x')\n", + "def isitspline(f1,f2,f3,x0,x1,x2,x3):\n", + " n1 = degree(f1)\n", + " n2 = degree(f2)\n", + " n3 = degree(f3)\n", + " n = max(n1,n2,n3)\n", + " f1_x1 = f1.subs(x,x1)\n", + " f2_x1 = f2.subs(x,x1)\n", + " f2_x2 = f2.subs(x,x2)\n", + " f3_x2 = f3.subs(x,x2)\n", + " if n ==1 and f1_x1 == f2_x1 and f2_x2 == f3_x2:\n", + " print 'The piecewise polynomials are continuous and f(x) is a linear spline'\n", + " elif f1_x1 == f2_x1 and f2_x2 == f3_x2:\n", + " for i in range(1,n):\n", + " df1 = f1.diff()\n", + " df2 = f2.diff()\n", + " df3 = f3.diff()\n", + " df1_x1 = df1.subs(x,x1)\n", + " df2_x1 = df2.subs(x,x1)\n", + " df2_x2 = df2.subs(x,x2)\n", + " df3_x2 = df3.subs(x,x2)\n", + " f1 = df1\n", + " f2 = df2\n", + " f3 = df3\n", + " if df1_x1 != df2_x1 or df2_x2 != df3_x2:\n", + " print 'The %dth derivative of polynomial is not continuours'%i\n", + " break;\n", + " \n", + " \n", + " if i == n-1 and df1_x1 == df2_x1 and df2_x2 == df3_x2:\n", + " print 'The polynomial is continuous and its derivatives from 1 to %i are continuous, f(x) is a %ith degree polynomial'%(i,i+1)\n", + " \n", + " else:\n", + " print 'The polynomial is not continuous'\n", + " \n", + " \n", + "n = 4 \n", + "x0 = -1 \n", + "x1 = 0\n", + "x2 = 1\n", + "x3 = 2\n", + "f1 = x+1 ;\n", + "f2 = 2*x + 1 ;\n", + "f3 = 4 - x ;\n", + "print 'case 1:'\n", + "isitspline(f1,f2,f3,x0,x1,x2,x3)\n", + "n = 4\n", + "x0 = 0 \n", + "x1= 1 \n", + "x2 = 2 \n", + "x3 = 3\n", + "f1 = x**2 + 1 ;\n", + "f2 = 2*x**2 ;\n", + "f3 = 5*x - 2 ;\n", + "print 'case 2:'\n", + "isitspline(f1,f2,f3,x0,x1,x2,x3)\n", + "n = 4\n", + "x0 = 0\n", + "x1 = 1\n", + "x2 = 2\n", + "x3 = 3\n", + "f1 = x\n", + "f2 = x**2 - x + 1\n", + "f3 = 3*x - 3\n", + "print 'case 3'\n", + "isitspline(f1,f2,f3,x0,x1,x2,x3)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 9_11 Pg No. 306" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "h= [5 7]\n", + "a1 = -0.0142857142857\n", + "s(x) = 0.497619047619048*x - 0.0119047619047619*(1.0*x - 4)**3 + 0.00952380952380905\n", + "s(7) : 3.17142857142857\n" + ] + } + ], + "source": [ + "from numpy import array,diff, zeros, ones\n", + "from sympy import symbols\n", + "from __future__ import division\n", + "X = [ 4, 9, 16]\n", + "Fx = [ 2, 3, 4]\n", + "n = len(X)\n", + "h = diff(X)\n", + "print 'h=',h\n", + "x = symbols('x')\n", + "#A(1) = 0;\n", + "#A(n) = 0;\n", + "A=zeros(n)\n", + "#Since we do not know only a1 = A(2) we just have one equation which can be solved directly without solving tridiagonal matrix\n", + "A[1] = 6*( ( Fx[2] - Fx[1] )/h[1] - ( Fx[1] - Fx[0] )/h[0] )/( 2*( h[0] + h[1] ) )\n", + "print 'a1 = ',A[1]\n", + "xuk = 7;\n", + "for i in range(1,n):\n", + " if xuk <= X[i]:\n", + " break;\n", + " \n", + "\n", + "#u = x*ones([1,2]) - X[i-1:i+1]\n", + "u = array([x*xx for xx in ones([1,2])]) - array(X[i-1:i+1])\n", + "s = ( A[1]*( u[0][i-1]**3 - ( h[i-1]**2 )*u[0][i-1])/6*h[i-1] ) + ( Fx[i]*u[0][i-1]- Fx[i-1]*u[0][i] )/h[i-1]\n", + "print 's(x) =',s\n", + "s_7 = s.subs(x,xuk);\n", + "print 's(7) :',s_7" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example No. 9_12 Pg No. 313" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "h= [1 1 1]\n", + "[[4 1]\n", + " [1 4]]\n", + "D= [ 0.5004 0.1998]\n", + "A= [ 0. 0.12012 0.01992 0. ]\n", + "s(x) = -0.0666*x - 0.02002*(1.0*x - 3)**2 + 0.00332*(1.0*x - 2)**3 + 0.44648\n", + "s(2.5): 0.275390000000000\n" + ] + } + ], + "source": [ + "from numpy import diff, diag, transpose, zeros,array, ones\n", + "from sympy import symbols\n", + "from numpy.linalg import solve\n", + "#Cubic Spline Interpolation\n", + "\n", + "X = range(1,5)\n", + "Fx = [ 0.5, 0.3333, 0.25, 0.2]\n", + "n = len(X)\n", + "h = diff(X)\n", + "print 'h=',h\n", + "x = symbols('x')\n", + "A=zeros(n)\n", + "#Forming Tridiagonal Matrix\n", + "#take make diagonal below main diagonal be 1 , main diagonal is 2 and diagonal above main diagonal is 3\n", + "diag1 = h[1:n-2]\n", + "diag2 = 2*(h[0:n-2]+h[1:n-1])\n", + "diag3 = h[1:n-2]\n", + "TridiagMat = diag(diag1,-1)+diag(diag2)+diag(diag3,1)\n", + "print TridiagMat\n", + "D = diff(Fx)#\n", + "D = 6*diff(D/h)\n", + "print 'D=',D\n", + "A[1:n-1] = solve(array(TridiagMat),array(D))\n", + "print 'A=',A\n", + "xuk = 2.5;\n", + "for i in range(1,n):\n", + " if xuk <= X[i]:\n", + " break;\n", + " \n", + "\n", + "u = array([x*xx for xx in ones([1,2])]) - array(X[i-1:i+1])\n", + "s = ( A[i-1]*( h[i]**2*u[0][1] - u[0][1]**2 )/( 6*h[i] ) ) + ( A[i]*( u[0][0]**3 - ( h[i-1]**2 )*u[0][0])/6*h[i-1] ) + ( Fx[i]*u[0][0]- Fx[i-1]*u[0][1] )/h[i-1];\n", + "print 's(x) = ',s\n", + "s2_5 = s.subs(x,xuk)\n", + "print 's(2.5):',s2_5" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.9" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Numerical_Methods_by_E._Balaguruswamy/screenshots/greatest-precision-4.png b/Numerical_Methods_by_E._Balaguruswamy/screenshots/greatest-precision-4.png Binary files differnew file mode 100644 index 00000000..27825c68 --- /dev/null +++ b/Numerical_Methods_by_E._Balaguruswamy/screenshots/greatest-precision-4.png diff --git a/Numerical_Methods_by_E._Balaguruswamy/screenshots/rounding-off-4.png b/Numerical_Methods_by_E._Balaguruswamy/screenshots/rounding-off-4.png Binary files differnew file mode 100644 index 00000000..ff48734e --- /dev/null +++ b/Numerical_Methods_by_E._Balaguruswamy/screenshots/rounding-off-4.png diff --git a/Numerical_Methods_by_E._Balaguruswamy/screenshots/truncation-error-4.png b/Numerical_Methods_by_E._Balaguruswamy/screenshots/truncation-error-4.png Binary files differnew file mode 100644 index 00000000..fbdf6b2c --- /dev/null +++ b/Numerical_Methods_by_E._Balaguruswamy/screenshots/truncation-error-4.png diff --git a/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_4JhcI7F.ipynb b/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_4JhcI7F.ipynb new file mode 100644 index 00000000..a4871749 --- /dev/null +++ b/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_4JhcI7F.ipynb @@ -0,0 +1,681 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# 4: Matter Waves" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 1, Page number 158" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "de-Broglie wavelength of proton is 1 angstrom\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "m=1.67*10**-27; #mass of proton(kg)\n", + "h=6.625*10**-34; #planks constant(Js)\n", + "v=3967; #velocity of proton(m/s)\n", + "\n", + "#Calculations\n", + "lamda=h/(m*v); #de-Broglie wavelength of proton(m)\n", + "\n", + "#Result\n", + "print \"de-Broglie wavelength of proton is\",int(lamda*10**10),\"angstrom\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 2, Page number 158" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "kinetic energy of electron is 6 eV\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "m=9.11*10**-31; #mass of electron(kg)\n", + "h=6.625*10**-34; #planks constant(Js)\n", + "lamda=5*10**-10; #de-Broglie wavelength(m)\n", + "e=1.6*10**-19; #charge(coulomb)\n", + "\n", + "#Calculations\n", + "E=h**2/(2*m*lamda**2*e); #kinetic energy of electron(eV)\n", + "\n", + "#Result\n", + "print \"kinetic energy of electron is\",int(E),\"eV\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 3, Page number 158" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "de-Broglie wavelength of proton is 3.97 *10**-6 angstrom\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "c=3*10**8; #velocity of light(m/sec)\n", + "m=1.67*10**-27; #mass of proton(kg)\n", + "h=6.625*10**-34; #planks constant(Js)\n", + "\n", + "#Calculations\n", + "v=c/30; #velocity of proton(m/sec)\n", + "lamda=h/(m*v); #de-Broglie wavelength of proton(m)\n", + "\n", + "#Result\n", + "print \"de-Broglie wavelength of proton is\",round(lamda*10**14,2),\"*10**-6 angstrom\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 4, Page number 159" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "de-Broglie wavelength of electron is 1 angstrom\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "V=150; #potential difference(V)\n", + "\n", + "#Calculations\n", + "lamda=12.26/math.sqrt(V); #de-Broglie wavelength of electron(angstrom)\n", + "\n", + "#Result\n", + "print \"de-Broglie wavelength of electron is\",int(lamda),\"angstrom\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 5, Page number 159" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "de-Broglie wavelength is 1.23 angstrom\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "V=100; #voltage(eV) \n", + "m=9.1*10**-31; #mass of proton(kg)\n", + "h=6.625*10**-34; #planks constant(Js)\n", + "e=1.6*10**-19; #charge(coulomb)\n", + "\n", + "#Calculations\n", + "lamda=h*10**10/math.sqrt(2*m*e*V); #de-Broglie wavelength(angstrom)\n", + "\n", + "#Result\n", + "print \"de-Broglie wavelength is\",round(lamda,2),\"angstrom\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 6, Page number 159" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "de-Broglie wavelength of neutron is 0.99 angstrom\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "m=1.67*10**-27; #mass of proton(kg)\n", + "h=6.625*10**-34; #planks constant(Js)\n", + "v=4000; #velocity of proton(m/s)\n", + "\n", + "#Calculations\n", + "lamda=h*10**10/(m*v); #de-Broglie wavelength of neutron(angstrom)\n", + "\n", + "#Result\n", + "print \"de-Broglie wavelength of neutron is\",round(lamda,2),\"angstrom\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 7, Page number 160" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ratio of kinetic energies of electron and proton is 1833\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "mp=1.67*10**-27; #mass of proton(kg)\n", + "me=9.11*10**-31; #mass of electron(kg)\n", + "\n", + "#Calculations\n", + "r=mp/me; #ratio of kinetic energies of electron and proton\n", + "\n", + "#Result\n", + "print \"ratio of kinetic energies of electron and proton is\",int(r)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 8, Page number 160" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ratio of wavelengths is 32\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "m=9.1*10**-31; #mass of proton(kg)\n", + "e=1.6*10**-19; #charge(coulomb)\n", + "c=3*10**8; #velocity of light(m/sec)\n", + "E=1000; #energy(eV)\n", + "\n", + "#Calculations\n", + "r=math.sqrt(2*m/(e*E))*c; #ratio of wavelengths\n", + "\n", + "#Result\n", + "print \"ratio of wavelengths is\",int(round(r))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 9, Page number 160" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "wavelength of electron is 0.289 angstrom\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "m=9.1*10**-31; #mass of electron(kg)\n", + "c=3*10**8; #velocity of light(m/sec)\n", + "h=6.6*10**-34; #planks constant(Js)\n", + "lamda=1.54*10**-10; #wavelength of X-ray(m)\n", + "wf=1*10**-15; #work function(J)\n", + "\n", + "#Calculations\n", + "E=h*c/lamda; #energy of X-ray(J)\n", + "Ee=E-wf; #energy of electron emitted(J)\n", + "lamda=h/math.sqrt(2*m*Ee); #wavelength of electron(m)\n", + "\n", + "#Result\n", + "print \"wavelength of electron is\",round(lamda*10**10,3),\"angstrom\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 10, Page number 161" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "de broglie wavelength of proton is 1.537 angstrom\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "m=1.67*10**-27; #mass of proton(kg)\n", + "h=6.6*10**-34; #planks constant(Js)\n", + "T=400; #temperature(K)\n", + "k=1.38*10**-23; #boltzmann constant\n", + "\n", + "#Calculations\n", + "lamda=h*10**10/math.sqrt(2*m*k*T); #de broglie wavelength of proton(angstrom)\n", + "\n", + "#Result\n", + "print \"de broglie wavelength of proton is\",round(lamda,3),\"angstrom\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 11, Page number 162" + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "rest energy of electron is 8.19e-14 J\n", + "energy of proton is 8.19e-11 J\n", + "velocity of proton is 312902460.506 m/s\n", + "wavelength of electron is 1.27 *10**-5 angstrom\n", + "answers given in the book are wrong\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "m=1.673*10**-27; #mass of proton(kg)\n", + "m0=9.1*10**-31; #mass of electron(kg)\n", + "c=3*10**8; #velocity of light(m/sec)\n", + "h=6.63*10**-34; #planks constant(Js)\n", + "ke=1000; #kinetic energy\n", + "\n", + "#Calculations\n", + "re=m0*c**2; #rest energy of electron(J)\n", + "Ep=ke*re; #energy of proton(J)\n", + "v=math.sqrt(2*Ep/m); #velocity of proton(m/s)\n", + "lamda=h*10**10/(m*v); #debroglie wavelength of proton(angstrom)\n", + "\n", + "#Result\n", + "print \"rest energy of electron is\",re,\"J\"\n", + "print \"energy of proton is\",Ep,\"J\"\n", + "print \"velocity of proton is\",v,\"m/s\"\n", + "print \"wavelength of electron is\",round(lamda*10**5,2),\"*10**-5 angstrom\"\n", + "print \"answers given in the book are wrong\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 12, Page number 162" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "velocity of electron is 4.55 *10**7 m/s\n", + "kinetic energy is 5887 eV\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "m=9.1*10**-31; #mass of electron(kg)\n", + "h=6.625*10**-34; #planks constant(Js)\n", + "lamda=0.16*10**-10; #debroglie wavelength of electron(m)\n", + "e=1.6*10**-19; #charge(coulomb)\n", + "\n", + "#Calculations\n", + "v=h/(lamda*m); #velocity of electron(m/s)\n", + "KE=m*v**2/(2*e); #kinetic energy(eV)\n", + "\n", + "#Result\n", + "print \"velocity of electron is\",round(v*10**-7,2),\"*10**7 m/s\"\n", + "print \"kinetic energy is\",int(KE),\"eV\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 13, Page number 163" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "interplanar spacing of crystal is 1.78 angstrom\n", + "answer given in the book is wrong\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "m=1.67*10**-27; #mass of proton(kg)\n", + "h=6.62*10**-34; #planks constant(Js)\n", + "T=300; #temperature(K)\n", + "k=1.38*10**-23; #boltzmann constant\n", + "\n", + "#Calculations\n", + "d=h*10**10/math.sqrt(2*m*k*T); #interplanar spacing of crystal(angstrom)\n", + "\n", + "#Result\n", + "print \"interplanar spacing of crystal is\",round(d,2),\"angstrom\"\n", + "print \"answer given in the book is wrong\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 14, Page number 164" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "potential is 605.16 volts\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "lamda=0.5; #wavelength(angstrom)\n", + "\n", + "#Calculations\n", + "V=(12.3/lamda)**2; #potential(volts)\n", + "\n", + "#Result\n", + "print \"potential is\",V,\"volts\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 15, Page number 164" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "energy of gama ray photon is 19.89 *10**-16 J\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "lamda=1*10**-10; #wavelength(m)\n", + "h=6.63*10**-34; #planks constant(Js)\n", + "c=3*10**8; #velocity of light(m/sec)\n", + "\n", + "#Calculations\n", + "p=h/lamda; #momentum(J-sec/m)\n", + "E=p*c; #energy of gama ray photon(J)\n", + "\n", + "#Result\n", + "print \"energy of gama ray photon is\",E*10**16,\"*10**-16 J\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 16, Page number 164" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "velocity of electron is 2.2 *10**6 m/sec\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "h=6.6*10**-34; #planks constant(Js)\n", + "m=9*10**-31; #mass of electron(kg)\n", + "r=0.53*10**-10; #radius of orbit(m)\n", + "\n", + "#Calculations\n", + "v=h/(2*math.pi*r*m); #velocity of electron(m/sec)\n", + "\n", + "#Result\n", + "print \"velocity of electron is\",round(v*10**-6,1),\"*10**6 m/sec\"" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_5CfOfQx.ipynb b/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_5CfOfQx.ipynb new file mode 100644 index 00000000..3725056f --- /dev/null +++ b/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_5CfOfQx.ipynb @@ -0,0 +1,243 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# 13: Bonding In Crystals" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 1, Page number 398" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "potential energy is -5.76 eV\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "x=9*10**9; #assume x=1/(4*pi*epsilon0)\n", + "e=1.6*10**-19; #charge(coulomb)\n", + "r0=2.5*10**-10; #radius(m)\n", + "\n", + "#Calculation\n", + "U=-e*x/r0; #potential energy(eV)\n", + "\n", + "#Result\n", + "print \"potential energy is\",U,\"eV\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 2, Page number 398" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "equilibrium distance is -2.25 angstrom\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "x=9*10**9; #assume x=1/(4*pi*epsilon0)\n", + "e=1.6*10**-19; #charge(coulomb)\n", + "U=6.4; #potential energy(eV)\n", + "\n", + "#Calculation\n", + "r0=-e*x/U; #equilibrium distance(m)\n", + "\n", + "\n", + "#Result\n", + "print \"equilibrium distance is\",r0*10**10,\"angstrom\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 3, Page number 399" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "compressibility of the solid is -25.087 *10**14\n", + "answer given in the book is wrong\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "x=9*10**9; #assume x=1/(4*pi*epsilon0)\n", + "e=1.6*10**-19; #charge(coulomb)\n", + "alpha=1.76; #madelung constant\n", + "n=0.5; #repulsive exponent\n", + "r0=4.1*10**-4; #equilibrium distance(m)\n", + "\n", + "#Calculation\n", + "C=18*r0**4/(x*alpha*e**2*(n-1)); #compressibility of the solid\n", + "\n", + "#Result\n", + "print \"compressibility of the solid is\",round(C*10**-14,3),\"*10**14\"\n", + "print \"answer given in the book is wrong\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 4, Page number 399" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "lattice energy is -6.45 eV\n", + "energy needed to form neutral atoms is -6.17 eV\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "x=9*10**9; #assume x=1/(4*pi*epsilon0)\n", + "e=1.6*10**-19; #charge(coulomb)\n", + "alpha=1.763; #madelung constant\n", + "n=10.5; #repulsive exponent\n", + "r0=3.56*10**-10; #equilibrium distance(m)\n", + "IE=3.89; #ionisation energy(eV)\n", + "EA=-3.61; #electron affinity(eV)\n", + "\n", + "#Calculation\n", + "U=-x*alpha*e**2*(1-(1/n))/(e*r0); #lattice energy(eV) \n", + "E=U+EA+IE; #energy needed to form neutral atoms\n", + "\n", + "#Result\n", + "print \"lattice energy is\",round(U,2),\"eV\"\n", + "print \"energy needed to form neutral atoms is\",round(E,2),\"eV\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 5, Page number 400" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "lattice energy is -3.98 eV\n", + "answer given in the book is wrong\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "x=9*10**9; #assume x=1/(4*pi*epsilon0)\n", + "e=1.6*10**-19; #charge(coulomb)\n", + "alpha=1.748; #madelung constant\n", + "n=9; #repulsive exponent\n", + "r0=2.81*10**-10; #equilibrium distance(m)\n", + "\n", + "#Calculation\n", + "U=-x*alpha*e**2*(1-(1/n))/(e*r0); #lattice energy(eV) \n", + "\n", + "#Result\n", + "print \"lattice energy is\",round(U/2,2),\"eV\"\n", + "print \"answer given in the book is wrong\"" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_B30VPml.ipynb b/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_B30VPml.ipynb new file mode 100644 index 00000000..4f050408 --- /dev/null +++ b/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_B30VPml.ipynb @@ -0,0 +1,244 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# 10: Nuclear Detectors" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 1, Page number 322" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "current produced is 1.829 *10**-13 amp\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "e=1.6*10**-19; #charge(coulomb)\n", + "n=10; #number of particles\n", + "E=4*10**6; #energy of alpha particle(eV)\n", + "E1=35; #energy of 1 ion pair(eV)\n", + "\n", + "#Calculation\n", + "N=E*n/E1; #number of ion pairs\n", + "q=N*e; #current produced(amp)\n", + "\n", + "#Result\n", + "print \"current produced is\",round(q*10**13,3),\"*10**-13 amp\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 2, Page number 322" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "number of ion pairs required is 6.25 *10**5\n", + "energy of alpha-particles is 21.875 MeV\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "v=4; #voltage sensitivity(div/volt)\n", + "d=0.8; #number of divisions\n", + "C=0.5*10**-12; #capacitance(F)\n", + "e=1.6*10**-19; #charge(coulomb)\n", + "E1=35; #energy of 1 ion pair(eV)\n", + "\n", + "#Calculation\n", + "V=d/v; #voltage(V)\n", + "q=C*V; #current(C)\n", + "n=q/e; #number of ion pairs required\n", + "E=n*E1/10**6; #energy of alpha-particles(MeV)\n", + "\n", + "#Result\n", + "print \"number of ion pairs required is\",n/10**5,\"*10**5\"\n", + "print \"energy of alpha-particles is\",E,\"MeV\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 3, Page number 323" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "maximum radial field is 1.89 *10**6 volts/meter\n", + "counter will last for 3.7 years\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "V=1000; #voltage(V)\n", + "r=0.0001; #radius(m)\n", + "b=2*10**-2; #diameter(m)\n", + "a=10**-4;\n", + "n=10**9; #number of counts\n", + "\n", + "#Calculation\n", + "Emax=V/(r*math.log(b/a)); #maximum radial field(volts/meter)\n", + "N=n/(50*30*60*3000); #counter will last for(years)\n", + "\n", + "#Result\n", + "print \"maximum radial field is\",round(Emax/10**6,2),\"*10**6 volts/meter\"\n", + "print \"counter will last for\",round(N,1),\"years\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 4, Page number 324" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "energy of the particle is 1500 MeV\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "r=2; #radius(m)\n", + "B=2.5; #flux density(Wb/m**2)\n", + "q=1.6*10**-19; #charge(coulomb)\n", + "c=3*10**8; #velocity of light(m/sec)\n", + "\n", + "#Calculation\n", + "E=B*q*r*c*10**-6/q; #energy of the particle(MeV)\n", + "\n", + "#Result\n", + "print \"energy of the particle is\",int(E),\"MeV\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 5, Page number 325" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "average current in the circuit is 1.6e-11 A\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "cr=600; #counting rate(counts/minute)\n", + "e=10**7; #number of electrons per discharge\n", + "q=1.6*10**-19; #charge(coulomb)\n", + "t=60; #number of seconds\n", + "\n", + "#Calculation\n", + "n=cr*e; #number of electrons in 1 minute\n", + "q=n*q/t; #average current in the circuit(A)\n", + "\n", + "#Result\n", + "print \"average current in the circuit is\",q,\"A\"" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_BE8QjoS.ipynb b/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_BE8QjoS.ipynb new file mode 100644 index 00000000..fd167244 --- /dev/null +++ b/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_BE8QjoS.ipynb @@ -0,0 +1,304 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# 6: Schrodinger Wave Mechanics" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 8, Page number 228" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "energy levels are 38 eV 150 eV 339 eV\n", + "answer given in the book is wrong\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "m=9.1*10**-31; #mass of electron(kg)\n", + "e=1.6*10**-19; #charge(coulomb)\n", + "a=10**-10; #width(m)\n", + "h=6.62*10**-34; #planck's constant\n", + "n1=1;\n", + "n2=2;\n", + "n3=3;\n", + "\n", + "#Calculation\n", + "Ex=h**2/(8*e*m*a**2); #energy(eV)\n", + "E1=Ex*n1**2; #energy at 1st level(eV)\n", + "E2=Ex*n2**2; #energy at 2nd level(eV)\n", + "E3=Ex*n3**2; #energy at 3rd level(eV)\n", + "\n", + "#Result\n", + "print \"energy levels are\",int(round(E1)),\"eV\",int(round(E2)),\"eV\",int(round(E3)),\"eV\"\n", + "print \"answer given in the book is wrong\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 9, Page number 229" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "probability of finding the particle is 0.133\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "deltax=1*10**-10; #width\n", + "a=15*10**-10; #width(m)\n", + "\n", + "#Calculation\n", + "W=2*deltax/a; #probability of finding the particle\n", + "\n", + "#Result\n", + "print \"probability of finding the particle is\",round(W,3)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 10, Page number 229" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "probability of transmission of electron is 0.5\n", + "answer given in the book is wrong\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "E=1; #energy(eV)\n", + "V0=2; #voltage(eV)\n", + "m=9.1*10**-31; #mass of electron(kg)\n", + "e=1.6*10**-19; #charge(coulomb)\n", + "chi=1.05*10**-34; \n", + "a=2*10**-10; #potential barrier\n", + "\n", + "#Calculation\n", + "x=math.sqrt(2*m*(V0-E)*e);\n", + "y=16*E*(1-(E/V0))/V0;\n", + "T=y*math.exp(-2*a*x/chi); #probability of transmission of electron\n", + "\n", + "#Result\n", + "print \"probability of transmission of electron is\",round(T,1)\n", + "print \"answer given in the book is wrong\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 11, Page number 230" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "fraction of electrons reflected is 0.38\n", + "fraction of electrons transmitted is 0.62\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "E=0.080*10**-19; #energy(eV)\n", + "E_V0=0.016*10**-19; #voltage(eV)\n", + "\n", + "#Calculation\n", + "x=math.sqrt(E);\n", + "y=math.sqrt(E_V0);\n", + "R=(x-y)/(x+y); #fraction of electrons reflected\n", + "T=1-R; #fraction of electrons transmitted\n", + "\n", + "#Result\n", + "print \"fraction of electrons reflected is\",round(R,2)\n", + "print \"fraction of electrons transmitted is\",round(T,2)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 12, Page number 231" + ] + }, + { + "cell_type": "code", + "execution_count": 37, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "fraction of electrons transmitted is 0.4998\n", + "fraction of electrons reflected is 0.5002\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "E=0.34; #energy(eV)\n", + "E_V0=0.01; #voltage(eV)\n", + "\n", + "#Calculation\n", + "x=math.sqrt(E);\n", + "y=math.sqrt(E_V0);\n", + "T=4*x*y/(x+y)**2; #fraction of electrons transmitted \n", + "R=1-T; #fraction of electrons reflected\n", + "\n", + "#Result\n", + "print \"fraction of electrons transmitted is\",round(T,4)\n", + "print \"fraction of electrons reflected is\",round(R,4)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 13, Page number 232" + ] + }, + { + "cell_type": "code", + "execution_count": 50, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "transmission coefficient is 3.27 *10**-9\n", + "transmission coefficient in 1st case is 7.62 *10**-8\n", + "transmission coefficient in 2nd case is 1.51 *10**-15\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "e=1.6*10**-19; #charge(coulomb)\n", + "E1=1*e; #energy(J)\n", + "E2=2*e; #energy(J)\n", + "V0=5*e; #voltage(J)\n", + "m=9.1*10**-31; #mass of electron(kg)\n", + "chi=1.054*10**-34; \n", + "a1=10*10**-10; #potential barrier(m)\n", + "a2=20*10**-10; #potential barrier(m)\n", + "\n", + "#Calculation\n", + "beta1=math.sqrt(2*m*(V0-E1)/(chi**2));\n", + "y1=16*E1*((V0-E1)/(V0**2));\n", + "T1=y1*math.exp(-2*a1*beta1); #transmission coefficient\n", + "beta2=math.sqrt(2*m*(V0-E2)/(chi**2));\n", + "y2=16*E2*((V0-E2)/(V0**2));\n", + "T2=y2*math.exp(-2*a1*beta2); #transmission coefficient in 1st case\n", + "T3=y2*math.exp(-2*a2*beta2); #transmission coefficient in 2nd case\n", + "\n", + "#Result\n", + "print \"transmission coefficient is\",round(T1*10**9,2),\"*10**-9\"\n", + "print \"transmission coefficient in 1st case is\",round(T2*10**8,2),\"*10**-8\"\n", + "print \"transmission coefficient in 2nd case is\",round(T3*10**15,2),\"*10**-15\"" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_Gb015bo.ipynb b/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_Gb015bo.ipynb new file mode 100644 index 00000000..e9b7b5a0 --- /dev/null +++ b/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_Gb015bo.ipynb @@ -0,0 +1,250 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# 12: X-ray Diffraction" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 1, Page number 378" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "wavelength of X-rays is 0.0842 nm\n", + "maximum order of diffraction is 6\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "d=0.282; #lattice spacing(nm)\n", + "theta=(8+(35/60))*math.pi/180; #glancing angle(radian)\n", + "n1=1; #order\n", + "\n", + "#Calculation\n", + "lamda=2*d*math.sin(theta)/n1; #wavelength of X-rays(nm)\n", + "n=2*d/lamda; #maximum order of diffraction\n", + "\n", + "#Result\n", + "print \"wavelength of X-rays is\",round(lamda,4),\"nm\"\n", + "print \"maximum order of diffraction is\",int(n)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 2, Page number 378" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "glancing angle for 1st order is 17 degrees 24 minutes\n", + "glancing angle for 2nd order is 36 degrees 44 minutes\n", + "answers given in the book are wrong\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "d=3.209; #lattice spacing(angstrom)\n", + "lamda=1.92; #wavelength of X-rays(angstrom)\n", + "n1=1; #order\n", + "n2=2; #order \n", + "\n", + "#Calculation\n", + "theta1=math.asin(n1*lamda/(2*d))*180/math.pi; #glancing angle for 1st order(degrees)\n", + "theta1d=int(theta1); #glancing angle for 1st order(degrees) \n", + "theta1m=(theta1-theta1d)*60; #glancing angle for 1st order(minutes)\n", + "theta2=math.asin(n2*lamda/(2*d))*180/math.pi; #glancing angle for 2nd order(degrees)\n", + "theta2d=int(theta2); #glancing angle for 2nd order(degrees)\n", + "theta2m=(theta2-theta2d)*60; #glancing angle for 2nd order(minutes)\n", + "\n", + "#Result\n", + "print \"glancing angle for 1st order is\",theta1d,\"degrees\",int(theta1m),\"minutes\"\n", + "print \"glancing angle for 2nd order is\",theta2d,\"degrees\",int(theta2m),\"minutes\"\n", + "print \"answers given in the book are wrong\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 4, Page number 379" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "wavelength of X-rays is 1.268 angstrom\n", + "answer given in the book is wrong\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "d=3.05; #lattice spacing(angstrom)\n", + "theta=12*math.pi/180; #glancing angle(radian)\n", + "n=1; #order\n", + "\n", + "#Calculation\n", + "lamda=2*d*math.sin(theta)/n1; #wavelength of X-rays(angstrom)\n", + "\n", + "#Result\n", + "print \"wavelength of X-rays is\",round(lamda,3),\"angstrom\"\n", + "print \"answer given in the book is wrong\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 5, Page number 380" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "wavelength of line A is 1.268 angstrom\n", + "answer given in the book is wrong\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "thetaA=30*math.pi/180; #glancing angle(radian)\n", + "thetaB=60*math.pi/180; #glancing angle(radian)\n", + "n1=1; #order\n", + "n2=2; #order\n", + "lamdaB=0.9; #wavelength of X-rays(angstrom)\n", + "\n", + "#Calculation\n", + "lamdaA=2*lamdaB*math.sin(thetaA)/math.sin(thetaB); #wavelength of line A(angstrom)\n", + "\n", + "#Result\n", + "print \"wavelength of line A is\",round(lamda,3),\"angstrom\"\n", + "print \"answer given in the book is wrong\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 6, Page number 380" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "wavelength of X-rays is 0.7853 angstrom\n", + "glancing angle for 2nd order is 18.2 degrees\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "d=2.51; #lattice spacing(angstrom)\n", + "theta=9*math.pi/180; #glancing angle(radian)\n", + "n1=1; #order\n", + "n2=2; #order\n", + "\n", + "#Calculation\n", + "lamda=2*d*math.sin(theta)/n1; #wavelength of X-rays(angstrom)\n", + "theta=math.asin(n2*lamda/(2*d))*180/math.pi; #glancing angle for 2nd order(degrees)\n", + "\n", + "#Result\n", + "print \"wavelength of X-rays is\",round(lamda,4),\"angstrom\"\n", + "print \"glancing angle for 2nd order is\",round(theta,1),\"degrees\"" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_KQ8ycMr.ipynb b/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_KQ8ycMr.ipynb new file mode 100644 index 00000000..283605cf --- /dev/null +++ b/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_KQ8ycMr.ipynb @@ -0,0 +1,236 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# 15: Superconductivity" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 1, Page number 442" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "critical field at 3K is 0.006281 Tesla\n", + "answer given in the book is wrong\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "H0=0.0106; #critical field at 0K(Tesla)\n", + "T=3; #temperature(K)\n", + "Tc=4.7; #temperature(K)\n", + "\n", + "#Calculation\n", + "Hc=H0*(1-(T/Tc)**2); #critical field at 3K(Tesla)\n", + "\n", + "#Result\n", + "print \"critical field at 3K is\",round(Hc,6),\"Tesla\"\n", + "print \"answer given in the book is wrong\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 2, Page number 442" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "temperature of superconductor is 1.701 K\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "H0=5*10**5/(4*math.pi); #critical field at 0K(Tesla)\n", + "Tc=2.69; #temperature(K)\n", + "Hc=3*10**5/(4*math.pi); #critical field(Tesla)\n", + "\n", + "#Calculation\n", + "T=Tc*math.sqrt(1-(Hc/H0)); #temperature(K)\n", + "\n", + "#Result\n", + "print \"temperature of superconductor is\",round(T,3),\"K\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 3, Page number 443" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "critical field is 4.3365 *10**4 A/m\n", + "critical current of the wire is 408 A\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "H0=6.5*10**4; #critical field at 0K(Tesla)\n", + "Tc=7.28; #temperature(K)\n", + "T=4.2; #temperature(K)\n", + "r=1.5*10**-3; #radius(m)\n", + "\n", + "#Calculation\n", + "Hc=H0*(1-(T/Tc)**2); #critical field(Tesla)\n", + "Ic=2*math.pi*r*Hc; #critical current of the wire(A)\n", + "\n", + "#Result\n", + "print \"critical field is\",round(Hc/10**4,4),\"*10**4 A/m\"\n", + "print \"critical current of the wire is\",int(Ic),\"A\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 4, Page number 443" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "critical temperature is 4.124 K\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "m1=199.5; #isotopic mass\n", + "m2=205.4; #change in mass \n", + "Tc1=4.185; #temperature of mercury(K)\n", + "\n", + "#Calculation\n", + "Tc2=Tc1*math.sqrt(m1/m2); #critical temperature(K)\n", + "\n", + "#Result\n", + "print \"critical temperature is\",round(Tc2,3),\"K\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 5, Page number 444" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "superconducting transition temperature is 8.106 K\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "T1=3; #temperature(K)\n", + "T2=8; #temperature(K)\n", + "lamda1=39.6; #penetration depth(nm)\n", + "lamda2=173; #penetration depth(nm)\n", + "\n", + "#Calculation\n", + "x=(lamda1/lamda2)**2;\n", + "Tc4=(T2**4-(x*T1**4))/(1-x);\n", + "Tc=Tc4**(1/4); #superconducting transition temperature(K)\n", + "\n", + "#Result\n", + "print \"superconducting transition temperature is\",round(Tc,3),\"K\"" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_LIZWeY4.ipynb b/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_LIZWeY4.ipynb new file mode 100644 index 00000000..1d50ed48 --- /dev/null +++ b/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_LIZWeY4.ipynb @@ -0,0 +1,384 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# 11: Crystal Structure" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 1, Page number 357" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "miller indices of plane are ( 6 4 3 )\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "a=1/2;\n", + "b=1/3;\n", + "c=1/4; #intercepts along the three axes\n", + "\n", + "#Calculations\n", + "def lcm(x, y):\n", + " if x > y:\n", + " greater = x\n", + " else:\n", + " greater = y\n", + " while(True):\n", + " if((greater % x == 0) and (greater % y == 0)):\n", + " lcm = greater\n", + " break\n", + " greater += 1\n", + " \n", + " return lcm\n", + "\n", + "z=lcm(1/a,1/b);\n", + "lcm=lcm(z,1/c);\n", + "h=a*lcm;\n", + "k=b*lcm;\n", + "l=c*lcm; #miller indices of plane\n", + "\n", + "#Result\n", + "print \"miller indices of plane are (\",int(h),int(k),int(l),\")\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 2, Page number 357" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "miller indices of plane are ( 3 2 0 )\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "a=1/2;\n", + "b=1/3;\n", + "x=float(\"inf\");\n", + "c=1/x; #intercepts along the three axes\n", + "\n", + "#Calculations\n", + "def lcm(x, y):\n", + " if x > y:\n", + " greater = x\n", + " else:\n", + " greater = y\n", + " while(True):\n", + " if((greater % x == 0) and (greater % y == 0)):\n", + " lcm = greater\n", + " break\n", + " greater += 1\n", + " \n", + " return lcm\n", + "\n", + "lcm=lcm(1/a,1/b);\n", + "h=a*lcm;\n", + "k=b*lcm;\n", + "l=c*lcm; #miller indices of plane\n", + "\n", + "#Result\n", + "print \"miller indices of plane are (\",int(h),int(k),int(l),\")\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 3, Page number 358" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "miller indices of plane are ( 6 3 2 )\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "a=1/1;\n", + "b=1/2;\n", + "c=1/3; #intercepts along the three axes\n", + "\n", + "#Calculations\n", + "def lcm(x, y):\n", + " if x > y:\n", + " greater = x\n", + " else:\n", + " greater = y\n", + " while(True):\n", + " if((greater % x == 0) and (greater % y == 0)):\n", + " lcm = greater\n", + " break\n", + " greater += 1\n", + " \n", + " return lcm\n", + "\n", + "z=lcm(1/a,1/b);\n", + "lcm=lcm(z,1/c);\n", + "h=a*lcm;\n", + "k=b*lcm;\n", + "l=c*lcm; #miller indices of plane\n", + "\n", + "#Result\n", + "print \"miller indices of plane are (\",int(h),int(k),int(l),\")\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 4, Page number 359" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "corresponding intercept on Y-axis and Z-axis are 0.8 angstrom and 0.65 angstrom\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "a=1.1;\n", + "b=1.2;\n", + "c=1.3; #intercepts along the three axes(angstrom)\n", + "h=2;\n", + "k=3;\n", + "l=4; #miller indices of plane\n", + "\n", + "#Calculations\n", + "l1=a*h/h;\n", + "l2=b*h/k; #corresponding intercept on Y-axis(angstrom)\n", + "l3=c*h/l; #corresponding intercept on Z-axis(angstrom)\n", + "\n", + "#Result\n", + "print \"corresponding intercept on Y-axis and Z-axis are\",l2,\"angstrom and\",l3,\"angstrom\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 5, Page number 360" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "miller indices of plane are ( 6 -2 3 )\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "a=1/1;\n", + "b=-1/3;\n", + "c=1/2; #intercepts along the three axes\n", + "\n", + "#Calculations\n", + "def lcm(x, y):\n", + " if x > y:\n", + " greater = x\n", + " else:\n", + " greater = y\n", + " while(True):\n", + " if((greater % x == 0) and (greater % y == 0)):\n", + " lcm = greater\n", + " break\n", + " greater += 1\n", + " \n", + " return lcm\n", + "\n", + "z=lcm(1/a,1/b);\n", + "lcm=lcm(z,1/c);\n", + "h=a*lcm;\n", + "k=b*lcm;\n", + "l=c*lcm; #miller indices of plane\n", + "\n", + "#Result\n", + "print \"miller indices of plane are (\",int(h),int(k),int(l),\")\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 6, Page number 360" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "lattice constant is 3.61 angstrom\n", + "distance between two nearest copper atoms is 2.55 angstrom\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "n=4; #number of molecules per unit cell\n", + "M=63.5; #molecular weight\n", + "N=6.02*10**26; #avagadro number(kg mol-1)\n", + "rho=8.96*10**3; #density(kg/m**3)\n", + "\n", + "#Calculations\n", + "a=(n*M/(rho*N))**(1/3); #lattice constant(m)\n", + "a=round(a*10**10,2); #lattice constant(angstrom) \n", + "d=a/math.sqrt(2); #distance between two nearest copper atoms(angstrom)\n", + "\n", + "#Result\n", + "print \"lattice constant is\",a,\"angstrom\"\n", + "print \"distance between two nearest copper atoms is\",round(d,2),\"angstrom\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 7, Page number 361" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "lattice constant is 2.8687 angstrom\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "n=2; #number of molecules per unit cell\n", + "M=55.85; #molecular weight\n", + "N=6.02*10**26; #avagadro number(kg mol-1)\n", + "rho=7860; #density(kg/m**3)\n", + "\n", + "#Calculations\n", + "a=(n*M/(rho*N))**(1/3); #lattice constant(m)\n", + "\n", + "#Result\n", + "print \"lattice constant is\",round(a*10**10,4),\"angstrom\"" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_Opo6g3L.ipynb b/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_Opo6g3L.ipynb new file mode 100644 index 00000000..e9b7b5a0 --- /dev/null +++ b/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_Opo6g3L.ipynb @@ -0,0 +1,250 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# 12: X-ray Diffraction" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 1, Page number 378" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "wavelength of X-rays is 0.0842 nm\n", + "maximum order of diffraction is 6\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "d=0.282; #lattice spacing(nm)\n", + "theta=(8+(35/60))*math.pi/180; #glancing angle(radian)\n", + "n1=1; #order\n", + "\n", + "#Calculation\n", + "lamda=2*d*math.sin(theta)/n1; #wavelength of X-rays(nm)\n", + "n=2*d/lamda; #maximum order of diffraction\n", + "\n", + "#Result\n", + "print \"wavelength of X-rays is\",round(lamda,4),\"nm\"\n", + "print \"maximum order of diffraction is\",int(n)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 2, Page number 378" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "glancing angle for 1st order is 17 degrees 24 minutes\n", + "glancing angle for 2nd order is 36 degrees 44 minutes\n", + "answers given in the book are wrong\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "d=3.209; #lattice spacing(angstrom)\n", + "lamda=1.92; #wavelength of X-rays(angstrom)\n", + "n1=1; #order\n", + "n2=2; #order \n", + "\n", + "#Calculation\n", + "theta1=math.asin(n1*lamda/(2*d))*180/math.pi; #glancing angle for 1st order(degrees)\n", + "theta1d=int(theta1); #glancing angle for 1st order(degrees) \n", + "theta1m=(theta1-theta1d)*60; #glancing angle for 1st order(minutes)\n", + "theta2=math.asin(n2*lamda/(2*d))*180/math.pi; #glancing angle for 2nd order(degrees)\n", + "theta2d=int(theta2); #glancing angle for 2nd order(degrees)\n", + "theta2m=(theta2-theta2d)*60; #glancing angle for 2nd order(minutes)\n", + "\n", + "#Result\n", + "print \"glancing angle for 1st order is\",theta1d,\"degrees\",int(theta1m),\"minutes\"\n", + "print \"glancing angle for 2nd order is\",theta2d,\"degrees\",int(theta2m),\"minutes\"\n", + "print \"answers given in the book are wrong\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 4, Page number 379" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "wavelength of X-rays is 1.268 angstrom\n", + "answer given in the book is wrong\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "d=3.05; #lattice spacing(angstrom)\n", + "theta=12*math.pi/180; #glancing angle(radian)\n", + "n=1; #order\n", + "\n", + "#Calculation\n", + "lamda=2*d*math.sin(theta)/n1; #wavelength of X-rays(angstrom)\n", + "\n", + "#Result\n", + "print \"wavelength of X-rays is\",round(lamda,3),\"angstrom\"\n", + "print \"answer given in the book is wrong\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 5, Page number 380" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "wavelength of line A is 1.268 angstrom\n", + "answer given in the book is wrong\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "thetaA=30*math.pi/180; #glancing angle(radian)\n", + "thetaB=60*math.pi/180; #glancing angle(radian)\n", + "n1=1; #order\n", + "n2=2; #order\n", + "lamdaB=0.9; #wavelength of X-rays(angstrom)\n", + "\n", + "#Calculation\n", + "lamdaA=2*lamdaB*math.sin(thetaA)/math.sin(thetaB); #wavelength of line A(angstrom)\n", + "\n", + "#Result\n", + "print \"wavelength of line A is\",round(lamda,3),\"angstrom\"\n", + "print \"answer given in the book is wrong\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 6, Page number 380" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "wavelength of X-rays is 0.7853 angstrom\n", + "glancing angle for 2nd order is 18.2 degrees\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "d=2.51; #lattice spacing(angstrom)\n", + "theta=9*math.pi/180; #glancing angle(radian)\n", + "n1=1; #order\n", + "n2=2; #order\n", + "\n", + "#Calculation\n", + "lamda=2*d*math.sin(theta)/n1; #wavelength of X-rays(angstrom)\n", + "theta=math.asin(n2*lamda/(2*d))*180/math.pi; #glancing angle for 2nd order(degrees)\n", + "\n", + "#Result\n", + "print \"wavelength of X-rays is\",round(lamda,4),\"angstrom\"\n", + "print \"glancing angle for 2nd order is\",round(theta,1),\"degrees\"" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_Pq40WOu.ipynb b/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_Pq40WOu.ipynb new file mode 100644 index 00000000..ecefb615 --- /dev/null +++ b/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_Pq40WOu.ipynb @@ -0,0 +1,210 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# 8: Alpha and Beta Decays" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 1, Page number 282" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "velocity of beta article is 0.8624 c\n", + "mass of beta particle is 1.98 m0\n", + "flux density is 0.029106 weber/m**2\n", + "answer in the book varies due to rounding off errors\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "e=1.6*10**-19; #charge(coulomb)\n", + "Ek=0.5*10**6; #kinetic energy(eV)\n", + "m0=9.11*10**-31; #mass(kg)\n", + "c=3*10**8; #velocity of light(m/s)\n", + "r=0.1; #radius(m)\n", + "\n", + "#Calculation\n", + "x=(Ek*e/(m0*c**2))+1;\n", + "y=1-(1/x)**2;\n", + "v=c*math.sqrt(y); #velocity of beta article(m/s)\n", + "m=m0/math.sqrt(1-(v/c)**2); #mass of beta particle(kg)\n", + "B=m*v/(e*r); #flux density(weber/m**2)\n", + "\n", + "#Result\n", + "print \"velocity of beta article is\",round(v/c,4),\"c\"\n", + "print \"mass of beta particle is\",round(m/m0,2),\"m0\"\n", + "print \"flux density is\",round(B,6),\"weber/m**2\"\n", + "print \"answer in the book varies due to rounding off errors\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 2, Page number 283" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "kinetic energy of alpha particle is 4.782 MeV\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "A=226; #atomic weight\n", + "Ra=226.02540; #mass of Ra\n", + "Rn=222.017571; #mass of Rn\n", + "He=4.002603; #mass of He\n", + "m=931.5; \n", + "\n", + "#Calculation\n", + "Q=(Ra-Rn-He)*m; \n", + "kalpha=(A-4)*Q/A; #kinetic energy of alpha particle(MeV)\n", + "\n", + "#Result\n", + "print \"kinetic energy of alpha particle is\",round(kalpha,3),\"MeV\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 3, Page number 283" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "maximum kinetic energy of electrons is 4.548 MeV\n", + "answer given in the book is wrong\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "Ne=22.99465; #mass of Ne\n", + "Na=22.989768; #mass of Na\n", + "m=931.5; \n", + "\n", + "#Calculation\n", + "Q=(Ne-Na)*m; #maximum kinetic energy of electrons(MeV)\n", + "\n", + "#Result\n", + "print \"maximum kinetic energy of electrons is\",round(Q,3),\"MeV\"\n", + "print \"answer given in the book is wrong\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 4, Page number 284" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Q value of 1st decay is 0.482 MeV\n", + "Q value of 2nd decay is 1.504 MeV\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "K=39.963999; #mass of K\n", + "Ca=39.962591; #mass of Ca\n", + "Ar=39.962384; #mass of Ar\n", + "me=0.000549; #mass of electron \n", + "m=931.5; \n", + "\n", + "#Calculation\n", + "Q1=(K-Ar-(2*me))*m; #Q value of 1st decay(MeV)\n", + "Q2=(K-Ar)*m; #Q value of 2nd decay(MeV)\n", + "\n", + "#Result\n", + "print \"Q value of 1st decay is\",round(Q1,3),\"MeV\"\n", + "print \"Q value of 2nd decay is\",round(Q2,3),\"MeV\"" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_QLXi0uM.ipynb b/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_QLXi0uM.ipynb new file mode 100644 index 00000000..449a8ffa --- /dev/null +++ b/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_QLXi0uM.ipynb @@ -0,0 +1,320 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# 14: Magnetism" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 1, Page number 420" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "magnetisation is 20 *10**9 A/m\n", + "flux density is 1.2818 *10**6 T\n", + "answer for flux density given in the book is wrong\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "mew0=4*math.pi*10**-7; #permeability of vacuum\n", + "H=10**12; #magnetic field intensity(A/m)\n", + "chi=20*10**-3; #susceptibility\n", + "\n", + "#Calculations\n", + "M=chi*H; #magnetisation(A/m)\n", + "B=mew0*(M+H); #flux density(T)\n", + "\n", + "#Result\n", + "print \"magnetisation is\",int(M/10**9),\"*10**9 A/m\"\n", + "print \"flux density is\",round(B/10**6,4),\"*10**6 T\"\n", + "print \"answer for flux density given in the book is wrong\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 2, Page number 420" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "magnetisation is 17725 A/m\n", + "answer for magnetisation given in the book is wrong\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "mew0=4*math.pi*10**-7; #permeability of vacuum\n", + "H=10**2; #magnetic field intensity(A/m)\n", + "B=0.0224; #flux density(T)\n", + "\n", + "#Calculations\n", + "M=(B/mew0)-H; #magnetisation(A/m)\n", + "\n", + "#Result\n", + "print \"magnetisation is\",int(M),\"A/m\"\n", + "print \"answer for magnetisation given in the book is wrong\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 3, Page number 421" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "change in magnetic moment is 5.27 *10**-29 Am**2\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "e=1.6*10**-19; #charge(coulomb)\n", + "r=5*10**-11; #radius(m)\n", + "B=3; #flux density(T)\n", + "m=9.1*10**-31; #mass(kg)\n", + "\n", + "#Calculations\n", + "mew=B*e**2*r**2/(4*m); #change in magnetic moment(Am**2)\n", + "\n", + "#Result\n", + "print \"change in magnetic moment is\",round(mew*10**29,2),\"*10**-29 Am**2\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 4, Page number 421" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "susceptibility is 0.8 *10**-4\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "T1=200; #temperature(K)\n", + "T2=300; #temperature(K)\n", + "chi1=1.2*10**-4; #susceptibility\n", + "\n", + "#Calculations\n", + "chi2=T1*chi1/T2; #susceptibility\n", + "\n", + "#Result\n", + "print \"susceptibility is\",chi2*10**4,\"*10**-4\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 5, Page number 422" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "paramagnetisation is 3.6 *10**2 A/m\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "H=10**5; #magnetic field intensity(A/m)\n", + "chi=3.6*10**-3; #susceptibility\n", + "\n", + "#Calculations\n", + "M=chi*H; #paramagnetisation(A/m)\n", + "\n", + "#Result\n", + "print \"paramagnetisation is\",M/10**2,\"*10**2 A/m\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 6, Page number 422" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "magnetic moment is 5.655 *10**-24 Am**2\n", + "saturation magnetic induction is 6.5 *10**-4 T\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "mew0=4*math.pi*10**-7; #permeability of vacuum\n", + "mewB=9.27*10**-24; \n", + "rho=8906; #density(kg/m**3)\n", + "N=6.023*10**23; #avagadro number\n", + "W=58.7; #atomic weight\n", + "\n", + "#Calculations\n", + "mewM=0.61*mewB; #magnetic moment(Am**2)\n", + "B=rho*N*mew0*mewM/W; #saturation magnetic induction(T)\n", + "\n", + "#Result\n", + "print \"magnetic moment is\",round(mewM*10**24,3),\"*10**-24 Am**2\"\n", + "print \"saturation magnetic induction is\",round(B*10**4,1),\"*10**-4 T\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 7, Page number 423" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "diamagnetic susceptibility is -8.249 *10**-8\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "mew0=4*math.pi*10**-7; #permeability of vacuum\n", + "e=1.6*10**-19; #charge(coulomb)\n", + "m=9.1*10**-31; #mass(kg)\n", + "R=0.5*10**-10; #radius(m)\n", + "N=28*10**26; #number of atoms\n", + "Z=2; #atomic number\n", + "\n", + "#Calculations\n", + "chi_dia=-mew0*Z*e**2*N*R**2/(6*m); #diamagnetic susceptibility\n", + "\n", + "#Result\n", + "print \"diamagnetic susceptibility is\",round(chi_dia*10**8,3),\"*10**-8\"" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_TdOIeIQ.ipynb b/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_TdOIeIQ.ipynb new file mode 100644 index 00000000..55a10563 --- /dev/null +++ b/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_TdOIeIQ.ipynb @@ -0,0 +1,568 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# 1: Atomic Spectra" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 1, Page number 55" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "wavelength of emitted photon is 1.281 angstrom\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "n1=3;\n", + "n2=5; #states\n", + "RH=1.0977*10**7;\n", + "\n", + "#Calculations\n", + "newbar=RH*((1/n1**2)-(1/n2**2));\n", + "lamda=10**6/newbar; #wavelength of emitted photon(angstrom)\n", + "\n", + "#Result\n", + "print \"wavelength of emitted photon is\",round(lamda,3),\"angstrom\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 2, Page number 56" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ratio of principal quantum number of two orbits is 14 / 11\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "E1=1.21;\n", + "E2=1.96; #energy of two orbits(eV)\n", + "\n", + "#Calculations\n", + "n1=math.sqrt(E2);\n", + "n2=math.sqrt(E1); #ratio of principal quantum number of two orbits\n", + "n1=n1*10;\n", + "n2=n2*10; #multiply and divide the ratio by 10\n", + "\n", + "#Result\n", + "print \"ratio of principal quantum number of two orbits is\",int(n1),\"/\",int(n2)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 3, Page number 56" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "magnetic moment of proton is 5.041 *10**-27 Am**2\n", + "answer in the book varies due to rounding off errors\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "e=1.6*10**-19; #charge(coulomb)\n", + "mp=1.672*10**-27; #mass of electron(kg)\n", + "h=6.62*10**-34; #planks constant(Js)\n", + "\n", + "#Calculations\n", + "mewp=e*h/(4*math.pi*mp); #magnetic moment of proton(Am**2) \n", + "\n", + "#Result\n", + "print \"magnetic moment of proton is\",round(mewp*10**27,3),\"*10**-27 Am**2\"\n", + "print \"answer in the book varies due to rounding off errors\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 4, Page number 56" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "specific charge of electron is 1.7604 *10**11 coulomb/kg\n", + "answer in the book varies due to rounding off errors\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "mewB=9.274*10**-24; #bohr magneton(amp m**2)\n", + "h=6.62*10**-34; #planks constant(Js)\n", + "\n", + "#Calculations\n", + "ebym=mewB*4*math.pi/h; #specific charge of electron(coulomb/kg) \n", + "\n", + "#Result\n", + "print \"specific charge of electron is\",round(ebym/10**11,4),\"*10**11 coulomb/kg\"\n", + "print \"answer in the book varies due to rounding off errors\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 5, Page number 57" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "wavelength separation is 0.3358 angstrom\n", + "answer in the book varies due to rounding off errors\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "e=1.6*10**-19; #charge(coulomb)\n", + "B=1; #flux density(Wb/m**2)\n", + "lamda=6000*10**-10; #wavelength(m)\n", + "m=9.1*10**-31; #mass(kg)\n", + "c=3*10**8; #velocity of light(m/sec)\n", + "\n", + "#Calculations\n", + "d_lamda=B*e*(lamda**2)/(4*math.pi*m*c); #wavelength separation(m)\n", + "d_lamda=2*d_lamda*10**10; #wavelength separation(angstrom)\n", + "\n", + "#Result\n", + "print \"wavelength separation is\",round(d_lamda,4),\"angstrom\"\n", + "print \"answer in the book varies due to rounding off errors\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 6, Page number 57" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "energy of electron in 1st and 2nd orbit is -13.6 eV and -3.4 eV\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "n1=1;\n", + "n2=2; #states\n", + "\n", + "#Calculations\n", + "E1=-13.6/n1**2; #energy of electron in 1st orbit(eV)\n", + "E2=-13.6/n2**2; #energy of electron in 2nd orbit(eV)\n", + "\n", + "#Result\n", + "print \"energy of electron in 1st and 2nd orbit is\",E1,\"eV and\",E2,\"eV\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 8, Page number 58" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "linear momentum is 2.107 *10**-24 kg ms-1\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "lamda=0.5*10**-10; #radius of 1st orbit(m)\n", + "h=6.62*10**-34; #planks constant(Js)\n", + "\n", + "#Calculations\n", + "L=h/(2*math.pi*lamda); #linear momentum(kg ms-1)\n", + "\n", + "#Result\n", + "print \"linear momentum is\",round(L*10**24,3),\"*10**-24 kg ms-1\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 9, Page number 58" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "state to which it is excited is 4\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "E1=-13.6; #energy of electron in 1st orbit(eV)\n", + "E2=-12.75; #energy of electron in 2nd orbit(eV)\n", + "\n", + "#Calculations\n", + "n=math.sqrt(-E1/(E2-E1)); #state to which it is excited\n", + "\n", + "#Result\n", + "print \"state to which it is excited is\",int(n)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 10, Page number 59" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "bohr magneton is 9.262 *10**-24 coulomb Js kg-1\n", + "answer in the book varies due to rounding off errors\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "e=1.6*10**-19; #charge(coulomb)\n", + "m=9.1*10**-31; #mass of electron(kg)\n", + "h=6.62*10**-34; #planks constant(Js)\n", + "\n", + "#Calculations\n", + "mewB=e*h/(4*math.pi*m); #bohr magneton(coulomb Js kg-1) \n", + "\n", + "#Result\n", + "print \"bohr magneton is\",round(mewB*10**24,3),\"*10**-24 coulomb Js kg-1\"\n", + "print \"answer in the book varies due to rounding off errors\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 11, Page number 59" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "component separation is 2.7983 *10**8 Hz\n", + "answer in the book varies due to rounding off errors\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "e=1.6*10**-19; #charge(coulomb)\n", + "m=9.1*10**-31; #mass of electron(kg)\n", + "B=0.02; #magnetic field(T)\n", + "\n", + "#Calculations\n", + "delta_new=e*B/(4*math.pi*m); #component separation(Hz)\n", + "\n", + "#Result\n", + "print \"component separation is\",round(delta_new/10**8,4),\"*10**8 Hz\"\n", + "print \"answer in the book varies due to rounding off errors\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 14, Page number 61" + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "magnetic flux density is 2.14 Tesla\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "e=1.6*10**-19; #charge(coulomb)\n", + "m=9.1*10**-31; #mass of electron(kg)\n", + "lamda=10000*10**-10; #wavelength(m)\n", + "c=3*10**8; #velocity of light(m/sec)\n", + "d_lamda=1*10**-10; #wavelength separation(m)\n", + "\n", + "#Calculations\n", + "B=d_lamda*4*math.pi*m*c/(e*lamda**2); #magnetic flux density(Tesla)\n", + "\n", + "#Result\n", + "print \"magnetic flux density is\",round(B,2),\"Tesla\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 19, Page number 66" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "separation is 0.33 angstrom\n", + "wavelength of three components is 4226 angstrom 4226.33 angstrom 4226.666 angstrom\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "e=1.6*10**-19; #charge(coulomb)\n", + "m=9.1*10**-31; #mass of electron(kg)\n", + "lamda=4226; #wavelength(angstrom)\n", + "c=3*10**8; #velocity of light(m/sec)\n", + "B=4; #magnetic field(Wb/m**2)\n", + "\n", + "#Calculations\n", + "dnew=B*e/(4*math.pi*m); \n", + "dlamda=lamda**2*dnew*10**-10/c; #separation(angstrom)\n", + "dlamda1=lamda+dlamda;\n", + "dlamda2=dlamda1+dlamda; #wavelength of three components(Hz)\n", + "\n", + "#Result\n", + "print \"separation is\",round(dlamda,2),\"angstrom\"\n", + "print \"wavelength of three components is\",lamda,\"angstrom\",round(dlamda1,2),\"angstrom\",round(dlamda2,3),\"angstrom\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 21, Page number 68" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "number of elements would be 110\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "n1=1;\n", + "n2=2; \n", + "n3=3;\n", + "n4=4;\n", + "n5=5;\n", + "\n", + "#Calculations\n", + "e1=2*n1**2; #maximum number of electrons in 1st orbit\n", + "e2=2*n2**2; #maximum number of electrons in 2nd orbit\n", + "e3=2*n3**2; #maximum number of electrons in 3rd orbit\n", + "e4=2*n4**2; #maximum number of electrons in 4th orbit\n", + "e5=2*n5**2; #maximum number of electrons in 5th orbit\n", + "e=e1+e2+e3+e4+e5; #number of elements\n", + "\n", + "#Result\n", + "print \"number of elements would be\",e" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_UiM06tF.ipynb b/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_UiM06tF.ipynb new file mode 100644 index 00000000..fd167244 --- /dev/null +++ b/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_UiM06tF.ipynb @@ -0,0 +1,304 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# 6: Schrodinger Wave Mechanics" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 8, Page number 228" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "energy levels are 38 eV 150 eV 339 eV\n", + "answer given in the book is wrong\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "m=9.1*10**-31; #mass of electron(kg)\n", + "e=1.6*10**-19; #charge(coulomb)\n", + "a=10**-10; #width(m)\n", + "h=6.62*10**-34; #planck's constant\n", + "n1=1;\n", + "n2=2;\n", + "n3=3;\n", + "\n", + "#Calculation\n", + "Ex=h**2/(8*e*m*a**2); #energy(eV)\n", + "E1=Ex*n1**2; #energy at 1st level(eV)\n", + "E2=Ex*n2**2; #energy at 2nd level(eV)\n", + "E3=Ex*n3**2; #energy at 3rd level(eV)\n", + "\n", + "#Result\n", + "print \"energy levels are\",int(round(E1)),\"eV\",int(round(E2)),\"eV\",int(round(E3)),\"eV\"\n", + "print \"answer given in the book is wrong\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 9, Page number 229" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "probability of finding the particle is 0.133\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "deltax=1*10**-10; #width\n", + "a=15*10**-10; #width(m)\n", + "\n", + "#Calculation\n", + "W=2*deltax/a; #probability of finding the particle\n", + "\n", + "#Result\n", + "print \"probability of finding the particle is\",round(W,3)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 10, Page number 229" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "probability of transmission of electron is 0.5\n", + "answer given in the book is wrong\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "E=1; #energy(eV)\n", + "V0=2; #voltage(eV)\n", + "m=9.1*10**-31; #mass of electron(kg)\n", + "e=1.6*10**-19; #charge(coulomb)\n", + "chi=1.05*10**-34; \n", + "a=2*10**-10; #potential barrier\n", + "\n", + "#Calculation\n", + "x=math.sqrt(2*m*(V0-E)*e);\n", + "y=16*E*(1-(E/V0))/V0;\n", + "T=y*math.exp(-2*a*x/chi); #probability of transmission of electron\n", + "\n", + "#Result\n", + "print \"probability of transmission of electron is\",round(T,1)\n", + "print \"answer given in the book is wrong\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 11, Page number 230" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "fraction of electrons reflected is 0.38\n", + "fraction of electrons transmitted is 0.62\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "E=0.080*10**-19; #energy(eV)\n", + "E_V0=0.016*10**-19; #voltage(eV)\n", + "\n", + "#Calculation\n", + "x=math.sqrt(E);\n", + "y=math.sqrt(E_V0);\n", + "R=(x-y)/(x+y); #fraction of electrons reflected\n", + "T=1-R; #fraction of electrons transmitted\n", + "\n", + "#Result\n", + "print \"fraction of electrons reflected is\",round(R,2)\n", + "print \"fraction of electrons transmitted is\",round(T,2)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 12, Page number 231" + ] + }, + { + "cell_type": "code", + "execution_count": 37, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "fraction of electrons transmitted is 0.4998\n", + "fraction of electrons reflected is 0.5002\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "E=0.34; #energy(eV)\n", + "E_V0=0.01; #voltage(eV)\n", + "\n", + "#Calculation\n", + "x=math.sqrt(E);\n", + "y=math.sqrt(E_V0);\n", + "T=4*x*y/(x+y)**2; #fraction of electrons transmitted \n", + "R=1-T; #fraction of electrons reflected\n", + "\n", + "#Result\n", + "print \"fraction of electrons transmitted is\",round(T,4)\n", + "print \"fraction of electrons reflected is\",round(R,4)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 13, Page number 232" + ] + }, + { + "cell_type": "code", + "execution_count": 50, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "transmission coefficient is 3.27 *10**-9\n", + "transmission coefficient in 1st case is 7.62 *10**-8\n", + "transmission coefficient in 2nd case is 1.51 *10**-15\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "e=1.6*10**-19; #charge(coulomb)\n", + "E1=1*e; #energy(J)\n", + "E2=2*e; #energy(J)\n", + "V0=5*e; #voltage(J)\n", + "m=9.1*10**-31; #mass of electron(kg)\n", + "chi=1.054*10**-34; \n", + "a1=10*10**-10; #potential barrier(m)\n", + "a2=20*10**-10; #potential barrier(m)\n", + "\n", + "#Calculation\n", + "beta1=math.sqrt(2*m*(V0-E1)/(chi**2));\n", + "y1=16*E1*((V0-E1)/(V0**2));\n", + "T1=y1*math.exp(-2*a1*beta1); #transmission coefficient\n", + "beta2=math.sqrt(2*m*(V0-E2)/(chi**2));\n", + "y2=16*E2*((V0-E2)/(V0**2));\n", + "T2=y2*math.exp(-2*a1*beta2); #transmission coefficient in 1st case\n", + "T3=y2*math.exp(-2*a2*beta2); #transmission coefficient in 2nd case\n", + "\n", + "#Result\n", + "print \"transmission coefficient is\",round(T1*10**9,2),\"*10**-9\"\n", + "print \"transmission coefficient in 1st case is\",round(T2*10**8,2),\"*10**-8\"\n", + "print \"transmission coefficient in 2nd case is\",round(T3*10**15,2),\"*10**-15\"" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_VQabJzR.ipynb b/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_VQabJzR.ipynb new file mode 100644 index 00000000..31b7323a --- /dev/null +++ b/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_VQabJzR.ipynb @@ -0,0 +1,277 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# 7: Nuclear Structure" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 1, Page number 259" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "radius of He is 2.2375 fermi\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "A1=165; #mass number\n", + "A2=4; #mass number\n", + "R1=7.731; #radius(fermi)\n", + "\n", + "#Calculation\n", + "R2=R1*(A2/A1)**(1/3); #radius of He(fermi)\n", + "\n", + "#Result\n", + "print \"radius of He is\",round(R2,4),\"fermi\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 2, Page number 259" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "average binding energy per nucleon is 7.07 MeV\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "n=1.008665; #mass of neutron(amu)\n", + "p=1.007276; #mass of proton(amu)\n", + "alpha=4.00150; #mass of alpha particle(amu)\n", + "m=931; \n", + "\n", + "#Calculation\n", + "deltam=2*(p+n)-alpha;\n", + "BE=deltam*m; #binding energy(MeV)\n", + "ABE=BE/4; #average binding energy per nucleon(MeV)\n", + "\n", + "#Result\n", + "print \"average binding energy per nucleon is\",round(ABE,2),\"MeV\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 3, Page number 260" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "binding energy of neutron is 7.25 MeV\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "n=1.008665; #mass of neutron(amu)\n", + "Li36=6.015125; #mass of Li(amu)\n", + "Li37=7.016004; #mass of Li(amu)\n", + "m=931; \n", + "\n", + "#Calculation\n", + "deltam=Li36+n-Li37; \n", + "BE=deltam*m; #binding energy of neutron(MeV)\n", + "\n", + "#Result\n", + "print \"binding energy of neutron is\",round(BE,2),\"MeV\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 4, Page number 260" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "energy released is 23.6 MeV\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "BEHe=4*7.0; #binding energy for He\n", + "BEH=2*1.1; #binding energy for H\n", + "\n", + "#Calculation\n", + "deltaE=BEHe-(2*BEH); #energy released(MeV) \n", + "\n", + "#Result\n", + "print \"energy released is\",deltaE,\"MeV\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 5, Page number 260" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "mass is 19.987 amu\n", + "answer given in the book is wrong\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "n=1.008665; #mass of neutron(amu)\n", + "p=1.007276; #mass of proton(amu)\n", + "BE=160.647; #binding energy(MeV)\n", + "m=931; \n", + "\n", + "#Calculation\n", + "Mx=10*(p+n)-(BE/m); #mass(amu)\n", + "\n", + "#Result\n", + "print \"mass is\",round(Mx,3),\"amu\"\n", + "print \"answer given in the book is wrong\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 6, Page number 261" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "binding energy of neutron is 11.471 MeV\n", + "answer given in the book varies due to rounding off errors\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "n=1.008665; #mass of neutron(amu)\n", + "Ca41=40.962278; #mass of Ca(amu)\n", + "Ca42=41.958622; #mass of Ca(amu)\n", + "m=931; \n", + "\n", + "#Calculation\n", + "deltam=Ca41+n-Ca42; \n", + "BE=deltam*m; #binding energy of neutron(MeV)\n", + "\n", + "#Result\n", + "print \"binding energy of neutron is\",round(BE,3),\"MeV\"\n", + "print \"answer given in the book varies due to rounding off errors\"" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_XKPPUxj.ipynb b/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_XKPPUxj.ipynb new file mode 100644 index 00000000..a4871749 --- /dev/null +++ b/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_XKPPUxj.ipynb @@ -0,0 +1,681 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# 4: Matter Waves" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 1, Page number 158" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "de-Broglie wavelength of proton is 1 angstrom\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "m=1.67*10**-27; #mass of proton(kg)\n", + "h=6.625*10**-34; #planks constant(Js)\n", + "v=3967; #velocity of proton(m/s)\n", + "\n", + "#Calculations\n", + "lamda=h/(m*v); #de-Broglie wavelength of proton(m)\n", + "\n", + "#Result\n", + "print \"de-Broglie wavelength of proton is\",int(lamda*10**10),\"angstrom\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 2, Page number 158" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "kinetic energy of electron is 6 eV\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "m=9.11*10**-31; #mass of electron(kg)\n", + "h=6.625*10**-34; #planks constant(Js)\n", + "lamda=5*10**-10; #de-Broglie wavelength(m)\n", + "e=1.6*10**-19; #charge(coulomb)\n", + "\n", + "#Calculations\n", + "E=h**2/(2*m*lamda**2*e); #kinetic energy of electron(eV)\n", + "\n", + "#Result\n", + "print \"kinetic energy of electron is\",int(E),\"eV\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 3, Page number 158" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "de-Broglie wavelength of proton is 3.97 *10**-6 angstrom\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "c=3*10**8; #velocity of light(m/sec)\n", + "m=1.67*10**-27; #mass of proton(kg)\n", + "h=6.625*10**-34; #planks constant(Js)\n", + "\n", + "#Calculations\n", + "v=c/30; #velocity of proton(m/sec)\n", + "lamda=h/(m*v); #de-Broglie wavelength of proton(m)\n", + "\n", + "#Result\n", + "print \"de-Broglie wavelength of proton is\",round(lamda*10**14,2),\"*10**-6 angstrom\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 4, Page number 159" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "de-Broglie wavelength of electron is 1 angstrom\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "V=150; #potential difference(V)\n", + "\n", + "#Calculations\n", + "lamda=12.26/math.sqrt(V); #de-Broglie wavelength of electron(angstrom)\n", + "\n", + "#Result\n", + "print \"de-Broglie wavelength of electron is\",int(lamda),\"angstrom\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 5, Page number 159" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "de-Broglie wavelength is 1.23 angstrom\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "V=100; #voltage(eV) \n", + "m=9.1*10**-31; #mass of proton(kg)\n", + "h=6.625*10**-34; #planks constant(Js)\n", + "e=1.6*10**-19; #charge(coulomb)\n", + "\n", + "#Calculations\n", + "lamda=h*10**10/math.sqrt(2*m*e*V); #de-Broglie wavelength(angstrom)\n", + "\n", + "#Result\n", + "print \"de-Broglie wavelength is\",round(lamda,2),\"angstrom\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 6, Page number 159" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "de-Broglie wavelength of neutron is 0.99 angstrom\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "m=1.67*10**-27; #mass of proton(kg)\n", + "h=6.625*10**-34; #planks constant(Js)\n", + "v=4000; #velocity of proton(m/s)\n", + "\n", + "#Calculations\n", + "lamda=h*10**10/(m*v); #de-Broglie wavelength of neutron(angstrom)\n", + "\n", + "#Result\n", + "print \"de-Broglie wavelength of neutron is\",round(lamda,2),\"angstrom\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 7, Page number 160" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ratio of kinetic energies of electron and proton is 1833\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "mp=1.67*10**-27; #mass of proton(kg)\n", + "me=9.11*10**-31; #mass of electron(kg)\n", + "\n", + "#Calculations\n", + "r=mp/me; #ratio of kinetic energies of electron and proton\n", + "\n", + "#Result\n", + "print \"ratio of kinetic energies of electron and proton is\",int(r)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 8, Page number 160" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ratio of wavelengths is 32\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "m=9.1*10**-31; #mass of proton(kg)\n", + "e=1.6*10**-19; #charge(coulomb)\n", + "c=3*10**8; #velocity of light(m/sec)\n", + "E=1000; #energy(eV)\n", + "\n", + "#Calculations\n", + "r=math.sqrt(2*m/(e*E))*c; #ratio of wavelengths\n", + "\n", + "#Result\n", + "print \"ratio of wavelengths is\",int(round(r))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 9, Page number 160" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "wavelength of electron is 0.289 angstrom\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "m=9.1*10**-31; #mass of electron(kg)\n", + "c=3*10**8; #velocity of light(m/sec)\n", + "h=6.6*10**-34; #planks constant(Js)\n", + "lamda=1.54*10**-10; #wavelength of X-ray(m)\n", + "wf=1*10**-15; #work function(J)\n", + "\n", + "#Calculations\n", + "E=h*c/lamda; #energy of X-ray(J)\n", + "Ee=E-wf; #energy of electron emitted(J)\n", + "lamda=h/math.sqrt(2*m*Ee); #wavelength of electron(m)\n", + "\n", + "#Result\n", + "print \"wavelength of electron is\",round(lamda*10**10,3),\"angstrom\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 10, Page number 161" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "de broglie wavelength of proton is 1.537 angstrom\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "m=1.67*10**-27; #mass of proton(kg)\n", + "h=6.6*10**-34; #planks constant(Js)\n", + "T=400; #temperature(K)\n", + "k=1.38*10**-23; #boltzmann constant\n", + "\n", + "#Calculations\n", + "lamda=h*10**10/math.sqrt(2*m*k*T); #de broglie wavelength of proton(angstrom)\n", + "\n", + "#Result\n", + "print \"de broglie wavelength of proton is\",round(lamda,3),\"angstrom\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 11, Page number 162" + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "rest energy of electron is 8.19e-14 J\n", + "energy of proton is 8.19e-11 J\n", + "velocity of proton is 312902460.506 m/s\n", + "wavelength of electron is 1.27 *10**-5 angstrom\n", + "answers given in the book are wrong\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "m=1.673*10**-27; #mass of proton(kg)\n", + "m0=9.1*10**-31; #mass of electron(kg)\n", + "c=3*10**8; #velocity of light(m/sec)\n", + "h=6.63*10**-34; #planks constant(Js)\n", + "ke=1000; #kinetic energy\n", + "\n", + "#Calculations\n", + "re=m0*c**2; #rest energy of electron(J)\n", + "Ep=ke*re; #energy of proton(J)\n", + "v=math.sqrt(2*Ep/m); #velocity of proton(m/s)\n", + "lamda=h*10**10/(m*v); #debroglie wavelength of proton(angstrom)\n", + "\n", + "#Result\n", + "print \"rest energy of electron is\",re,\"J\"\n", + "print \"energy of proton is\",Ep,\"J\"\n", + "print \"velocity of proton is\",v,\"m/s\"\n", + "print \"wavelength of electron is\",round(lamda*10**5,2),\"*10**-5 angstrom\"\n", + "print \"answers given in the book are wrong\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 12, Page number 162" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "velocity of electron is 4.55 *10**7 m/s\n", + "kinetic energy is 5887 eV\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "m=9.1*10**-31; #mass of electron(kg)\n", + "h=6.625*10**-34; #planks constant(Js)\n", + "lamda=0.16*10**-10; #debroglie wavelength of electron(m)\n", + "e=1.6*10**-19; #charge(coulomb)\n", + "\n", + "#Calculations\n", + "v=h/(lamda*m); #velocity of electron(m/s)\n", + "KE=m*v**2/(2*e); #kinetic energy(eV)\n", + "\n", + "#Result\n", + "print \"velocity of electron is\",round(v*10**-7,2),\"*10**7 m/s\"\n", + "print \"kinetic energy is\",int(KE),\"eV\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 13, Page number 163" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "interplanar spacing of crystal is 1.78 angstrom\n", + "answer given in the book is wrong\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "m=1.67*10**-27; #mass of proton(kg)\n", + "h=6.62*10**-34; #planks constant(Js)\n", + "T=300; #temperature(K)\n", + "k=1.38*10**-23; #boltzmann constant\n", + "\n", + "#Calculations\n", + "d=h*10**10/math.sqrt(2*m*k*T); #interplanar spacing of crystal(angstrom)\n", + "\n", + "#Result\n", + "print \"interplanar spacing of crystal is\",round(d,2),\"angstrom\"\n", + "print \"answer given in the book is wrong\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 14, Page number 164" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "potential is 605.16 volts\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "lamda=0.5; #wavelength(angstrom)\n", + "\n", + "#Calculations\n", + "V=(12.3/lamda)**2; #potential(volts)\n", + "\n", + "#Result\n", + "print \"potential is\",V,\"volts\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 15, Page number 164" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "energy of gama ray photon is 19.89 *10**-16 J\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "lamda=1*10**-10; #wavelength(m)\n", + "h=6.63*10**-34; #planks constant(Js)\n", + "c=3*10**8; #velocity of light(m/sec)\n", + "\n", + "#Calculations\n", + "p=h/lamda; #momentum(J-sec/m)\n", + "E=p*c; #energy of gama ray photon(J)\n", + "\n", + "#Result\n", + "print \"energy of gama ray photon is\",E*10**16,\"*10**-16 J\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 16, Page number 164" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "velocity of electron is 2.2 *10**6 m/sec\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "h=6.6*10**-34; #planks constant(Js)\n", + "m=9*10**-31; #mass of electron(kg)\n", + "r=0.53*10**-10; #radius of orbit(m)\n", + "\n", + "#Calculations\n", + "v=h/(2*math.pi*r*m); #velocity of electron(m/sec)\n", + "\n", + "#Result\n", + "print \"velocity of electron is\",round(v*10**-6,1),\"*10**6 m/sec\"" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_dfFlLnm.ipynb b/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_dfFlLnm.ipynb new file mode 100644 index 00000000..1d50ed48 --- /dev/null +++ b/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_dfFlLnm.ipynb @@ -0,0 +1,384 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# 11: Crystal Structure" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 1, Page number 357" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "miller indices of plane are ( 6 4 3 )\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "a=1/2;\n", + "b=1/3;\n", + "c=1/4; #intercepts along the three axes\n", + "\n", + "#Calculations\n", + "def lcm(x, y):\n", + " if x > y:\n", + " greater = x\n", + " else:\n", + " greater = y\n", + " while(True):\n", + " if((greater % x == 0) and (greater % y == 0)):\n", + " lcm = greater\n", + " break\n", + " greater += 1\n", + " \n", + " return lcm\n", + "\n", + "z=lcm(1/a,1/b);\n", + "lcm=lcm(z,1/c);\n", + "h=a*lcm;\n", + "k=b*lcm;\n", + "l=c*lcm; #miller indices of plane\n", + "\n", + "#Result\n", + "print \"miller indices of plane are (\",int(h),int(k),int(l),\")\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 2, Page number 357" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "miller indices of plane are ( 3 2 0 )\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "a=1/2;\n", + "b=1/3;\n", + "x=float(\"inf\");\n", + "c=1/x; #intercepts along the three axes\n", + "\n", + "#Calculations\n", + "def lcm(x, y):\n", + " if x > y:\n", + " greater = x\n", + " else:\n", + " greater = y\n", + " while(True):\n", + " if((greater % x == 0) and (greater % y == 0)):\n", + " lcm = greater\n", + " break\n", + " greater += 1\n", + " \n", + " return lcm\n", + "\n", + "lcm=lcm(1/a,1/b);\n", + "h=a*lcm;\n", + "k=b*lcm;\n", + "l=c*lcm; #miller indices of plane\n", + "\n", + "#Result\n", + "print \"miller indices of plane are (\",int(h),int(k),int(l),\")\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 3, Page number 358" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "miller indices of plane are ( 6 3 2 )\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "a=1/1;\n", + "b=1/2;\n", + "c=1/3; #intercepts along the three axes\n", + "\n", + "#Calculations\n", + "def lcm(x, y):\n", + " if x > y:\n", + " greater = x\n", + " else:\n", + " greater = y\n", + " while(True):\n", + " if((greater % x == 0) and (greater % y == 0)):\n", + " lcm = greater\n", + " break\n", + " greater += 1\n", + " \n", + " return lcm\n", + "\n", + "z=lcm(1/a,1/b);\n", + "lcm=lcm(z,1/c);\n", + "h=a*lcm;\n", + "k=b*lcm;\n", + "l=c*lcm; #miller indices of plane\n", + "\n", + "#Result\n", + "print \"miller indices of plane are (\",int(h),int(k),int(l),\")\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 4, Page number 359" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "corresponding intercept on Y-axis and Z-axis are 0.8 angstrom and 0.65 angstrom\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "a=1.1;\n", + "b=1.2;\n", + "c=1.3; #intercepts along the three axes(angstrom)\n", + "h=2;\n", + "k=3;\n", + "l=4; #miller indices of plane\n", + "\n", + "#Calculations\n", + "l1=a*h/h;\n", + "l2=b*h/k; #corresponding intercept on Y-axis(angstrom)\n", + "l3=c*h/l; #corresponding intercept on Z-axis(angstrom)\n", + "\n", + "#Result\n", + "print \"corresponding intercept on Y-axis and Z-axis are\",l2,\"angstrom and\",l3,\"angstrom\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 5, Page number 360" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "miller indices of plane are ( 6 -2 3 )\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "a=1/1;\n", + "b=-1/3;\n", + "c=1/2; #intercepts along the three axes\n", + "\n", + "#Calculations\n", + "def lcm(x, y):\n", + " if x > y:\n", + " greater = x\n", + " else:\n", + " greater = y\n", + " while(True):\n", + " if((greater % x == 0) and (greater % y == 0)):\n", + " lcm = greater\n", + " break\n", + " greater += 1\n", + " \n", + " return lcm\n", + "\n", + "z=lcm(1/a,1/b);\n", + "lcm=lcm(z,1/c);\n", + "h=a*lcm;\n", + "k=b*lcm;\n", + "l=c*lcm; #miller indices of plane\n", + "\n", + "#Result\n", + "print \"miller indices of plane are (\",int(h),int(k),int(l),\")\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 6, Page number 360" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "lattice constant is 3.61 angstrom\n", + "distance between two nearest copper atoms is 2.55 angstrom\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "n=4; #number of molecules per unit cell\n", + "M=63.5; #molecular weight\n", + "N=6.02*10**26; #avagadro number(kg mol-1)\n", + "rho=8.96*10**3; #density(kg/m**3)\n", + "\n", + "#Calculations\n", + "a=(n*M/(rho*N))**(1/3); #lattice constant(m)\n", + "a=round(a*10**10,2); #lattice constant(angstrom) \n", + "d=a/math.sqrt(2); #distance between two nearest copper atoms(angstrom)\n", + "\n", + "#Result\n", + "print \"lattice constant is\",a,\"angstrom\"\n", + "print \"distance between two nearest copper atoms is\",round(d,2),\"angstrom\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 7, Page number 361" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "lattice constant is 2.8687 angstrom\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "n=2; #number of molecules per unit cell\n", + "M=55.85; #molecular weight\n", + "N=6.02*10**26; #avagadro number(kg mol-1)\n", + "rho=7860; #density(kg/m**3)\n", + "\n", + "#Calculations\n", + "a=(n*M/(rho*N))**(1/3); #lattice constant(m)\n", + "\n", + "#Result\n", + "print \"lattice constant is\",round(a*10**10,4),\"angstrom\"" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_fegIkl6.ipynb b/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_fegIkl6.ipynb new file mode 100644 index 00000000..ede08994 --- /dev/null +++ b/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_fegIkl6.ipynb @@ -0,0 +1,588 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# 2: Molecular Spectra" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 2, Page number 97" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "raman shift is 219.03 cm-1\n", + "answer given in the book is wrong\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "lamda_sample=4358; #wavelength(angstrom)\n", + "lamda_raman=4400; #wavelength(angstrom)\n", + "\n", + "#Calculations\n", + "delta_new=(10**8/lamda_sample)-(10**8/lamda_raman); #raman shift(cm-1)\n", + "\n", + "#Result\n", + "print \"raman shift is\",round(delta_new,2),\"cm-1\"\n", + "print \"answer given in the book is wrong\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 3, Page number 98" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "energy of diatomic molecule is 2.22 *10**-68 J\n", + "answer given in the book is wrong\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "h=6.62*10**-34; #planck's constant\n", + "\n", + "#Calculations\n", + "E=h**2/(2*math.pi**2); #energy of diatomic molecule(J)\n", + "\n", + "#Result\n", + "print \"energy of diatomic molecule is\",round(E*10**68,2),\"*10**-68 J\"\n", + "print \"answer given in the book is wrong\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 4, Page number 98" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "raman shift is 0.02 *10**6 m-1\n", + "wavelength of antistokes line 4950.5 angstrom\n", + "answer for wavelength given in the book is wrong\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "lamda0=5000*10**-10; #wavelength(m)\n", + "lamda=5050.5*10**-10; #wavelength(m)\n", + "\n", + "#Calculations\n", + "new0=1/lamda0; #frequency(m-1)\n", + "new=1/lamda; #frequency(m-1)\n", + "delta_new=new0-new; #raman shift(m-1)\n", + "new_as=delta_new+new0; #frequency of anti-stokes line(m-1)\n", + "lamdaas=1*10**10/new_as; #wavelength of anti-stokes line(angstrom)\n", + "\n", + "#Result\n", + "print \"raman shift is\",round(delta_new*10**-6,2),\"*10**6 m-1\"\n", + "print \"wavelength of antistokes line\",round(lamdaas,2),\"angstrom\"\n", + "print \"answer for wavelength given in the book is wrong\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 5, Page number 99" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "energy required is 60 eV\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "k=4.8*10**2; #force constant(N/m)\n", + "x=2*10**-10; #inter nuclear distance(m)\n", + "e=1.6*10**-19; #charge(coulomb)\n", + "\n", + "#Calculations\n", + "E=k*x**2/(2*e); #energy required(eV)\n", + "\n", + "#Result\n", + "print \"energy required is\",int(E),\"eV\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 6, Page number 99" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "frequency of vibration is 2.04 *10**13 sec-1\n", + "spacing between energy levels is 8.447 *10**-2 eV\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "k=187; #force constant(N/m)\n", + "m=1.14*10**-26; #reduced mass(kg)\n", + "h=6.63*10**-34; #planck's constant\n", + "e=1.6*10**-19; #charge(coulomb)\n", + "\n", + "#Calculations\n", + "new=math.sqrt(k/m)/(2*math.pi); #frequency of vibration(sec-1)\n", + "delta_E=h*new; #spacing between energy levels(J)\n", + "delta_E=delta_E/e; #spacing between energy levels(eV)\n", + "\n", + "#Result\n", + "print \"frequency of vibration is\",round(new*10**-13,2),\"*10**13 sec-1\"\n", + "print \"spacing between energy levels is\",round(delta_E*10**2,3),\"*10**-2 eV\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 7, Page number 100" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "internuclear distance is 1.42 angstrom\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "B=8.5; #seperation(cm-1)\n", + "h=6.62*10**-27; #planck's constant\n", + "c=3*10**10; #velocity of light(cm/sec)\n", + "N=6.023*10**23; #avagadro number\n", + "m1=1;\n", + "m2=79; \n", + "\n", + "#Calculations\n", + "I=h/(8*math.pi**2*B*c); #moment inertia of molecule(gm cm**2)\n", + "m=m1*m2/(N*(m1+m2)); #reduced mass(gm)\n", + "r=10**8*math.sqrt(I/m); #internuclear distance(angstrom)\n", + "\n", + "#Result\n", + "print \"internuclear distance is\",round(r,2),\"angstrom\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 8, Page number 100" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "vibrational frequency of sample is 1974 cm-1\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "lamda1=4358.3; #wavelength(angstrom)\n", + "lamda2=4768.5; #wavelength(angstrom)\n", + "\n", + "#Calculations\n", + "delta_new=(10**8/lamda1)-(10**8/lamda2); #vibrational frequency of sample(cm-1)\n", + "\n", + "#Result\n", + "print \"vibrational frequency of sample is\",int(round(delta_new)),\"cm-1\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 9, Page number 101" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "frequqncy of OD stretching vibration is 2401 cm-1\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "MO=16;\n", + "MD=2;\n", + "MH=1;\n", + "new=3300; #frequency(cm-1)\n", + "\n", + "#Calculations\n", + "mew_OD=MO*MD/(MO+MD); \n", + "mew_OH=MO*MH/(MO+MH);\n", + "new1=math.sqrt(mew_OD/mew_OH);\n", + "new_OD=new/new1; #frequqncy of OD stretching vibration(cm-1)\n", + "\n", + "#Result\n", + "print \"frequqncy of OD stretching vibration is\",int(new_OD),\"cm-1\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 11, Page number 102" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "raman shift of 4400 line is 219.03 cm-1\n", + "raman shift of 4419 line is 316.8 cm-1\n", + "raman shift of 4447 line is 459.2 cm-1\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "lamda0=4358; #wavelength(angstrom)\n", + "lamda1=4400; #wavelength(angstrom)\n", + "lamda2=4419; #wavelength(angstrom)\n", + "lamda3=4447; #wavelength(angstrom)\n", + "\n", + "#Calculations\n", + "new0bar=10**8/lamda0; #wave number of exciting line(cm-1)\n", + "rs1=(10**8/lamda0)-(10**8/lamda1); #raman shift of 4400 line(cm-1)\n", + "rs2=(10**8/lamda0)-(10**8/lamda2); #raman shift of 4419 line(cm-1)\n", + "rs3=(10**8/lamda0)-(10**8/lamda3); #raman shift of 4447 line(cm-1)\n", + "\n", + "#Result\n", + "print \"raman shift of 4400 line is\",round(rs1,2),\"cm-1\"\n", + "print \"raman shift of 4419 line is\",round(rs2,1),\"cm-1\"\n", + "print \"raman shift of 4447 line is\",round(rs3,1),\"cm-1\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 12, Page number 102" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "corresponding wavelength is 32 *10**-4 cm\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "new_bar=20.68; #transition(cm-1)\n", + "J=14;\n", + "\n", + "#Calculations\n", + "B=new_bar/2; \n", + "new=2*B*(J+1); #frequency(cm-1)\n", + "lamda=1/new; #corresponding wavelength(cm) \n", + "\n", + "#Result\n", + "print \"corresponding wavelength is\",int(lamda*10**4),\"*10**-4 cm\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 13, Page number 103" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "moment of inertia of molecule is 1.4 *10**-42 gm cm**2\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "twoB=4000; #seperation observed from the series(cm-1)\n", + "h=6.62*10**-27; #planck's constant\n", + "c=3*10**10; #velocity of light(cm/sec)\n", + "\n", + "#Calculations\n", + "B=twoB/2;\n", + "I=h/(8*math.pi**2*B*c); #moment of inertia of molecule(gm cm**2)\n", + "\n", + "#Result\n", + "print \"moment of inertia of molecule is\",round(I*10**42,1),\"*10**-42 gm cm**2\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 14, Page number 104" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "corresponding wavelengths are 5648 angstrom 5725 angstrom 5775 angstrom 5836 angstrom 5983 angstrom 6558 angstrom\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "lamda=5461*10**-8; #wavelength(cm)\n", + "new1=608;\n", + "new2=846;\n", + "new3=995;\n", + "new4=1178;\n", + "new5=1599; \n", + "new6=3064; #raman shift(cm-1)\n", + "\n", + "#Calculations\n", + "newbar=1/lamda; #wave number(cm-1)\n", + "new11=newbar-new1;\n", + "new22=newbar-new2;\n", + "new33=newbar-new3;\n", + "new44=newbar-new4;\n", + "new55=newbar-new5;\n", + "new66=newbar-new6;\n", + "lamda1=10**8/new11;\n", + "lamda2=10**8/new22;\n", + "lamda3=10**8/new33;\n", + "lamda4=10**8/new44;\n", + "lamda5=10**8/new55;\n", + "lamda6=10**8/new66; #corresponding wavelength(angstrom)\n", + "\n", + "#Result\n", + "print \"corresponding wavelengths are\",int(lamda1),\"angstrom\",int(lamda2),\"angstrom\",int(round(lamda3)),\"angstrom\",int(lamda4),\"angstrom\",int(lamda5),\"angstrom\",int(lamda6),\"angstrom\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 15, Page number 105" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "force constant is 115 N/m\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "h=6.63*10**-34; #planck's constant(J s)\n", + "e=1.602*10**-19; #charge(coulomb) \n", + "mew=1.14*10**-26; #reduced mass(kg)\n", + "deltaE=6.63*10**-2*e; #energy(J)\n", + "\n", + "#Calculations\n", + "new=deltaE/h; #frequency(sec-1)\n", + "k=4*math.pi**2*new**2*mew; #force constant(N/m)\n", + "\n", + "#Result\n", + "print \"force constant is\",int(k),\"N/m\"" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_g1GxlUN.ipynb b/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_g1GxlUN.ipynb new file mode 100644 index 00000000..ecefb615 --- /dev/null +++ b/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_g1GxlUN.ipynb @@ -0,0 +1,210 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# 8: Alpha and Beta Decays" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 1, Page number 282" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "velocity of beta article is 0.8624 c\n", + "mass of beta particle is 1.98 m0\n", + "flux density is 0.029106 weber/m**2\n", + "answer in the book varies due to rounding off errors\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "e=1.6*10**-19; #charge(coulomb)\n", + "Ek=0.5*10**6; #kinetic energy(eV)\n", + "m0=9.11*10**-31; #mass(kg)\n", + "c=3*10**8; #velocity of light(m/s)\n", + "r=0.1; #radius(m)\n", + "\n", + "#Calculation\n", + "x=(Ek*e/(m0*c**2))+1;\n", + "y=1-(1/x)**2;\n", + "v=c*math.sqrt(y); #velocity of beta article(m/s)\n", + "m=m0/math.sqrt(1-(v/c)**2); #mass of beta particle(kg)\n", + "B=m*v/(e*r); #flux density(weber/m**2)\n", + "\n", + "#Result\n", + "print \"velocity of beta article is\",round(v/c,4),\"c\"\n", + "print \"mass of beta particle is\",round(m/m0,2),\"m0\"\n", + "print \"flux density is\",round(B,6),\"weber/m**2\"\n", + "print \"answer in the book varies due to rounding off errors\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 2, Page number 283" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "kinetic energy of alpha particle is 4.782 MeV\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "A=226; #atomic weight\n", + "Ra=226.02540; #mass of Ra\n", + "Rn=222.017571; #mass of Rn\n", + "He=4.002603; #mass of He\n", + "m=931.5; \n", + "\n", + "#Calculation\n", + "Q=(Ra-Rn-He)*m; \n", + "kalpha=(A-4)*Q/A; #kinetic energy of alpha particle(MeV)\n", + "\n", + "#Result\n", + "print \"kinetic energy of alpha particle is\",round(kalpha,3),\"MeV\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 3, Page number 283" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "maximum kinetic energy of electrons is 4.548 MeV\n", + "answer given in the book is wrong\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "Ne=22.99465; #mass of Ne\n", + "Na=22.989768; #mass of Na\n", + "m=931.5; \n", + "\n", + "#Calculation\n", + "Q=(Ne-Na)*m; #maximum kinetic energy of electrons(MeV)\n", + "\n", + "#Result\n", + "print \"maximum kinetic energy of electrons is\",round(Q,3),\"MeV\"\n", + "print \"answer given in the book is wrong\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 4, Page number 284" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Q value of 1st decay is 0.482 MeV\n", + "Q value of 2nd decay is 1.504 MeV\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "K=39.963999; #mass of K\n", + "Ca=39.962591; #mass of Ca\n", + "Ar=39.962384; #mass of Ar\n", + "me=0.000549; #mass of electron \n", + "m=931.5; \n", + "\n", + "#Calculation\n", + "Q1=(K-Ar-(2*me))*m; #Q value of 1st decay(MeV)\n", + "Q2=(K-Ar)*m; #Q value of 2nd decay(MeV)\n", + "\n", + "#Result\n", + "print \"Q value of 1st decay is\",round(Q1,3),\"MeV\"\n", + "print \"Q value of 2nd decay is\",round(Q2,3),\"MeV\"" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_gGvuusH.ipynb b/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_gGvuusH.ipynb new file mode 100644 index 00000000..55a10563 --- /dev/null +++ b/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_gGvuusH.ipynb @@ -0,0 +1,568 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# 1: Atomic Spectra" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 1, Page number 55" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "wavelength of emitted photon is 1.281 angstrom\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "n1=3;\n", + "n2=5; #states\n", + "RH=1.0977*10**7;\n", + "\n", + "#Calculations\n", + "newbar=RH*((1/n1**2)-(1/n2**2));\n", + "lamda=10**6/newbar; #wavelength of emitted photon(angstrom)\n", + "\n", + "#Result\n", + "print \"wavelength of emitted photon is\",round(lamda,3),\"angstrom\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 2, Page number 56" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ratio of principal quantum number of two orbits is 14 / 11\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "E1=1.21;\n", + "E2=1.96; #energy of two orbits(eV)\n", + "\n", + "#Calculations\n", + "n1=math.sqrt(E2);\n", + "n2=math.sqrt(E1); #ratio of principal quantum number of two orbits\n", + "n1=n1*10;\n", + "n2=n2*10; #multiply and divide the ratio by 10\n", + "\n", + "#Result\n", + "print \"ratio of principal quantum number of two orbits is\",int(n1),\"/\",int(n2)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 3, Page number 56" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "magnetic moment of proton is 5.041 *10**-27 Am**2\n", + "answer in the book varies due to rounding off errors\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "e=1.6*10**-19; #charge(coulomb)\n", + "mp=1.672*10**-27; #mass of electron(kg)\n", + "h=6.62*10**-34; #planks constant(Js)\n", + "\n", + "#Calculations\n", + "mewp=e*h/(4*math.pi*mp); #magnetic moment of proton(Am**2) \n", + "\n", + "#Result\n", + "print \"magnetic moment of proton is\",round(mewp*10**27,3),\"*10**-27 Am**2\"\n", + "print \"answer in the book varies due to rounding off errors\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 4, Page number 56" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "specific charge of electron is 1.7604 *10**11 coulomb/kg\n", + "answer in the book varies due to rounding off errors\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "mewB=9.274*10**-24; #bohr magneton(amp m**2)\n", + "h=6.62*10**-34; #planks constant(Js)\n", + "\n", + "#Calculations\n", + "ebym=mewB*4*math.pi/h; #specific charge of electron(coulomb/kg) \n", + "\n", + "#Result\n", + "print \"specific charge of electron is\",round(ebym/10**11,4),\"*10**11 coulomb/kg\"\n", + "print \"answer in the book varies due to rounding off errors\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 5, Page number 57" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "wavelength separation is 0.3358 angstrom\n", + "answer in the book varies due to rounding off errors\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "e=1.6*10**-19; #charge(coulomb)\n", + "B=1; #flux density(Wb/m**2)\n", + "lamda=6000*10**-10; #wavelength(m)\n", + "m=9.1*10**-31; #mass(kg)\n", + "c=3*10**8; #velocity of light(m/sec)\n", + "\n", + "#Calculations\n", + "d_lamda=B*e*(lamda**2)/(4*math.pi*m*c); #wavelength separation(m)\n", + "d_lamda=2*d_lamda*10**10; #wavelength separation(angstrom)\n", + "\n", + "#Result\n", + "print \"wavelength separation is\",round(d_lamda,4),\"angstrom\"\n", + "print \"answer in the book varies due to rounding off errors\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 6, Page number 57" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "energy of electron in 1st and 2nd orbit is -13.6 eV and -3.4 eV\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "n1=1;\n", + "n2=2; #states\n", + "\n", + "#Calculations\n", + "E1=-13.6/n1**2; #energy of electron in 1st orbit(eV)\n", + "E2=-13.6/n2**2; #energy of electron in 2nd orbit(eV)\n", + "\n", + "#Result\n", + "print \"energy of electron in 1st and 2nd orbit is\",E1,\"eV and\",E2,\"eV\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 8, Page number 58" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "linear momentum is 2.107 *10**-24 kg ms-1\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "lamda=0.5*10**-10; #radius of 1st orbit(m)\n", + "h=6.62*10**-34; #planks constant(Js)\n", + "\n", + "#Calculations\n", + "L=h/(2*math.pi*lamda); #linear momentum(kg ms-1)\n", + "\n", + "#Result\n", + "print \"linear momentum is\",round(L*10**24,3),\"*10**-24 kg ms-1\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 9, Page number 58" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "state to which it is excited is 4\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "E1=-13.6; #energy of electron in 1st orbit(eV)\n", + "E2=-12.75; #energy of electron in 2nd orbit(eV)\n", + "\n", + "#Calculations\n", + "n=math.sqrt(-E1/(E2-E1)); #state to which it is excited\n", + "\n", + "#Result\n", + "print \"state to which it is excited is\",int(n)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 10, Page number 59" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "bohr magneton is 9.262 *10**-24 coulomb Js kg-1\n", + "answer in the book varies due to rounding off errors\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "e=1.6*10**-19; #charge(coulomb)\n", + "m=9.1*10**-31; #mass of electron(kg)\n", + "h=6.62*10**-34; #planks constant(Js)\n", + "\n", + "#Calculations\n", + "mewB=e*h/(4*math.pi*m); #bohr magneton(coulomb Js kg-1) \n", + "\n", + "#Result\n", + "print \"bohr magneton is\",round(mewB*10**24,3),\"*10**-24 coulomb Js kg-1\"\n", + "print \"answer in the book varies due to rounding off errors\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 11, Page number 59" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "component separation is 2.7983 *10**8 Hz\n", + "answer in the book varies due to rounding off errors\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "e=1.6*10**-19; #charge(coulomb)\n", + "m=9.1*10**-31; #mass of electron(kg)\n", + "B=0.02; #magnetic field(T)\n", + "\n", + "#Calculations\n", + "delta_new=e*B/(4*math.pi*m); #component separation(Hz)\n", + "\n", + "#Result\n", + "print \"component separation is\",round(delta_new/10**8,4),\"*10**8 Hz\"\n", + "print \"answer in the book varies due to rounding off errors\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 14, Page number 61" + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "magnetic flux density is 2.14 Tesla\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "e=1.6*10**-19; #charge(coulomb)\n", + "m=9.1*10**-31; #mass of electron(kg)\n", + "lamda=10000*10**-10; #wavelength(m)\n", + "c=3*10**8; #velocity of light(m/sec)\n", + "d_lamda=1*10**-10; #wavelength separation(m)\n", + "\n", + "#Calculations\n", + "B=d_lamda*4*math.pi*m*c/(e*lamda**2); #magnetic flux density(Tesla)\n", + "\n", + "#Result\n", + "print \"magnetic flux density is\",round(B,2),\"Tesla\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 19, Page number 66" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "separation is 0.33 angstrom\n", + "wavelength of three components is 4226 angstrom 4226.33 angstrom 4226.666 angstrom\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "e=1.6*10**-19; #charge(coulomb)\n", + "m=9.1*10**-31; #mass of electron(kg)\n", + "lamda=4226; #wavelength(angstrom)\n", + "c=3*10**8; #velocity of light(m/sec)\n", + "B=4; #magnetic field(Wb/m**2)\n", + "\n", + "#Calculations\n", + "dnew=B*e/(4*math.pi*m); \n", + "dlamda=lamda**2*dnew*10**-10/c; #separation(angstrom)\n", + "dlamda1=lamda+dlamda;\n", + "dlamda2=dlamda1+dlamda; #wavelength of three components(Hz)\n", + "\n", + "#Result\n", + "print \"separation is\",round(dlamda,2),\"angstrom\"\n", + "print \"wavelength of three components is\",lamda,\"angstrom\",round(dlamda1,2),\"angstrom\",round(dlamda2,3),\"angstrom\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 21, Page number 68" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "number of elements would be 110\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "n1=1;\n", + "n2=2; \n", + "n3=3;\n", + "n4=4;\n", + "n5=5;\n", + "\n", + "#Calculations\n", + "e1=2*n1**2; #maximum number of electrons in 1st orbit\n", + "e2=2*n2**2; #maximum number of electrons in 2nd orbit\n", + "e3=2*n3**2; #maximum number of electrons in 3rd orbit\n", + "e4=2*n4**2; #maximum number of electrons in 4th orbit\n", + "e5=2*n5**2; #maximum number of electrons in 5th orbit\n", + "e=e1+e2+e3+e4+e5; #number of elements\n", + "\n", + "#Result\n", + "print \"number of elements would be\",e" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_gZeNd4b.ipynb b/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_gZeNd4b.ipynb new file mode 100644 index 00000000..171aaa2d --- /dev/null +++ b/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_gZeNd4b.ipynb @@ -0,0 +1,396 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# 5: Uncertainity Principle" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 1, Page number 180" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "uncertainity in momentum is 0.211 *10**-20 kg m/sec\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "hby2pi=1.055*10**-34; #plancks constant(J s)\n", + "deltax=5*10**-14; #uncertainity(m)\n", + "\n", + "#Calculations\n", + "delta_px=hby2pi/deltax; #uncertainity in momentum(kg m/sec)\n", + "\n", + "#Result\n", + "print \"uncertainity in momentum is\",delta_px*10**20,\"*10**-20 kg m/sec\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 2, Page number 180" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "uncertainity in position is 3.85 *10**-3 m\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "h=6.6*10**-34; #plancks constant(J s)\n", + "m=9.1*10**-31; #mass(kg)\n", + "v=600; #speed(m/s)\n", + "deltap=(0.005/100)*m*v; #uncertainity in momentum(kg m/sec)\n", + "\n", + "#Calculations\n", + "deltax=h/(2*math.pi*deltap); #uncertainity in position(m)\n", + "\n", + "#Result\n", + "print \"uncertainity in position is\",round(deltax*10**3,2),\"*10**-3 m\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 3, Page number 180" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "uncertainity in momentum is 3.5 *10**-24 kg ms-1\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "h=6.62*10**-34; #plancks constant(J s)\n", + "deltax=3*10**-11; #uncertainity(m)\n", + "\n", + "#Calculations\n", + "deltap=h/(2*math.pi*deltax); #uncertainity in momentum(kg m/sec)\n", + "\n", + "#Result\n", + "print \"uncertainity in momentum is\",round(deltap*10**24,1),\"*10**-24 kg ms-1\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 4, Page number 180" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "uncertainity in determination of energy is 6.59 *10**-8 eV\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "h=6.62*10**-34; #plancks constant(J s)\n", + "deltat=10**-8; #lifetime of excited atom(sec)\n", + "e=1.6*10**-19; #charge(coulomb)\n", + "\n", + "#Calculations\n", + "deltaE=h/(2*math.pi*deltat*e); #uncertainity in determination of energy(eV)\n", + "\n", + "#Result\n", + "print \"uncertainity in determination of energy is\",round(deltaE*10**8,2),\"*10**-8 eV\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 5, Page number 181" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "uncertainity in measurement of angular momentum is 2.17 *10**-29 Js\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "h=6.62*10**-34; #plancks constant(J s)\n", + "deltaphi=math.pi/(180*60*60); \n", + "\n", + "#Calculations\n", + "deltaL=h/(2*math.pi*deltaphi); #uncertainity in measurement of angular momentum(Js)\n", + "\n", + "#Result\n", + "print \"uncertainity in measurement of angular momentum is\",round(deltaL*10**29,2),\"*10**-29 Js\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 6, Page number 181" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "uncertainity in position is 5.27 *10**-34 m\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "h=6.62*10**-34; #plancks constant(J s)\n", + "m=25*10**-3; #mass(kg)\n", + "v=400; #speed(m/s)\n", + "deltap=(2/100)*m*v; #uncertainity in momentum(kg m/sec)\n", + "\n", + "#Calculations\n", + "deltax=h/(2*math.pi*deltap); #uncertainity in position(m)\n", + "\n", + "#Result\n", + "print \"uncertainity in position is\",round(deltax*10**34,2),\"*10**-34 m\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 7, Page number 181" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "percentage of uncertainity in momentum is 3.1 %\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "h=6.62*10**-34; #plancks constant(J s)\n", + "deltax=2*10**-10; #uncertainity in position(m)\n", + "m=9.1*10**-31; #mass(kg)\n", + "e=1.6*10**-19; #charge(coulomb)\n", + "V=1000; #voltage(V)\n", + "\n", + "#Calculations\n", + "deltap=h/(2*math.pi*deltax); #uncertainity in momentum(kg m/s)\n", + "p=math.sqrt(2*m*e*V); #momentum(kg m/s)\n", + "pp=deltap*100/p; #percentage of uncertainity in momentum\n", + "\n", + "#Result\n", + "print \"percentage of uncertainity in momentum is\",round(pp,1),\"%\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 8, Page number 182" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "uncertainity in velocity of electron is 5.79 *10**4 ms-1\n", + "uncertainity in velocity of proton is 31.545 ms-1\n", + "answer for uncertainity in velocity of proton given in the book varies due to rounding off errors\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "h=6.62*10**-34; #plancks constant(J s)\n", + "deltax=20*10**-10; #uncertainity in position(m)\n", + "me=9.1*10**-31; #mass of electron(kg)\n", + "mp=1.67*10**-27; #mass of proton(kg)\n", + "\n", + "#Calculations\n", + "deltave=h/(2*math.pi*deltax*me); #uncertainity in velocity of electron(ms-1)\n", + "deltavp=h/(2*math.pi*deltax*mp); #uncertainity in velocity of proton(ms-1)\n", + "\n", + "#Result\n", + "print \"uncertainity in velocity of electron is\",round(deltave*10**-4,2),\"*10**4 ms-1\"\n", + "print \"uncertainity in velocity of proton is\",round(deltavp,3),\"ms-1\"\n", + "print \"answer for uncertainity in velocity of proton given in the book varies due to rounding off errors\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 9, Page number 182" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "minimum uncertainity in momentum is 1.3 *10**-20 kg m/s\n", + "minimum kinetic energy of proton is 0.32 MeV\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "h=6.62*10**-34; #plancks constant(J s)\n", + "deltax=8*10**-15; #uncertainity in position(m)\n", + "mp=1.67*10**-27; #mass(kg)\n", + "e=1.6*10**-19; #charge(coulomb)\n", + "\n", + "#Calculations\n", + "deltap=h/(2*math.pi*deltax); #minimum uncertainity in momentum(kg m/s)\n", + "ke=deltap**2/(2*mp*e); #minimum kinetic energy of proton(eV)\n", + "\n", + "#Result\n", + "print \"minimum uncertainity in momentum is\",round(deltap*10**20,1),\"*10**-20 kg m/s\"\n", + "print \"minimum kinetic energy of proton is\",round(ke/10**6,2),\"MeV\"" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_khAt4Y6.ipynb b/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_khAt4Y6.ipynb new file mode 100644 index 00000000..444cec94 --- /dev/null +++ b/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_khAt4Y6.ipynb @@ -0,0 +1,208 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# 9: Nuclear Reactions" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 1, Page number 299" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Q value in nuclear reaction is -1.1898 MeV\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "N=14.003073; #mass of N\n", + "O=16.99913; #mass of O\n", + "H=1.007825; #mass of H\n", + "He=4.002604; #mass of He\n", + "m=931; \n", + "\n", + "#Calculation\n", + "Q=(N+He-(O+H))*m; #Q value in nuclear reaction(MeV) \n", + "\n", + "#Result\n", + "print \"Q value in nuclear reaction is\",round(Q,4),\"MeV\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 2, Page number 299" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "heat generated is 6.6 *10**6 KWH\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "Li=7.01600; #mass of Li\n", + "H=1.007825; #mass of H\n", + "He=4.002604; #mass of He\n", + "m=931; \n", + "e=1.6*10**-19; #charge(coulomb)\n", + "N=6.02*10**26; #avagadro number\n", + "M=0.1; #mass(kg)\n", + "x=1000*3600;\n", + "\n", + "#Calculation\n", + "Q=(Li+H-(He+He))*m*10**6*e; #heat generated by Li(J)\n", + "mLi=Li/N; #mass of Li(kg) \n", + "H=Q*M/(x*mLi); #heat generated(KWH)\n", + "\n", + "#Result\n", + "print \"heat generated is\",round(H*10**-6,1),\"*10**6 KWH\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 3, Page number 300" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Q-value for the reaction is 5.485 MeV\n", + "kinetic energy of Zn is 0.635 MeV\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "Cu=62.929599; #mass of Cu\n", + "H=2.014102; #mass of H(amu)\n", + "n=1.008665; #mass of n(amu)\n", + "Zn=63.929145; #mass of Zn(amu)\n", + "m=931; \n", + "Kx=12; #energy of deuterons(MeV)\n", + "Ky=16.85; #kinetic energy of deuterons(MeV)\n", + "\n", + "#Calculation\n", + "Q=(H+Cu-n-Zn)*m; #Q-value for the reaction(MeV)\n", + "K=Q+Kx-Ky; #kinetic energy of Zn(MeV)\n", + "\n", + "#Result\n", + "print \"Q-value for the reaction is\",round(Q,3),\"MeV\"\n", + "print \"kinetic energy of Zn is\",round(K,3),\"MeV\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 4, Page number 301" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "threshold kinetic energy is 5.378 MeV\n", + "answer given in the book is wrong\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "P=1.007825; #mass of P(amu)\n", + "H2=2.014102; #mass of H2(amu)\n", + "H3=3.016049; #mass of H3(amu)\n", + "m=931; \n", + "\n", + "#Calculation\n", + "Q=(P+H3-(2*H2))*m; #Q-value(MeV)\n", + "Kth=-Q*(1+(P/H3)); #threshold kinetic energy(MeV)\n", + "\n", + "#Result\n", + "print \"threshold kinetic energy is\",round(Kth,3),\"MeV\"\n", + "print \"answer given in the book is wrong\"" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_oJQM5Mb.ipynb b/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_oJQM5Mb.ipynb new file mode 100644 index 00000000..4f050408 --- /dev/null +++ b/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_oJQM5Mb.ipynb @@ -0,0 +1,244 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# 10: Nuclear Detectors" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 1, Page number 322" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "current produced is 1.829 *10**-13 amp\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "e=1.6*10**-19; #charge(coulomb)\n", + "n=10; #number of particles\n", + "E=4*10**6; #energy of alpha particle(eV)\n", + "E1=35; #energy of 1 ion pair(eV)\n", + "\n", + "#Calculation\n", + "N=E*n/E1; #number of ion pairs\n", + "q=N*e; #current produced(amp)\n", + "\n", + "#Result\n", + "print \"current produced is\",round(q*10**13,3),\"*10**-13 amp\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 2, Page number 322" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "number of ion pairs required is 6.25 *10**5\n", + "energy of alpha-particles is 21.875 MeV\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "v=4; #voltage sensitivity(div/volt)\n", + "d=0.8; #number of divisions\n", + "C=0.5*10**-12; #capacitance(F)\n", + "e=1.6*10**-19; #charge(coulomb)\n", + "E1=35; #energy of 1 ion pair(eV)\n", + "\n", + "#Calculation\n", + "V=d/v; #voltage(V)\n", + "q=C*V; #current(C)\n", + "n=q/e; #number of ion pairs required\n", + "E=n*E1/10**6; #energy of alpha-particles(MeV)\n", + "\n", + "#Result\n", + "print \"number of ion pairs required is\",n/10**5,\"*10**5\"\n", + "print \"energy of alpha-particles is\",E,\"MeV\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 3, Page number 323" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "maximum radial field is 1.89 *10**6 volts/meter\n", + "counter will last for 3.7 years\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "V=1000; #voltage(V)\n", + "r=0.0001; #radius(m)\n", + "b=2*10**-2; #diameter(m)\n", + "a=10**-4;\n", + "n=10**9; #number of counts\n", + "\n", + "#Calculation\n", + "Emax=V/(r*math.log(b/a)); #maximum radial field(volts/meter)\n", + "N=n/(50*30*60*3000); #counter will last for(years)\n", + "\n", + "#Result\n", + "print \"maximum radial field is\",round(Emax/10**6,2),\"*10**6 volts/meter\"\n", + "print \"counter will last for\",round(N,1),\"years\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 4, Page number 324" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "energy of the particle is 1500 MeV\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "r=2; #radius(m)\n", + "B=2.5; #flux density(Wb/m**2)\n", + "q=1.6*10**-19; #charge(coulomb)\n", + "c=3*10**8; #velocity of light(m/sec)\n", + "\n", + "#Calculation\n", + "E=B*q*r*c*10**-6/q; #energy of the particle(MeV)\n", + "\n", + "#Result\n", + "print \"energy of the particle is\",int(E),\"MeV\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 5, Page number 325" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "average current in the circuit is 1.6e-11 A\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "cr=600; #counting rate(counts/minute)\n", + "e=10**7; #number of electrons per discharge\n", + "q=1.6*10**-19; #charge(coulomb)\n", + "t=60; #number of seconds\n", + "\n", + "#Calculation\n", + "n=cr*e; #number of electrons in 1 minute\n", + "q=n*q/t; #average current in the circuit(A)\n", + "\n", + "#Result\n", + "print \"average current in the circuit is\",q,\"A\"" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_p22tFeA.ipynb b/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_p22tFeA.ipynb new file mode 100644 index 00000000..171aaa2d --- /dev/null +++ b/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_p22tFeA.ipynb @@ -0,0 +1,396 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# 5: Uncertainity Principle" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 1, Page number 180" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "uncertainity in momentum is 0.211 *10**-20 kg m/sec\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "hby2pi=1.055*10**-34; #plancks constant(J s)\n", + "deltax=5*10**-14; #uncertainity(m)\n", + "\n", + "#Calculations\n", + "delta_px=hby2pi/deltax; #uncertainity in momentum(kg m/sec)\n", + "\n", + "#Result\n", + "print \"uncertainity in momentum is\",delta_px*10**20,\"*10**-20 kg m/sec\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 2, Page number 180" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "uncertainity in position is 3.85 *10**-3 m\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "h=6.6*10**-34; #plancks constant(J s)\n", + "m=9.1*10**-31; #mass(kg)\n", + "v=600; #speed(m/s)\n", + "deltap=(0.005/100)*m*v; #uncertainity in momentum(kg m/sec)\n", + "\n", + "#Calculations\n", + "deltax=h/(2*math.pi*deltap); #uncertainity in position(m)\n", + "\n", + "#Result\n", + "print \"uncertainity in position is\",round(deltax*10**3,2),\"*10**-3 m\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 3, Page number 180" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "uncertainity in momentum is 3.5 *10**-24 kg ms-1\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "h=6.62*10**-34; #plancks constant(J s)\n", + "deltax=3*10**-11; #uncertainity(m)\n", + "\n", + "#Calculations\n", + "deltap=h/(2*math.pi*deltax); #uncertainity in momentum(kg m/sec)\n", + "\n", + "#Result\n", + "print \"uncertainity in momentum is\",round(deltap*10**24,1),\"*10**-24 kg ms-1\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 4, Page number 180" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "uncertainity in determination of energy is 6.59 *10**-8 eV\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "h=6.62*10**-34; #plancks constant(J s)\n", + "deltat=10**-8; #lifetime of excited atom(sec)\n", + "e=1.6*10**-19; #charge(coulomb)\n", + "\n", + "#Calculations\n", + "deltaE=h/(2*math.pi*deltat*e); #uncertainity in determination of energy(eV)\n", + "\n", + "#Result\n", + "print \"uncertainity in determination of energy is\",round(deltaE*10**8,2),\"*10**-8 eV\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 5, Page number 181" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "uncertainity in measurement of angular momentum is 2.17 *10**-29 Js\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "h=6.62*10**-34; #plancks constant(J s)\n", + "deltaphi=math.pi/(180*60*60); \n", + "\n", + "#Calculations\n", + "deltaL=h/(2*math.pi*deltaphi); #uncertainity in measurement of angular momentum(Js)\n", + "\n", + "#Result\n", + "print \"uncertainity in measurement of angular momentum is\",round(deltaL*10**29,2),\"*10**-29 Js\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 6, Page number 181" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "uncertainity in position is 5.27 *10**-34 m\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "h=6.62*10**-34; #plancks constant(J s)\n", + "m=25*10**-3; #mass(kg)\n", + "v=400; #speed(m/s)\n", + "deltap=(2/100)*m*v; #uncertainity in momentum(kg m/sec)\n", + "\n", + "#Calculations\n", + "deltax=h/(2*math.pi*deltap); #uncertainity in position(m)\n", + "\n", + "#Result\n", + "print \"uncertainity in position is\",round(deltax*10**34,2),\"*10**-34 m\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 7, Page number 181" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "percentage of uncertainity in momentum is 3.1 %\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "h=6.62*10**-34; #plancks constant(J s)\n", + "deltax=2*10**-10; #uncertainity in position(m)\n", + "m=9.1*10**-31; #mass(kg)\n", + "e=1.6*10**-19; #charge(coulomb)\n", + "V=1000; #voltage(V)\n", + "\n", + "#Calculations\n", + "deltap=h/(2*math.pi*deltax); #uncertainity in momentum(kg m/s)\n", + "p=math.sqrt(2*m*e*V); #momentum(kg m/s)\n", + "pp=deltap*100/p; #percentage of uncertainity in momentum\n", + "\n", + "#Result\n", + "print \"percentage of uncertainity in momentum is\",round(pp,1),\"%\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 8, Page number 182" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "uncertainity in velocity of electron is 5.79 *10**4 ms-1\n", + "uncertainity in velocity of proton is 31.545 ms-1\n", + "answer for uncertainity in velocity of proton given in the book varies due to rounding off errors\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "h=6.62*10**-34; #plancks constant(J s)\n", + "deltax=20*10**-10; #uncertainity in position(m)\n", + "me=9.1*10**-31; #mass of electron(kg)\n", + "mp=1.67*10**-27; #mass of proton(kg)\n", + "\n", + "#Calculations\n", + "deltave=h/(2*math.pi*deltax*me); #uncertainity in velocity of electron(ms-1)\n", + "deltavp=h/(2*math.pi*deltax*mp); #uncertainity in velocity of proton(ms-1)\n", + "\n", + "#Result\n", + "print \"uncertainity in velocity of electron is\",round(deltave*10**-4,2),\"*10**4 ms-1\"\n", + "print \"uncertainity in velocity of proton is\",round(deltavp,3),\"ms-1\"\n", + "print \"answer for uncertainity in velocity of proton given in the book varies due to rounding off errors\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 9, Page number 182" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "minimum uncertainity in momentum is 1.3 *10**-20 kg m/s\n", + "minimum kinetic energy of proton is 0.32 MeV\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "h=6.62*10**-34; #plancks constant(J s)\n", + "deltax=8*10**-15; #uncertainity in position(m)\n", + "mp=1.67*10**-27; #mass(kg)\n", + "e=1.6*10**-19; #charge(coulomb)\n", + "\n", + "#Calculations\n", + "deltap=h/(2*math.pi*deltax); #minimum uncertainity in momentum(kg m/s)\n", + "ke=deltap**2/(2*mp*e); #minimum kinetic energy of proton(eV)\n", + "\n", + "#Result\n", + "print \"minimum uncertainity in momentum is\",round(deltap*10**20,1),\"*10**-20 kg m/s\"\n", + "print \"minimum kinetic energy of proton is\",round(ke/10**6,2),\"MeV\"" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_qNHcrb8.ipynb b/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_qNHcrb8.ipynb new file mode 100644 index 00000000..283605cf --- /dev/null +++ b/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_qNHcrb8.ipynb @@ -0,0 +1,236 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# 15: Superconductivity" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 1, Page number 442" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "critical field at 3K is 0.006281 Tesla\n", + "answer given in the book is wrong\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "H0=0.0106; #critical field at 0K(Tesla)\n", + "T=3; #temperature(K)\n", + "Tc=4.7; #temperature(K)\n", + "\n", + "#Calculation\n", + "Hc=H0*(1-(T/Tc)**2); #critical field at 3K(Tesla)\n", + "\n", + "#Result\n", + "print \"critical field at 3K is\",round(Hc,6),\"Tesla\"\n", + "print \"answer given in the book is wrong\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 2, Page number 442" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "temperature of superconductor is 1.701 K\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "H0=5*10**5/(4*math.pi); #critical field at 0K(Tesla)\n", + "Tc=2.69; #temperature(K)\n", + "Hc=3*10**5/(4*math.pi); #critical field(Tesla)\n", + "\n", + "#Calculation\n", + "T=Tc*math.sqrt(1-(Hc/H0)); #temperature(K)\n", + "\n", + "#Result\n", + "print \"temperature of superconductor is\",round(T,3),\"K\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 3, Page number 443" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "critical field is 4.3365 *10**4 A/m\n", + "critical current of the wire is 408 A\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "H0=6.5*10**4; #critical field at 0K(Tesla)\n", + "Tc=7.28; #temperature(K)\n", + "T=4.2; #temperature(K)\n", + "r=1.5*10**-3; #radius(m)\n", + "\n", + "#Calculation\n", + "Hc=H0*(1-(T/Tc)**2); #critical field(Tesla)\n", + "Ic=2*math.pi*r*Hc; #critical current of the wire(A)\n", + "\n", + "#Result\n", + "print \"critical field is\",round(Hc/10**4,4),\"*10**4 A/m\"\n", + "print \"critical current of the wire is\",int(Ic),\"A\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 4, Page number 443" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "critical temperature is 4.124 K\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "m1=199.5; #isotopic mass\n", + "m2=205.4; #change in mass \n", + "Tc1=4.185; #temperature of mercury(K)\n", + "\n", + "#Calculation\n", + "Tc2=Tc1*math.sqrt(m1/m2); #critical temperature(K)\n", + "\n", + "#Result\n", + "print \"critical temperature is\",round(Tc2,3),\"K\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 5, Page number 444" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "superconducting transition temperature is 8.106 K\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "T1=3; #temperature(K)\n", + "T2=8; #temperature(K)\n", + "lamda1=39.6; #penetration depth(nm)\n", + "lamda2=173; #penetration depth(nm)\n", + "\n", + "#Calculation\n", + "x=(lamda1/lamda2)**2;\n", + "Tc4=(T2**4-(x*T1**4))/(1-x);\n", + "Tc=Tc4**(1/4); #superconducting transition temperature(K)\n", + "\n", + "#Result\n", + "print \"superconducting transition temperature is\",round(Tc,3),\"K\"" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_qeUxd0G.ipynb b/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_qeUxd0G.ipynb new file mode 100644 index 00000000..449a8ffa --- /dev/null +++ b/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_qeUxd0G.ipynb @@ -0,0 +1,320 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# 14: Magnetism" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 1, Page number 420" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "magnetisation is 20 *10**9 A/m\n", + "flux density is 1.2818 *10**6 T\n", + "answer for flux density given in the book is wrong\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "mew0=4*math.pi*10**-7; #permeability of vacuum\n", + "H=10**12; #magnetic field intensity(A/m)\n", + "chi=20*10**-3; #susceptibility\n", + "\n", + "#Calculations\n", + "M=chi*H; #magnetisation(A/m)\n", + "B=mew0*(M+H); #flux density(T)\n", + "\n", + "#Result\n", + "print \"magnetisation is\",int(M/10**9),\"*10**9 A/m\"\n", + "print \"flux density is\",round(B/10**6,4),\"*10**6 T\"\n", + "print \"answer for flux density given in the book is wrong\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 2, Page number 420" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "magnetisation is 17725 A/m\n", + "answer for magnetisation given in the book is wrong\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "mew0=4*math.pi*10**-7; #permeability of vacuum\n", + "H=10**2; #magnetic field intensity(A/m)\n", + "B=0.0224; #flux density(T)\n", + "\n", + "#Calculations\n", + "M=(B/mew0)-H; #magnetisation(A/m)\n", + "\n", + "#Result\n", + "print \"magnetisation is\",int(M),\"A/m\"\n", + "print \"answer for magnetisation given in the book is wrong\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 3, Page number 421" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "change in magnetic moment is 5.27 *10**-29 Am**2\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "e=1.6*10**-19; #charge(coulomb)\n", + "r=5*10**-11; #radius(m)\n", + "B=3; #flux density(T)\n", + "m=9.1*10**-31; #mass(kg)\n", + "\n", + "#Calculations\n", + "mew=B*e**2*r**2/(4*m); #change in magnetic moment(Am**2)\n", + "\n", + "#Result\n", + "print \"change in magnetic moment is\",round(mew*10**29,2),\"*10**-29 Am**2\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 4, Page number 421" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "susceptibility is 0.8 *10**-4\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "T1=200; #temperature(K)\n", + "T2=300; #temperature(K)\n", + "chi1=1.2*10**-4; #susceptibility\n", + "\n", + "#Calculations\n", + "chi2=T1*chi1/T2; #susceptibility\n", + "\n", + "#Result\n", + "print \"susceptibility is\",chi2*10**4,\"*10**-4\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 5, Page number 422" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "paramagnetisation is 3.6 *10**2 A/m\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "H=10**5; #magnetic field intensity(A/m)\n", + "chi=3.6*10**-3; #susceptibility\n", + "\n", + "#Calculations\n", + "M=chi*H; #paramagnetisation(A/m)\n", + "\n", + "#Result\n", + "print \"paramagnetisation is\",M/10**2,\"*10**2 A/m\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 6, Page number 422" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "magnetic moment is 5.655 *10**-24 Am**2\n", + "saturation magnetic induction is 6.5 *10**-4 T\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "mew0=4*math.pi*10**-7; #permeability of vacuum\n", + "mewB=9.27*10**-24; \n", + "rho=8906; #density(kg/m**3)\n", + "N=6.023*10**23; #avagadro number\n", + "W=58.7; #atomic weight\n", + "\n", + "#Calculations\n", + "mewM=0.61*mewB; #magnetic moment(Am**2)\n", + "B=rho*N*mew0*mewM/W; #saturation magnetic induction(T)\n", + "\n", + "#Result\n", + "print \"magnetic moment is\",round(mewM*10**24,3),\"*10**-24 Am**2\"\n", + "print \"saturation magnetic induction is\",round(B*10**4,1),\"*10**-4 T\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 7, Page number 423" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "diamagnetic susceptibility is -8.249 *10**-8\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "mew0=4*math.pi*10**-7; #permeability of vacuum\n", + "e=1.6*10**-19; #charge(coulomb)\n", + "m=9.1*10**-31; #mass(kg)\n", + "R=0.5*10**-10; #radius(m)\n", + "N=28*10**26; #number of atoms\n", + "Z=2; #atomic number\n", + "\n", + "#Calculations\n", + "chi_dia=-mew0*Z*e**2*N*R**2/(6*m); #diamagnetic susceptibility\n", + "\n", + "#Result\n", + "print \"diamagnetic susceptibility is\",round(chi_dia*10**8,3),\"*10**-8\"" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_r0nfWNs.ipynb b/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_r0nfWNs.ipynb new file mode 100644 index 00000000..3725056f --- /dev/null +++ b/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_r0nfWNs.ipynb @@ -0,0 +1,243 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# 13: Bonding In Crystals" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 1, Page number 398" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "potential energy is -5.76 eV\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "x=9*10**9; #assume x=1/(4*pi*epsilon0)\n", + "e=1.6*10**-19; #charge(coulomb)\n", + "r0=2.5*10**-10; #radius(m)\n", + "\n", + "#Calculation\n", + "U=-e*x/r0; #potential energy(eV)\n", + "\n", + "#Result\n", + "print \"potential energy is\",U,\"eV\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 2, Page number 398" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "equilibrium distance is -2.25 angstrom\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "x=9*10**9; #assume x=1/(4*pi*epsilon0)\n", + "e=1.6*10**-19; #charge(coulomb)\n", + "U=6.4; #potential energy(eV)\n", + "\n", + "#Calculation\n", + "r0=-e*x/U; #equilibrium distance(m)\n", + "\n", + "\n", + "#Result\n", + "print \"equilibrium distance is\",r0*10**10,\"angstrom\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 3, Page number 399" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "compressibility of the solid is -25.087 *10**14\n", + "answer given in the book is wrong\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "x=9*10**9; #assume x=1/(4*pi*epsilon0)\n", + "e=1.6*10**-19; #charge(coulomb)\n", + "alpha=1.76; #madelung constant\n", + "n=0.5; #repulsive exponent\n", + "r0=4.1*10**-4; #equilibrium distance(m)\n", + "\n", + "#Calculation\n", + "C=18*r0**4/(x*alpha*e**2*(n-1)); #compressibility of the solid\n", + "\n", + "#Result\n", + "print \"compressibility of the solid is\",round(C*10**-14,3),\"*10**14\"\n", + "print \"answer given in the book is wrong\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 4, Page number 399" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "lattice energy is -6.45 eV\n", + "energy needed to form neutral atoms is -6.17 eV\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "x=9*10**9; #assume x=1/(4*pi*epsilon0)\n", + "e=1.6*10**-19; #charge(coulomb)\n", + "alpha=1.763; #madelung constant\n", + "n=10.5; #repulsive exponent\n", + "r0=3.56*10**-10; #equilibrium distance(m)\n", + "IE=3.89; #ionisation energy(eV)\n", + "EA=-3.61; #electron affinity(eV)\n", + "\n", + "#Calculation\n", + "U=-x*alpha*e**2*(1-(1/n))/(e*r0); #lattice energy(eV) \n", + "E=U+EA+IE; #energy needed to form neutral atoms\n", + "\n", + "#Result\n", + "print \"lattice energy is\",round(U,2),\"eV\"\n", + "print \"energy needed to form neutral atoms is\",round(E,2),\"eV\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 5, Page number 400" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "lattice energy is -3.98 eV\n", + "answer given in the book is wrong\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "x=9*10**9; #assume x=1/(4*pi*epsilon0)\n", + "e=1.6*10**-19; #charge(coulomb)\n", + "alpha=1.748; #madelung constant\n", + "n=9; #repulsive exponent\n", + "r0=2.81*10**-10; #equilibrium distance(m)\n", + "\n", + "#Calculation\n", + "U=-x*alpha*e**2*(1-(1/n))/(e*r0); #lattice energy(eV) \n", + "\n", + "#Result\n", + "print \"lattice energy is\",round(U/2,2),\"eV\"\n", + "print \"answer given in the book is wrong\"" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_uWQUwaW.ipynb b/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_uWQUwaW.ipynb new file mode 100644 index 00000000..31b7323a --- /dev/null +++ b/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_uWQUwaW.ipynb @@ -0,0 +1,277 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# 7: Nuclear Structure" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 1, Page number 259" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "radius of He is 2.2375 fermi\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "A1=165; #mass number\n", + "A2=4; #mass number\n", + "R1=7.731; #radius(fermi)\n", + "\n", + "#Calculation\n", + "R2=R1*(A2/A1)**(1/3); #radius of He(fermi)\n", + "\n", + "#Result\n", + "print \"radius of He is\",round(R2,4),\"fermi\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 2, Page number 259" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "average binding energy per nucleon is 7.07 MeV\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "n=1.008665; #mass of neutron(amu)\n", + "p=1.007276; #mass of proton(amu)\n", + "alpha=4.00150; #mass of alpha particle(amu)\n", + "m=931; \n", + "\n", + "#Calculation\n", + "deltam=2*(p+n)-alpha;\n", + "BE=deltam*m; #binding energy(MeV)\n", + "ABE=BE/4; #average binding energy per nucleon(MeV)\n", + "\n", + "#Result\n", + "print \"average binding energy per nucleon is\",round(ABE,2),\"MeV\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 3, Page number 260" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "binding energy of neutron is 7.25 MeV\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "n=1.008665; #mass of neutron(amu)\n", + "Li36=6.015125; #mass of Li(amu)\n", + "Li37=7.016004; #mass of Li(amu)\n", + "m=931; \n", + "\n", + "#Calculation\n", + "deltam=Li36+n-Li37; \n", + "BE=deltam*m; #binding energy of neutron(MeV)\n", + "\n", + "#Result\n", + "print \"binding energy of neutron is\",round(BE,2),\"MeV\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 4, Page number 260" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "energy released is 23.6 MeV\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "BEHe=4*7.0; #binding energy for He\n", + "BEH=2*1.1; #binding energy for H\n", + "\n", + "#Calculation\n", + "deltaE=BEHe-(2*BEH); #energy released(MeV) \n", + "\n", + "#Result\n", + "print \"energy released is\",deltaE,\"MeV\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 5, Page number 260" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "mass is 19.987 amu\n", + "answer given in the book is wrong\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "n=1.008665; #mass of neutron(amu)\n", + "p=1.007276; #mass of proton(amu)\n", + "BE=160.647; #binding energy(MeV)\n", + "m=931; \n", + "\n", + "#Calculation\n", + "Mx=10*(p+n)-(BE/m); #mass(amu)\n", + "\n", + "#Result\n", + "print \"mass is\",round(Mx,3),\"amu\"\n", + "print \"answer given in the book is wrong\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 6, Page number 261" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "binding energy of neutron is 11.471 MeV\n", + "answer given in the book varies due to rounding off errors\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "n=1.008665; #mass of neutron(amu)\n", + "Ca41=40.962278; #mass of Ca(amu)\n", + "Ca42=41.958622; #mass of Ca(amu)\n", + "m=931; \n", + "\n", + "#Calculation\n", + "deltam=Ca41+n-Ca42; \n", + "BE=deltam*m; #binding energy of neutron(MeV)\n", + "\n", + "#Result\n", + "print \"binding energy of neutron is\",round(BE,3),\"MeV\"\n", + "print \"answer given in the book varies due to rounding off errors\"" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_vkMAnbH.ipynb b/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_vkMAnbH.ipynb new file mode 100644 index 00000000..444cec94 --- /dev/null +++ b/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_vkMAnbH.ipynb @@ -0,0 +1,208 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# 9: Nuclear Reactions" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 1, Page number 299" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Q value in nuclear reaction is -1.1898 MeV\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "N=14.003073; #mass of N\n", + "O=16.99913; #mass of O\n", + "H=1.007825; #mass of H\n", + "He=4.002604; #mass of He\n", + "m=931; \n", + "\n", + "#Calculation\n", + "Q=(N+He-(O+H))*m; #Q value in nuclear reaction(MeV) \n", + "\n", + "#Result\n", + "print \"Q value in nuclear reaction is\",round(Q,4),\"MeV\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 2, Page number 299" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "heat generated is 6.6 *10**6 KWH\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "Li=7.01600; #mass of Li\n", + "H=1.007825; #mass of H\n", + "He=4.002604; #mass of He\n", + "m=931; \n", + "e=1.6*10**-19; #charge(coulomb)\n", + "N=6.02*10**26; #avagadro number\n", + "M=0.1; #mass(kg)\n", + "x=1000*3600;\n", + "\n", + "#Calculation\n", + "Q=(Li+H-(He+He))*m*10**6*e; #heat generated by Li(J)\n", + "mLi=Li/N; #mass of Li(kg) \n", + "H=Q*M/(x*mLi); #heat generated(KWH)\n", + "\n", + "#Result\n", + "print \"heat generated is\",round(H*10**-6,1),\"*10**6 KWH\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 3, Page number 300" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Q-value for the reaction is 5.485 MeV\n", + "kinetic energy of Zn is 0.635 MeV\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "Cu=62.929599; #mass of Cu\n", + "H=2.014102; #mass of H(amu)\n", + "n=1.008665; #mass of n(amu)\n", + "Zn=63.929145; #mass of Zn(amu)\n", + "m=931; \n", + "Kx=12; #energy of deuterons(MeV)\n", + "Ky=16.85; #kinetic energy of deuterons(MeV)\n", + "\n", + "#Calculation\n", + "Q=(H+Cu-n-Zn)*m; #Q-value for the reaction(MeV)\n", + "K=Q+Kx-Ky; #kinetic energy of Zn(MeV)\n", + "\n", + "#Result\n", + "print \"Q-value for the reaction is\",round(Q,3),\"MeV\"\n", + "print \"kinetic energy of Zn is\",round(K,3),\"MeV\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 4, Page number 301" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "threshold kinetic energy is 5.378 MeV\n", + "answer given in the book is wrong\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "P=1.007825; #mass of P(amu)\n", + "H2=2.014102; #mass of H2(amu)\n", + "H3=3.016049; #mass of H3(amu)\n", + "m=931; \n", + "\n", + "#Calculation\n", + "Q=(P+H3-(2*H2))*m; #Q-value(MeV)\n", + "Kth=-Q*(1+(P/H3)); #threshold kinetic energy(MeV)\n", + "\n", + "#Result\n", + "print \"threshold kinetic energy is\",round(Kth,3),\"MeV\"\n", + "print \"answer given in the book is wrong\"" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_wP2wGMS.ipynb b/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_wP2wGMS.ipynb new file mode 100644 index 00000000..ede08994 --- /dev/null +++ b/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_wP2wGMS.ipynb @@ -0,0 +1,588 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# 2: Molecular Spectra" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 2, Page number 97" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "raman shift is 219.03 cm-1\n", + "answer given in the book is wrong\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "lamda_sample=4358; #wavelength(angstrom)\n", + "lamda_raman=4400; #wavelength(angstrom)\n", + "\n", + "#Calculations\n", + "delta_new=(10**8/lamda_sample)-(10**8/lamda_raman); #raman shift(cm-1)\n", + "\n", + "#Result\n", + "print \"raman shift is\",round(delta_new,2),\"cm-1\"\n", + "print \"answer given in the book is wrong\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 3, Page number 98" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "energy of diatomic molecule is 2.22 *10**-68 J\n", + "answer given in the book is wrong\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "h=6.62*10**-34; #planck's constant\n", + "\n", + "#Calculations\n", + "E=h**2/(2*math.pi**2); #energy of diatomic molecule(J)\n", + "\n", + "#Result\n", + "print \"energy of diatomic molecule is\",round(E*10**68,2),\"*10**-68 J\"\n", + "print \"answer given in the book is wrong\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 4, Page number 98" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "raman shift is 0.02 *10**6 m-1\n", + "wavelength of antistokes line 4950.5 angstrom\n", + "answer for wavelength given in the book is wrong\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "lamda0=5000*10**-10; #wavelength(m)\n", + "lamda=5050.5*10**-10; #wavelength(m)\n", + "\n", + "#Calculations\n", + "new0=1/lamda0; #frequency(m-1)\n", + "new=1/lamda; #frequency(m-1)\n", + "delta_new=new0-new; #raman shift(m-1)\n", + "new_as=delta_new+new0; #frequency of anti-stokes line(m-1)\n", + "lamdaas=1*10**10/new_as; #wavelength of anti-stokes line(angstrom)\n", + "\n", + "#Result\n", + "print \"raman shift is\",round(delta_new*10**-6,2),\"*10**6 m-1\"\n", + "print \"wavelength of antistokes line\",round(lamdaas,2),\"angstrom\"\n", + "print \"answer for wavelength given in the book is wrong\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 5, Page number 99" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "energy required is 60 eV\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "k=4.8*10**2; #force constant(N/m)\n", + "x=2*10**-10; #inter nuclear distance(m)\n", + "e=1.6*10**-19; #charge(coulomb)\n", + "\n", + "#Calculations\n", + "E=k*x**2/(2*e); #energy required(eV)\n", + "\n", + "#Result\n", + "print \"energy required is\",int(E),\"eV\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 6, Page number 99" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "frequency of vibration is 2.04 *10**13 sec-1\n", + "spacing between energy levels is 8.447 *10**-2 eV\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "k=187; #force constant(N/m)\n", + "m=1.14*10**-26; #reduced mass(kg)\n", + "h=6.63*10**-34; #planck's constant\n", + "e=1.6*10**-19; #charge(coulomb)\n", + "\n", + "#Calculations\n", + "new=math.sqrt(k/m)/(2*math.pi); #frequency of vibration(sec-1)\n", + "delta_E=h*new; #spacing between energy levels(J)\n", + "delta_E=delta_E/e; #spacing between energy levels(eV)\n", + "\n", + "#Result\n", + "print \"frequency of vibration is\",round(new*10**-13,2),\"*10**13 sec-1\"\n", + "print \"spacing between energy levels is\",round(delta_E*10**2,3),\"*10**-2 eV\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 7, Page number 100" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "internuclear distance is 1.42 angstrom\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "B=8.5; #seperation(cm-1)\n", + "h=6.62*10**-27; #planck's constant\n", + "c=3*10**10; #velocity of light(cm/sec)\n", + "N=6.023*10**23; #avagadro number\n", + "m1=1;\n", + "m2=79; \n", + "\n", + "#Calculations\n", + "I=h/(8*math.pi**2*B*c); #moment inertia of molecule(gm cm**2)\n", + "m=m1*m2/(N*(m1+m2)); #reduced mass(gm)\n", + "r=10**8*math.sqrt(I/m); #internuclear distance(angstrom)\n", + "\n", + "#Result\n", + "print \"internuclear distance is\",round(r,2),\"angstrom\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 8, Page number 100" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "vibrational frequency of sample is 1974 cm-1\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "lamda1=4358.3; #wavelength(angstrom)\n", + "lamda2=4768.5; #wavelength(angstrom)\n", + "\n", + "#Calculations\n", + "delta_new=(10**8/lamda1)-(10**8/lamda2); #vibrational frequency of sample(cm-1)\n", + "\n", + "#Result\n", + "print \"vibrational frequency of sample is\",int(round(delta_new)),\"cm-1\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 9, Page number 101" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "frequqncy of OD stretching vibration is 2401 cm-1\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "MO=16;\n", + "MD=2;\n", + "MH=1;\n", + "new=3300; #frequency(cm-1)\n", + "\n", + "#Calculations\n", + "mew_OD=MO*MD/(MO+MD); \n", + "mew_OH=MO*MH/(MO+MH);\n", + "new1=math.sqrt(mew_OD/mew_OH);\n", + "new_OD=new/new1; #frequqncy of OD stretching vibration(cm-1)\n", + "\n", + "#Result\n", + "print \"frequqncy of OD stretching vibration is\",int(new_OD),\"cm-1\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 11, Page number 102" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "raman shift of 4400 line is 219.03 cm-1\n", + "raman shift of 4419 line is 316.8 cm-1\n", + "raman shift of 4447 line is 459.2 cm-1\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "lamda0=4358; #wavelength(angstrom)\n", + "lamda1=4400; #wavelength(angstrom)\n", + "lamda2=4419; #wavelength(angstrom)\n", + "lamda3=4447; #wavelength(angstrom)\n", + "\n", + "#Calculations\n", + "new0bar=10**8/lamda0; #wave number of exciting line(cm-1)\n", + "rs1=(10**8/lamda0)-(10**8/lamda1); #raman shift of 4400 line(cm-1)\n", + "rs2=(10**8/lamda0)-(10**8/lamda2); #raman shift of 4419 line(cm-1)\n", + "rs3=(10**8/lamda0)-(10**8/lamda3); #raman shift of 4447 line(cm-1)\n", + "\n", + "#Result\n", + "print \"raman shift of 4400 line is\",round(rs1,2),\"cm-1\"\n", + "print \"raman shift of 4419 line is\",round(rs2,1),\"cm-1\"\n", + "print \"raman shift of 4447 line is\",round(rs3,1),\"cm-1\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 12, Page number 102" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "corresponding wavelength is 32 *10**-4 cm\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "new_bar=20.68; #transition(cm-1)\n", + "J=14;\n", + "\n", + "#Calculations\n", + "B=new_bar/2; \n", + "new=2*B*(J+1); #frequency(cm-1)\n", + "lamda=1/new; #corresponding wavelength(cm) \n", + "\n", + "#Result\n", + "print \"corresponding wavelength is\",int(lamda*10**4),\"*10**-4 cm\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 13, Page number 103" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "moment of inertia of molecule is 1.4 *10**-42 gm cm**2\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "twoB=4000; #seperation observed from the series(cm-1)\n", + "h=6.62*10**-27; #planck's constant\n", + "c=3*10**10; #velocity of light(cm/sec)\n", + "\n", + "#Calculations\n", + "B=twoB/2;\n", + "I=h/(8*math.pi**2*B*c); #moment of inertia of molecule(gm cm**2)\n", + "\n", + "#Result\n", + "print \"moment of inertia of molecule is\",round(I*10**42,1),\"*10**-42 gm cm**2\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 14, Page number 104" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "corresponding wavelengths are 5648 angstrom 5725 angstrom 5775 angstrom 5836 angstrom 5983 angstrom 6558 angstrom\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "lamda=5461*10**-8; #wavelength(cm)\n", + "new1=608;\n", + "new2=846;\n", + "new3=995;\n", + "new4=1178;\n", + "new5=1599; \n", + "new6=3064; #raman shift(cm-1)\n", + "\n", + "#Calculations\n", + "newbar=1/lamda; #wave number(cm-1)\n", + "new11=newbar-new1;\n", + "new22=newbar-new2;\n", + "new33=newbar-new3;\n", + "new44=newbar-new4;\n", + "new55=newbar-new5;\n", + "new66=newbar-new6;\n", + "lamda1=10**8/new11;\n", + "lamda2=10**8/new22;\n", + "lamda3=10**8/new33;\n", + "lamda4=10**8/new44;\n", + "lamda5=10**8/new55;\n", + "lamda6=10**8/new66; #corresponding wavelength(angstrom)\n", + "\n", + "#Result\n", + "print \"corresponding wavelengths are\",int(lamda1),\"angstrom\",int(lamda2),\"angstrom\",int(round(lamda3)),\"angstrom\",int(lamda4),\"angstrom\",int(lamda5),\"angstrom\",int(lamda6),\"angstrom\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 15, Page number 105" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "force constant is 115 N/m\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "h=6.63*10**-34; #planck's constant(J s)\n", + "e=1.602*10**-19; #charge(coulomb) \n", + "mew=1.14*10**-26; #reduced mass(kg)\n", + "deltaE=6.63*10**-2*e; #energy(J)\n", + "\n", + "#Calculations\n", + "new=deltaE/h; #frequency(sec-1)\n", + "k=4*math.pi**2*new**2*mew; #force constant(N/m)\n", + "\n", + "#Result\n", + "print \"force constant is\",int(k),\"N/m\"" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_x09tDSO.ipynb b/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_x09tDSO.ipynb new file mode 100644 index 00000000..72f70169 --- /dev/null +++ b/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_x09tDSO.ipynb @@ -0,0 +1,540 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# 3: Inadequacy of Classical Physics" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 1, Page number 128" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "maximum energy of photoelectron is 3.038 *10**-19 J\n", + "maximum velocity of electron is 8.17 *10**5 ms-1\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "me=9.1*10**-31; #mass of electron(kg)\n", + "h=6.6*10**-34; #planks constant(Js)\n", + "c=3*10**8; #velocity(m/sec)\n", + "lamda=1700*10**-10; #wavelength(m)\n", + "lamda0=2300*10**-10; #wavelength(m)\n", + "\n", + "#Calculations\n", + "KE=h*c*((1/lamda)-(1/lamda0)); #maximum energy of photoelectron(J)\n", + "vmax=math.sqrt(2*KE/me); #maximum velocity of electron(ms-1)\n", + "\n", + "#Result\n", + "print \"maximum energy of photoelectron is\",round(KE*10**19,3),\"*10**-19 J\"\n", + "print \"maximum velocity of electron is\",round(vmax/10**5,2),\"*10**5 ms-1\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 2, Page number 128" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "threshold wavelength is 5380 angstrom\n", + "since wavelength of orange light is more, photoelectric effect doesn't take place\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "e=1.6*10**-19; #charge(coulomb)\n", + "W=2.3*e; #work function(J)\n", + "h=6.6*10**-34; #planks constant(Js)\n", + "c=3*10**8; #velocity(m/sec)\n", + "lamda=6850; #wavelength of orange light(angstrom)\n", + "\n", + "#Calculations\n", + "lamda0=h*c/W; #threshold wavelength(m)\n", + "\n", + "#Result\n", + "print \"threshold wavelength is\",int(lamda0*10**10),\"angstrom\"\n", + "print \"since wavelength of orange light is more, photoelectric effect doesn't take place\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 3, Page number 129" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "retarding potential is 1.175 volts\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "e=1.6*10**-19; #charge(coulomb)\n", + "W=1.3*e; #work function(J)\n", + "h=6.6*10**-34; #planks constant(Js)\n", + "new=6*10**14; #frequency(Hertz)\n", + "\n", + "#Calculations\n", + "V0=((h*new)-W)/e; #retarding potential(volts)\n", + "\n", + "#Result\n", + "print \"retarding potential is\",V0,\"volts\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 4, Page number 129" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "work function is 1.28 eV\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "h=6.6*10**-34; #planks constant(Js)\n", + "e=1.6*10**-19; #charge(coulomb)\n", + "c=3*10**8; #velocity(m/sec)\n", + "lamda=3*10**-7; #wavelength(m)\n", + "me=9.1*10**-31; #mass of electron(kg)\n", + "v=1*10**6; #velocity(m/sec)\n", + "\n", + "#Calculations\n", + "W=(h*c/lamda)-(me*v**2/2); #work function(J)\n", + "W=W/e; #work function(eV)\n", + "\n", + "#Result\n", + "print \"work function is\",round(W,2),\"eV\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 5, Page number 129" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "photoelectric current is 1.86 micro ampere\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "h=6.6*10**-34; #planks constant(Js)\n", + "e=1.6*10**-19; #charge(coulomb)\n", + "c=3*10**8; #velocity(m/sec)\n", + "lamda=4600*10**-10; #wavelength(m)\n", + "qe=0.5; #efficiency(%)\n", + "\n", + "#Calculations\n", + "E=h*c/lamda; #energy(J)\n", + "n=10**-3/E; #number of photons/second\n", + "i=n*qe*e*10**6/100; #photoelectric current(micro ampere)\n", + "\n", + "#Result\n", + "print \"photoelectric current is\",round(i,2),\"micro ampere\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 6, Page number 130" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "planck's constant is 6.61 *10**-34 joule second\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "T1=3*10**-19; #temperature(J)\n", + "T2=1*10**-19; #temperature(J)\n", + "c=3*10**8; #velocity(m/sec)\n", + "lamda1=3350; #wavelength(m)\n", + "lamda2=5060; #wavelength(m)\n", + "\n", + "#Calculations\n", + "x=10**10*((1/lamda1)-(1/lamda2));\n", + "h=(T1-T2)/(c*x); #planck's constant(joule second)\n", + "\n", + "#Result\n", + "print \"planck's constant is\",round(h*10**34,2),\"*10**-34 joule second\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 7, Page number 131" + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "wavelength of scattered radiation is 3.0121 angstrom\n", + "energy of recoil electron is 2.66 *10**-18 joule\n", + "answers given in the book are wrong\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "c=3*10**8; #velocity of light(m/sec)\n", + "m0=9.1*10**-31; #mass(kg)\n", + "h=6.62*10**-34; #planks constant(Js)\n", + "theta=60*math.pi/180; #angle(radian)\n", + "lamda=3*10**-10; #wavelength(angstrom)\n", + "lamda_dash=3.058; #wavelength(angstrom)\n", + "\n", + "#Calculations\n", + "lamda_sr=h/(m0*c); \n", + "lamda_dash=lamda+(lamda_sr*(1-math.cos(theta))); #wavelength of scattered radiation(m) \n", + "lamda_dash=round(lamda_dash*10**10,4)*10**-10; #wavelength of scattered radiation(m)\n", + "E=h*c*((1/lamda)-(1/lamda_dash)); #energy of recoil electron(joule)\n", + "\n", + "#Result\n", + "print \"wavelength of scattered radiation is\",lamda_dash*10**10,\"angstrom\"\n", + "print \"energy of recoil electron is\",round(E*10**18,2),\"*10**-18 joule\"\n", + "print \"answers given in the book are wrong\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 8, Page number 132" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "wavelength of scattered radiation is 2.003 angstrom\n", + "velocity of recoil electron is 0.0188 *10**8 ms-1\n", + "answer for velocity given in the book is wrong\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "c=3*10**8; #velocity of light(m/sec)\n", + "m0=9.1*10**-31; #mass(kg)\n", + "h=6.62*10**-34; #planks constant(Js)\n", + "theta=30*math.pi/180; #angle(radian)\n", + "lamda=2*10**-10; #wavelength(angstrom)\n", + "\n", + "#Calculations\n", + "lamda_sr=h/(m0*c); \n", + "lamda_dash=lamda+(lamda_sr*(1-math.cos(theta))); #wavelength of scattered radiation(m) \n", + "E=h*c*((1/lamda)-(1/lamda_dash)); #energy of recoil electron(joule)\n", + "x=1+(E/(m0*c**2));\n", + "v=c*math.sqrt(1-((1/x)**2)); #velocity of recoil electron(m/sec)\n", + "\n", + "#Result\n", + "print \"wavelength of scattered radiation is\",round(lamda_dash*10**10,3),\"angstrom\"\n", + "print \"velocity of recoil electron is\",round(v/10**8,4),\"*10**8 ms-1\"\n", + "print \"answer for velocity given in the book is wrong\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 9, Page number 133" + ] + }, + { + "cell_type": "code", + "execution_count": 49, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "wavelength of scattered photon is 3.024 angstrom\n", + "energy of recoil electron is 0.5 *10**-17 joules\n", + "direction of recoil electron is 44 degrees 46 minutes\n", + "answer for angle given in the book is wrong\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "c=3*10**8; #velocity of light(m/sec)\n", + "e=1.6*10**-19; #charge(coulomb)\n", + "m0=9.1*10**-31; #mass(kg)\n", + "h=6.62*10**-34; #planks constant(Js)\n", + "theta=90*math.pi/180; #angle(radian)\n", + "lamda=3*10**-10; #wavelength(m) \n", + "\n", + "#Calculations\n", + "lamda_dash=lamda+(h*(1-math.cos(theta))/(m0*c)); #wavelength of scattered photon(m) \n", + "E=h*c*((1/lamda)-(1/lamda_dash)); #energy of recoil electron(joule)\n", + "x=h/(lamda*m0*c);\n", + "tanphi=lamda*math.sin(theta)/(lamda_dash-(lamda*math.cos(theta)));\n", + "phi=math.atan(tanphi); #direction of recoil electron(radian)\n", + "phi=phi*180/math.pi; #direction of recoil electron(degrees)\n", + "phim=60*(phi-int(phi)); #angle(minutes)\n", + "\n", + "#Result\n", + "print \"wavelength of scattered photon is\",round(lamda_dash*10**10,3),\"angstrom\"\n", + "print \"energy of recoil electron is\",round(E*10**17,1),\"*10**-17 joules\"\n", + "print \"direction of recoil electron is\",int(phi),\"degrees\",int(phim),\"minutes\"\n", + "print \"answer for angle given in the book is wrong\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 10, Page number 134" + ] + }, + { + "cell_type": "code", + "execution_count": 51, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "energy of scattered photon is 0.226 MeV\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "c=3*10**8; #velocity of light(m/sec)\n", + "e=1.6*10**-19; #charge(coulomb)\n", + "m0=9.1*10**-31; #mass(kg)\n", + "h=6.62*10**-34; #planks constant(Js)\n", + "theta=180*math.pi/180; #angle(radian)\n", + "E=1.96*10**6*e; #energy of scattered photon(J)\n", + "\n", + "#Calculations\n", + "lamda=h*c/E; #wavelength(m)\n", + "delta_lamda=2*h/(m0*c); \n", + "lamda_dash=lamda+delta_lamda; #wavelength of scattered photon(m) \n", + "Edash=h*c/(e*lamda_dash); #energy of scattered photon(eV)\n", + "\n", + "#Result\n", + "print \"energy of scattered photon is\",round(Edash/10**6,3),\"MeV\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 11, Page number 135" + ] + }, + { + "cell_type": "code", + "execution_count": 65, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "wavelength of scattered radiation is 4.9e-12 m\n", + "energy of recoil electron is 3.9592 *10**-14 Joules\n", + "direction of recoil electron is 27 degrees 47 minutes\n", + "answer for energy and direction of recoil electron and given in the book is wrong\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "c=3*10**8; #velocity of light(m/sec)\n", + "e=1.6*10**-19; #charge(coulomb)\n", + "m0=9.1*10**-31; #mass(kg)\n", + "h=6.6*10**-34; #planks constant(Js)\n", + "theta=90*math.pi/180; #angle(radian)\n", + "E=500*10**3*e; #energy of scattered photon(J)\n", + "\n", + "#Calculations\n", + "lamda=h*c/E; #wavelength(m)\n", + "delta_lamda=h*(1-math.cos(theta))/(m0*c); \n", + "lamda_dash=lamda+delta_lamda; #wavelength of scattered radiation(m) \n", + "lamda_dash=round(lamda_dash*10**12,1)*10**-12; #wavelength of scattered radiation(m) \n", + "E=h*c*((1/lamda)-(1/lamda_dash)); #energy of recoil electron(J)\n", + "tanphi=lamda*math.sin(theta)/(lamda_dash-(lamda*math.cos(theta)));\n", + "phi=math.atan(tanphi); #direction of recoil electron(radian)\n", + "phi=phi*180/math.pi; #direction of recoil electron(degrees)\n", + "phim=60*(phi-int(phi)); #angle(minutes)\n", + "\n", + "#Result\n", + "print \"wavelength of scattered radiation is\",lamda_dash,\"m\"\n", + "print \"energy of recoil electron is\",round(E*10**14,4),\"*10**-14 Joules\"\n", + "print \"direction of recoil electron is\",int(round(phi)),\"degrees\",int(phim),\"minutes\"\n", + "print \"answer for energy and direction of recoil electron and given in the book is wrong\"" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_yCW2orc.ipynb b/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_yCW2orc.ipynb new file mode 100644 index 00000000..72f70169 --- /dev/null +++ b/Physics_BSc(Paper_4)_by_Sanjeeva_Rao,_Bhikshmaiah,_Ramakrishna_Reddy,_Ananta_Ramaiah/C_yCW2orc.ipynb @@ -0,0 +1,540 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# 3: Inadequacy of Classical Physics" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 1, Page number 128" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "maximum energy of photoelectron is 3.038 *10**-19 J\n", + "maximum velocity of electron is 8.17 *10**5 ms-1\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "me=9.1*10**-31; #mass of electron(kg)\n", + "h=6.6*10**-34; #planks constant(Js)\n", + "c=3*10**8; #velocity(m/sec)\n", + "lamda=1700*10**-10; #wavelength(m)\n", + "lamda0=2300*10**-10; #wavelength(m)\n", + "\n", + "#Calculations\n", + "KE=h*c*((1/lamda)-(1/lamda0)); #maximum energy of photoelectron(J)\n", + "vmax=math.sqrt(2*KE/me); #maximum velocity of electron(ms-1)\n", + "\n", + "#Result\n", + "print \"maximum energy of photoelectron is\",round(KE*10**19,3),\"*10**-19 J\"\n", + "print \"maximum velocity of electron is\",round(vmax/10**5,2),\"*10**5 ms-1\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 2, Page number 128" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "threshold wavelength is 5380 angstrom\n", + "since wavelength of orange light is more, photoelectric effect doesn't take place\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "e=1.6*10**-19; #charge(coulomb)\n", + "W=2.3*e; #work function(J)\n", + "h=6.6*10**-34; #planks constant(Js)\n", + "c=3*10**8; #velocity(m/sec)\n", + "lamda=6850; #wavelength of orange light(angstrom)\n", + "\n", + "#Calculations\n", + "lamda0=h*c/W; #threshold wavelength(m)\n", + "\n", + "#Result\n", + "print \"threshold wavelength is\",int(lamda0*10**10),\"angstrom\"\n", + "print \"since wavelength of orange light is more, photoelectric effect doesn't take place\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 3, Page number 129" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "retarding potential is 1.175 volts\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "e=1.6*10**-19; #charge(coulomb)\n", + "W=1.3*e; #work function(J)\n", + "h=6.6*10**-34; #planks constant(Js)\n", + "new=6*10**14; #frequency(Hertz)\n", + "\n", + "#Calculations\n", + "V0=((h*new)-W)/e; #retarding potential(volts)\n", + "\n", + "#Result\n", + "print \"retarding potential is\",V0,\"volts\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 4, Page number 129" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "work function is 1.28 eV\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "h=6.6*10**-34; #planks constant(Js)\n", + "e=1.6*10**-19; #charge(coulomb)\n", + "c=3*10**8; #velocity(m/sec)\n", + "lamda=3*10**-7; #wavelength(m)\n", + "me=9.1*10**-31; #mass of electron(kg)\n", + "v=1*10**6; #velocity(m/sec)\n", + "\n", + "#Calculations\n", + "W=(h*c/lamda)-(me*v**2/2); #work function(J)\n", + "W=W/e; #work function(eV)\n", + "\n", + "#Result\n", + "print \"work function is\",round(W,2),\"eV\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 5, Page number 129" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "photoelectric current is 1.86 micro ampere\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "h=6.6*10**-34; #planks constant(Js)\n", + "e=1.6*10**-19; #charge(coulomb)\n", + "c=3*10**8; #velocity(m/sec)\n", + "lamda=4600*10**-10; #wavelength(m)\n", + "qe=0.5; #efficiency(%)\n", + "\n", + "#Calculations\n", + "E=h*c/lamda; #energy(J)\n", + "n=10**-3/E; #number of photons/second\n", + "i=n*qe*e*10**6/100; #photoelectric current(micro ampere)\n", + "\n", + "#Result\n", + "print \"photoelectric current is\",round(i,2),\"micro ampere\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 6, Page number 130" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "planck's constant is 6.61 *10**-34 joule second\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "T1=3*10**-19; #temperature(J)\n", + "T2=1*10**-19; #temperature(J)\n", + "c=3*10**8; #velocity(m/sec)\n", + "lamda1=3350; #wavelength(m)\n", + "lamda2=5060; #wavelength(m)\n", + "\n", + "#Calculations\n", + "x=10**10*((1/lamda1)-(1/lamda2));\n", + "h=(T1-T2)/(c*x); #planck's constant(joule second)\n", + "\n", + "#Result\n", + "print \"planck's constant is\",round(h*10**34,2),\"*10**-34 joule second\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 7, Page number 131" + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "wavelength of scattered radiation is 3.0121 angstrom\n", + "energy of recoil electron is 2.66 *10**-18 joule\n", + "answers given in the book are wrong\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "c=3*10**8; #velocity of light(m/sec)\n", + "m0=9.1*10**-31; #mass(kg)\n", + "h=6.62*10**-34; #planks constant(Js)\n", + "theta=60*math.pi/180; #angle(radian)\n", + "lamda=3*10**-10; #wavelength(angstrom)\n", + "lamda_dash=3.058; #wavelength(angstrom)\n", + "\n", + "#Calculations\n", + "lamda_sr=h/(m0*c); \n", + "lamda_dash=lamda+(lamda_sr*(1-math.cos(theta))); #wavelength of scattered radiation(m) \n", + "lamda_dash=round(lamda_dash*10**10,4)*10**-10; #wavelength of scattered radiation(m)\n", + "E=h*c*((1/lamda)-(1/lamda_dash)); #energy of recoil electron(joule)\n", + "\n", + "#Result\n", + "print \"wavelength of scattered radiation is\",lamda_dash*10**10,\"angstrom\"\n", + "print \"energy of recoil electron is\",round(E*10**18,2),\"*10**-18 joule\"\n", + "print \"answers given in the book are wrong\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 8, Page number 132" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "wavelength of scattered radiation is 2.003 angstrom\n", + "velocity of recoil electron is 0.0188 *10**8 ms-1\n", + "answer for velocity given in the book is wrong\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "c=3*10**8; #velocity of light(m/sec)\n", + "m0=9.1*10**-31; #mass(kg)\n", + "h=6.62*10**-34; #planks constant(Js)\n", + "theta=30*math.pi/180; #angle(radian)\n", + "lamda=2*10**-10; #wavelength(angstrom)\n", + "\n", + "#Calculations\n", + "lamda_sr=h/(m0*c); \n", + "lamda_dash=lamda+(lamda_sr*(1-math.cos(theta))); #wavelength of scattered radiation(m) \n", + "E=h*c*((1/lamda)-(1/lamda_dash)); #energy of recoil electron(joule)\n", + "x=1+(E/(m0*c**2));\n", + "v=c*math.sqrt(1-((1/x)**2)); #velocity of recoil electron(m/sec)\n", + "\n", + "#Result\n", + "print \"wavelength of scattered radiation is\",round(lamda_dash*10**10,3),\"angstrom\"\n", + "print \"velocity of recoil electron is\",round(v/10**8,4),\"*10**8 ms-1\"\n", + "print \"answer for velocity given in the book is wrong\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 9, Page number 133" + ] + }, + { + "cell_type": "code", + "execution_count": 49, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "wavelength of scattered photon is 3.024 angstrom\n", + "energy of recoil electron is 0.5 *10**-17 joules\n", + "direction of recoil electron is 44 degrees 46 minutes\n", + "answer for angle given in the book is wrong\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "c=3*10**8; #velocity of light(m/sec)\n", + "e=1.6*10**-19; #charge(coulomb)\n", + "m0=9.1*10**-31; #mass(kg)\n", + "h=6.62*10**-34; #planks constant(Js)\n", + "theta=90*math.pi/180; #angle(radian)\n", + "lamda=3*10**-10; #wavelength(m) \n", + "\n", + "#Calculations\n", + "lamda_dash=lamda+(h*(1-math.cos(theta))/(m0*c)); #wavelength of scattered photon(m) \n", + "E=h*c*((1/lamda)-(1/lamda_dash)); #energy of recoil electron(joule)\n", + "x=h/(lamda*m0*c);\n", + "tanphi=lamda*math.sin(theta)/(lamda_dash-(lamda*math.cos(theta)));\n", + "phi=math.atan(tanphi); #direction of recoil electron(radian)\n", + "phi=phi*180/math.pi; #direction of recoil electron(degrees)\n", + "phim=60*(phi-int(phi)); #angle(minutes)\n", + "\n", + "#Result\n", + "print \"wavelength of scattered photon is\",round(lamda_dash*10**10,3),\"angstrom\"\n", + "print \"energy of recoil electron is\",round(E*10**17,1),\"*10**-17 joules\"\n", + "print \"direction of recoil electron is\",int(phi),\"degrees\",int(phim),\"minutes\"\n", + "print \"answer for angle given in the book is wrong\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 10, Page number 134" + ] + }, + { + "cell_type": "code", + "execution_count": 51, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "energy of scattered photon is 0.226 MeV\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "c=3*10**8; #velocity of light(m/sec)\n", + "e=1.6*10**-19; #charge(coulomb)\n", + "m0=9.1*10**-31; #mass(kg)\n", + "h=6.62*10**-34; #planks constant(Js)\n", + "theta=180*math.pi/180; #angle(radian)\n", + "E=1.96*10**6*e; #energy of scattered photon(J)\n", + "\n", + "#Calculations\n", + "lamda=h*c/E; #wavelength(m)\n", + "delta_lamda=2*h/(m0*c); \n", + "lamda_dash=lamda+delta_lamda; #wavelength of scattered photon(m) \n", + "Edash=h*c/(e*lamda_dash); #energy of scattered photon(eV)\n", + "\n", + "#Result\n", + "print \"energy of scattered photon is\",round(Edash/10**6,3),\"MeV\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example number 11, Page number 135" + ] + }, + { + "cell_type": "code", + "execution_count": 65, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "wavelength of scattered radiation is 4.9e-12 m\n", + "energy of recoil electron is 3.9592 *10**-14 Joules\n", + "direction of recoil electron is 27 degrees 47 minutes\n", + "answer for energy and direction of recoil electron and given in the book is wrong\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration \n", + "c=3*10**8; #velocity of light(m/sec)\n", + "e=1.6*10**-19; #charge(coulomb)\n", + "m0=9.1*10**-31; #mass(kg)\n", + "h=6.6*10**-34; #planks constant(Js)\n", + "theta=90*math.pi/180; #angle(radian)\n", + "E=500*10**3*e; #energy of scattered photon(J)\n", + "\n", + "#Calculations\n", + "lamda=h*c/E; #wavelength(m)\n", + "delta_lamda=h*(1-math.cos(theta))/(m0*c); \n", + "lamda_dash=lamda+delta_lamda; #wavelength of scattered radiation(m) \n", + "lamda_dash=round(lamda_dash*10**12,1)*10**-12; #wavelength of scattered radiation(m) \n", + "E=h*c*((1/lamda)-(1/lamda_dash)); #energy of recoil electron(J)\n", + "tanphi=lamda*math.sin(theta)/(lamda_dash-(lamda*math.cos(theta)));\n", + "phi=math.atan(tanphi); #direction of recoil electron(radian)\n", + "phi=phi*180/math.pi; #direction of recoil electron(degrees)\n", + "phim=60*(phi-int(phi)); #angle(minutes)\n", + "\n", + "#Result\n", + "print \"wavelength of scattered radiation is\",lamda_dash,\"m\"\n", + "print \"energy of recoil electron is\",round(E*10**14,4),\"*10**-14 Joules\"\n", + "print \"direction of recoil electron is\",int(round(phi)),\"degrees\",int(phim),\"minutes\"\n", + "print \"answer for energy and direction of recoil electron and given in the book is wrong\"" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} |