summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTrupti Kini2016-02-27 23:30:09 +0600
committerTrupti Kini2016-02-27 23:30:09 +0600
commit4f7cbff441f0ed54667e973d0ad3913958135349 (patch)
tree8aab310483679c7229b6595f6b22d5c271fb1276
parent2eb56155ebc24ccecc3efc3e23740e0dfa7d2939 (diff)
downloadPython-Textbook-Companions-4f7cbff441f0ed54667e973d0ad3913958135349.tar.gz
Python-Textbook-Companions-4f7cbff441f0ed54667e973d0ad3913958135349.tar.bz2
Python-Textbook-Companions-4f7cbff441f0ed54667e973d0ad3913958135349.zip
Added(A)/Deleted(D) following books
A sample_notebooks/AnkitKumar/Ch16.ipynb A sample_notebooks/GauravMittal/Ch3.ipynb A sample_notebooks/Mohdarif/Ch21.ipynb
-rw-r--r--sample_notebooks/AnkitKumar/Ch16.ipynb364
-rw-r--r--sample_notebooks/GauravMittal/Ch3.ipynb373
-rw-r--r--sample_notebooks/Mohdarif/Ch21.ipynb725
3 files changed, 1462 insertions, 0 deletions
diff --git a/sample_notebooks/AnkitKumar/Ch16.ipynb b/sample_notebooks/AnkitKumar/Ch16.ipynb
new file mode 100644
index 00000000..86539c04
--- /dev/null
+++ b/sample_notebooks/AnkitKumar/Ch16.ipynb
@@ -0,0 +1,364 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter 16 : Electrical Energy & Capacitance"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 16.1 Page No : 533"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 22,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "The value of E = 4000.00 v/m\n"
+ ]
+ }
+ ],
+ "source": [
+ "v_bminusv_a=-12\n",
+ "d=0.3*10**-2#in m\n",
+ "E=-(v_bminusv_a)/d\n",
+ "print \"The value of E = %0.2f v/m\"%E"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 16.2 Page No : 533"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 3,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "solution a\n",
+ "Electric potential from A to B = -40000.00 V\n",
+ "solution b\n",
+ "Change in electric potential = -0.00 joules\n",
+ "velocity = 2768514.16 m/s\n"
+ ]
+ }
+ ],
+ "source": [
+ "from math import sqrt\n",
+ "print \"solution a\"\n",
+ "E=8*10**4#in V/m\n",
+ "d=0.5#in m\n",
+ "delta_V=-E*d\n",
+ "print \"Electric potential from A to B = %0.2f V\"%delta_V\n",
+ "print \"solution b\"\n",
+ "q=1.6*10**-19#in C\n",
+ "delta_PE=q*delta_V\n",
+ "print \"Change in electric potential = %0.2f joules\"%delta_PE\n",
+ "m_p=1.67*10**-27#in kg\n",
+ "vf=sqrt((2*-delta_PE)/m_p)\n",
+ "print \"velocity = %0.2f m/s\"%vf"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 16.3 Page No: 534"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 5,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Solution a\n",
+ "Magnitude of V1 = 112375.00 v\n",
+ "Magnitude of V2 = -35960.00 v\n",
+ "solution b\n",
+ "Magnitude of Vp = 76415.00 v\n",
+ "work done = 0.31 Joule\n"
+ ]
+ }
+ ],
+ "source": [
+ "k_e=8.99*10**9 #N.m**2/c**2\n",
+ "q1=5*10**-6# in C\n",
+ "q2=-2*10**-6#in C\n",
+ "r1=0.4\n",
+ "r2=0.5\n",
+ "V1=(k_e*q1)/(r1)\n",
+ "V2=(k_e*q2)/(r2)\n",
+ "print \"Solution a\"\n",
+ "print \"Magnitude of V1 = %0.2f v\"%V1\n",
+ "print \"Magnitude of V2 = %0.2f v\"%V2\n",
+ "print \"solution b\"\n",
+ "vp=V1+V2\n",
+ "print \"Magnitude of Vp = %0.2f v\"%vp\n",
+ "q3=4*10**-6#in C\n",
+ "w=vp*q3\n",
+ "print \"work done = %0.2f Joule\"%w"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 16.4 Page No: 535"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 9,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Capacitance = 1.77e-12 farad\n"
+ ]
+ }
+ ],
+ "source": [
+ "e0=8.85*10**-12#in c2/N.m2\n",
+ "A=2*10**-4#in m2\n",
+ "d=1*10**-3#in m\n",
+ "c=(e0*A)/d\n",
+ "print \"Capacitance = %0.2e farad\"%c"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 16.5 Page No : 535"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 11,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "capacitance = 4.50e-05 farad\n",
+ "voltage between battery = 2.16e-04 c\n"
+ ]
+ }
+ ],
+ "source": [
+ "c1=3*10**-6\n",
+ "c2=6*10**-6\n",
+ "c3=12*10**-6\n",
+ "c4=24*10**-6\n",
+ "delta_v=18\n",
+ "c_eq=c1+c2+c3+c4\n",
+ "print \"capacitance = %0.2e farad\"%c_eq\n",
+ "q=delta_v*c3\n",
+ "print \"voltage between battery = %0.2e c\"%q"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 16.6 Page No : 536"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 12,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "solution a\n",
+ "capacitance = 1.60e-06 farad\n",
+ "solution b\n",
+ "voltage between battery = 2.88e-05 c\n"
+ ]
+ }
+ ],
+ "source": [
+ "c1=3*10**-6\n",
+ "c2=6*10**-6\n",
+ "c3=12*10**-6\n",
+ "c4=24*10**-6\n",
+ "delta_v=18\n",
+ "print \"solution a\"\n",
+ "c_eq=1/((1/c1)+(1/c2)+(1/c3)+(1/c4))\n",
+ "print \"capacitance = %0.2e farad\"%c_eq\n",
+ "q=delta_v*c_eq\n",
+ "print \"solution b\"\n",
+ "print \"voltage between battery = %0.2e c\"%q"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 16.7 Page No: 536"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 13,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "solution a\n",
+ "capacitance = 2.00e-06 farad\n"
+ ]
+ }
+ ],
+ "source": [
+ "c1=4*10**-6\n",
+ "c2=4*10**-6\n",
+ "print \"solution a\"\n",
+ "c_eq=1/((1/c1)+(1/c2))\n",
+ "print \"capacitance = %0.2e farad\"%c_eq"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 16.8 Page No: 537"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 19,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "solution a\n",
+ "Energy stored = 4671 volt\n",
+ "solution b\n",
+ "power = 240000 watt\n"
+ ]
+ }
+ ],
+ "source": [
+ "Energy=1.2*10**3#in J\n",
+ "c=1.1*10**-4#in f\n",
+ "delta_v=sqrt((2*Energy)/c)\n",
+ "print \"solution a\"\n",
+ "print \"Energy stored = %0.f volt\"%delta_v\n",
+ "print \"solution b\"\n",
+ "Energy_deliverd=600#in j\n",
+ "delta_t=2.5*10**-3#in s\n",
+ "p=(Energy_deliverd)/delta_t\n",
+ "print \"power = %0.f watt\"%p"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 16.9 Page No: 538"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 21,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "solution a\n",
+ "Capacitance = 1.96e-11 farad\n",
+ "solution b\n",
+ "Voltage = 16000.0 volt\n",
+ "Maximum charge = 3.14e-07 columb\n"
+ ]
+ }
+ ],
+ "source": [
+ "k=3.7\n",
+ "e0=8.85*10**-12#in c2/N.m2\n",
+ "A=6*10**-4#in m2\n",
+ "d=1*10**-3#in m\n",
+ "c=(k*e0*A)/d\n",
+ "print \"solution a\"\n",
+ "print \"Capacitance = %0.2e farad\"%c\n",
+ "print \"solution b\"\n",
+ "E_max=16*10**6#in v/m\n",
+ "delta_v_max=E_max*d\n",
+ "print \"Voltage = %0.1f volt\"%delta_v_max\n",
+ "Q_max=delta_v_max*c\n",
+ "print \"Maximum charge = %0.2e columb\"%Q_max"
+ ]
+ }
+ ],
+ "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/sample_notebooks/GauravMittal/Ch3.ipynb b/sample_notebooks/GauravMittal/Ch3.ipynb
new file mode 100644
index 00000000..6e94dab7
--- /dev/null
+++ b/sample_notebooks/GauravMittal/Ch3.ipynb
@@ -0,0 +1,373 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter 3 - Properties of pure substances"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example: 3.1 Page: 88"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Example: 3.1 - Page: 88\n",
+ "\n",
+ "\n",
+ "Molar Volume of the gas is 1.29e-02 cubic metres\n"
+ ]
+ }
+ ],
+ "source": [
+ "print \"Example: 3.1 - Page: 88\\n\\n\"\n",
+ "\n",
+ "# Solution\n",
+ "\n",
+ "#*****Data*****\n",
+ "P = 2*10**5## [Pa]\n",
+ "T = 273 + 37## [K]\n",
+ "R = 8.314## [J/mol K]\n",
+ "#****************\n",
+ "# Since the gas behaves ideally:\n",
+ "V = R*T/P## [cubic metres]\n",
+ "print \"Molar Volume of the gas is %.2e cubic metres\"%(V)#"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example: 3.2 Page: 89"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 4,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Example: 3.2 - Page: 89\n",
+ "\n",
+ "\n",
+ "The pressure of air after compression is 1200 kPa\n",
+ "\n"
+ ]
+ }
+ ],
+ "source": [
+ "print \"Example: 3.2 - Page: 89\\n\\n\"\n",
+ "\n",
+ "# Solution\n",
+ "\n",
+ "#*****Data*****\n",
+ "V1 = 8## [cubic m]\n",
+ "P1 = 300## [kPa]\n",
+ "V2 = 2## [cubic m]\n",
+ "#**************\n",
+ "# Apptying the ideal gas Eqn. & since the Temperature remains constant:\n",
+ "P2 = P1*V1/V2## [kPa]\n",
+ "print \"The pressure of air after compression is %d kPa\\n\"%(P2)#"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example: 3.3 Page: 89"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 5,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Example: 3.3 - Page: 89\n",
+ "\n",
+ "\n",
+ "The pressure of the remaining air is 0 kPa\n",
+ "\n"
+ ]
+ }
+ ],
+ "source": [
+ "print \"Example: 3.3 - Page: 89\\n\\n\"\n",
+ "\n",
+ "# Solution\n",
+ "\n",
+ "#*****Data*****\n",
+ "V1 = 6## [cubic m]\n",
+ "P1 = 500## [kPa]\n",
+ "R = 0.287## [kJ/kg K]\n",
+ "#*************\n",
+ "# Applying the charectarstic equation to the gas initially:\n",
+ "# P1*V1 = m1*R*T1.......................................(i)\n",
+ "# Applying the charectarstic equation to the gas which was left in the vessel after one-fifth of the gas has been removed:\n",
+ "# P2*V2 = m2*R*T2.......................................(ii)\n",
+ "# V2 = V1# T2 = T1# m2 = (4/5)*m1# Eqn (ii) becomes:\n",
+ "# P2*V1 = (4/5)*m1*R*T1..................................(iii)\n",
+ "# Dividing eqn (i) by eqn (iii), we get:\n",
+ "P2 = (4/5)*P1## [kPa]\n",
+ "print \"The pressure of the remaining air is %d kPa\\n\"%(P2)#"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example: 3.4 Page: 90"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 6,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Example: 3.4 - Page: 90\n",
+ "\n",
+ "\n",
+ "Final Temperature of the air when the piston reaches stop is 361.5 K\n",
+ "\n",
+ "Pressure of air inside the cylinder is 2.51 bar\n",
+ "\n"
+ ]
+ }
+ ],
+ "source": [
+ "print \"Example: 3.4 - Page: 90\\n\\n\"\n",
+ "\n",
+ "# Solution\n",
+ "\n",
+ "#*****Data*****\n",
+ "T1 = 450 + 273## [K]\n",
+ "P1 = 3## [bar]\n",
+ "#***************\n",
+ "# Soluton(a)\n",
+ "# From Fig. 3.7, (Page 90)\n",
+ "# Since the weight remains the same, therefore, the final pressure is equal to the initial pressure.\n",
+ "# Therefore it is a constant pressure process.\n",
+ "P2 = P1## [bar]\n",
+ "# Volumetric Ratio:\n",
+ "V2_by_V1 = 2.5/(2.5 + 2.5)# Applying ideal gas law & P1 = P2\n",
+ "T2 = T1*V2_by_V1## [K]\n",
+ "print \"Final Temperature of the air when the piston reaches stop is %.1f K\\n\"%(T2)\n",
+ "# Solution (b)\n",
+ "# When the piston rests ot the stops, the pressure exerted by the weight, air & the atmosphere will be different. But there will beno further decrease in volume.\n",
+ "# This is a constant volume process.\n",
+ "T3 = 273 + 30## [K]\n",
+ "# Applying ideal gas law & V2 = V3\n",
+ "P3 = T3*P2/T2## [bar]\n",
+ "print \"Pressure of air inside the cylinder is %.2f bar\\n\"%(P3)#"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example: 3.5 Page: 95"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 7,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Example: 3.5 - Page: 95\n",
+ "\n",
+ "\n",
+ "The temperature at which ammonia exists in the cylinder is 321.5 K\n",
+ "\n"
+ ]
+ }
+ ],
+ "source": [
+ "print \"Example: 3.5 - Page: 95\\n\\n\"\n",
+ "\n",
+ "# Solution\n",
+ "\n",
+ "#*****Data*****\n",
+ "m = 1.373## [kg]\n",
+ "P = 1.95*10**(6)## [Pa]\n",
+ "V = 0.1## [cubic m]\n",
+ "a = 422.546*10**(-3)## [cubic m/square mol]\n",
+ "b = 37*10**(-6)## [cubic m/mol]\n",
+ "M = 17*10**(-3)## [kg/mol]\n",
+ "R = 8.314## [J/mol K]\n",
+ "#****************\n",
+ "n = m/M## [moles]\n",
+ "Vm = V/n## [molar volume, cubic m]\n",
+ "# Applying Van der Waals equation of state:\n",
+ "T = (P + (a/Vm**2))*((Vm - b)/R)## [K]\n",
+ "print \"The temperature at which ammonia exists in the cylinder is %.1f K\\n\"%(T)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example: 3.10 Page: 103"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 10,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Example: 3.10 - Page: 103\n",
+ "\n",
+ "\n",
+ "Value of derivative is 23.98 bar/OC\n",
+ "\n",
+ "The pressure generated by heating at constant Volume is 240.84 Pa\n",
+ "\n",
+ "The change in Volume is -0.038 cubic cm/g\n",
+ "\n"
+ ]
+ }
+ ],
+ "source": [
+ "from math import exp\n",
+ "print \"Example: 3.10 - Page: 103\\n\\n\"\n",
+ "\n",
+ "# Solution\n",
+ "\n",
+ "#*****Data*****\n",
+ "beeta = 1.487*10**(-3)## [1/OC]\n",
+ "alpha = 62*10**(-6)## [1/bar]\n",
+ "V1 = 1.287## [cubic cm /g]\n",
+ "#************\n",
+ "# Solution (a)\n",
+ "# The value of derivative (dP/dT) at constant V:\n",
+ "# dV/V = beeta*dT - alpha*dP\n",
+ "# dV = 0\n",
+ "# dP/dT = beeta/alpha\n",
+ "# Value = dP/dT\n",
+ "Value = beeta/alpha## [bar/OC]\n",
+ "print \"Value of derivative is %.2f bar/OC\\n\"%(Value)\n",
+ "# Solution (b)\n",
+ "P1 = 1## [bar]\n",
+ "T1 = 20## [OC]\n",
+ "T2 = 30## [OC]\n",
+ "# Applying the same equation:\n",
+ "P2 = P1 +(beeta/alpha)*(T2 - T1)## [bar]\n",
+ "print \"The pressure generated by heating at constant Volume is %.2f Pa\\n\"%(P2)\n",
+ "# Solution (c)\n",
+ "T2 = 0## [OC]\n",
+ "T1 = 20## [OC]\n",
+ "P2 = 10## [bar]\n",
+ "P1 = 1## [bar]\n",
+ "# The change in Volume can be obtained as:\n",
+ "V2 = V1*exp((beeta*(T2 - T1)) - alpha*(P2 - P1))## [cubic cm/g]\n",
+ "deltaV = V2 - V1## [cubic cm/g]\n",
+ "print \"The change in Volume is %.3f cubic cm/g\\n\"%(deltaV)#"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example: 3.11 Page: 107"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 14,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Example: 3.11 - Page: 107\n",
+ "\n",
+ "\n",
+ "Acentric factor is 0.6447\n"
+ ]
+ }
+ ],
+ "source": [
+ "from math import log10\n",
+ "print \"Example: 3.11 - Page: 107\\n\\n\"\n",
+ "\n",
+ "# Solution\n",
+ "\n",
+ "#*****Data*****\n",
+ "Tc = 513.9## [K]\n",
+ "Pc = 61.48*10**5## [Pa]\n",
+ "#************\n",
+ "Tr = 0.7\n",
+ "T = Tr*Tc - 273.15## [OC]\n",
+ "P_sat = 10**(8.112 - (1592.864/(T + 226.184)))## [mm Hg]\n",
+ "P_sat = P_sat*101325/760## [Pa]\n",
+ "Pr_sat = P_sat/Pc## [Pa]\n",
+ "omega = -1 - log10(Pr_sat)## [Acentric factor]\n",
+ "print \"Acentric factor is %.4f\"%(omega)#"
+ ]
+ }
+ ],
+ "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/sample_notebooks/Mohdarif/Ch21.ipynb b/sample_notebooks/Mohdarif/Ch21.ipynb
new file mode 100644
index 00000000..507735ab
--- /dev/null
+++ b/sample_notebooks/Mohdarif/Ch21.ipynb
@@ -0,0 +1,725 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter 21 Newtin-cotes integration formula"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Ex : 21.1 Pg : 612"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 5,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "The Error Et= 1.468\n",
+ "The percent relative error et= 89.467 %\n",
+ "The approximate error estimate without using the true value= 2.56\n"
+ ]
+ }
+ ],
+ "source": [
+ "from __future__ import division\n",
+ "def f(x):\n",
+ " y=(0.2+25*x-200*x**2+675*x**3-900*x**4+400*x**5)\n",
+ " return y\n",
+ "tval=1.640533#\n",
+ "a=0#\n",
+ "b=0.8#\n",
+ "fa=f(a)#\n",
+ "fb=f(b)#\n",
+ "l=(b-a)*((fa+fb)/2)#\n",
+ "Et=tval-l##error\n",
+ "et=Et*100/tval##percent relative error\n",
+ "\n",
+ "#by using approximate error estimate\n",
+ "\n",
+ "#the second derivative of f\n",
+ "def g(x):\n",
+ " y=-400+4050*x-10800*x**2+8000*x**3\n",
+ " return y\n",
+ "\n",
+ "from sympy.mpmath import quad\n",
+ "f2x=quad(g,[0,0.8])/(b-a)##average value of second derivative\n",
+ "Ea=-(1/12)*(f2x)*(b-a)**3#\n",
+ "print \"The Error Et=\",round(Et,3)\n",
+ "print \"The percent relative error et=\",round(et,3),\"%\"\n",
+ "print \"The approximate error estimate without using the true value=\",Ea"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Ex : 21.2 Pg : 613"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 7,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "The Error Et= 0.572\n",
+ "The percent relative error et= 34.85 %\n",
+ "The approximate error estimate without using the true value= 0.64\n"
+ ]
+ }
+ ],
+ "source": [
+ "def f(x):\n",
+ " y=(0.2+25*x-200*x**2+675*x**3-900*x**4+400*x**5)\n",
+ " return y\n",
+ "a=0#\n",
+ "b=0.8#\n",
+ "tval=1.640533#\n",
+ "n=2#\n",
+ "h=(b-a)/n#\n",
+ "fa=f(a)#\n",
+ "fb=f(b)#\n",
+ "fh=f(h)#\n",
+ "l=(b-a)*(fa+2*fh+fb)/(2*n)#\n",
+ "Et=tval-l##error\n",
+ "et=Et*100/tval##percent relative error\n",
+ "\n",
+ "#by using approximate error estimate\n",
+ "\n",
+ "#the second derivative of f\n",
+ "def g(x):\n",
+ " y=-400+4050*x-10800*x**2+8000*x**3\n",
+ " return y\n",
+ "f2x=quad(g,[0,0.8])/(b-a)##average value of second derivative\n",
+ "Ea=-(1/12)*(f2x)*(b-a)**3/(n**2)#\n",
+ "print \"The Error Et=\",round(Et,3)\n",
+ "print \"The percent relative error et=\",round(et,3),\"%\"\n",
+ "print \"The approximate error estimate without using the true value=\",Ea"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Ex :21.3 Pg : 614"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 13,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "No. of segments= 10\n",
+ "Segment size= 1.0\n",
+ "Estimated d= 288.749146143 m\n",
+ "0.237014701487 et(%)\n",
+ "---------------------------------------------------------\n",
+ "No. of segments= 20\n",
+ "Segment size= 0.5\n",
+ "Estimated d= 289.263574224 m\n",
+ "0.0592795228803 et(%)\n",
+ "---------------------------------------------------------\n",
+ "No. of segments= 50\n",
+ "Segment size= 0.2\n",
+ "Estimated d= 298.382319223 m\n",
+ "et(%) -3.09125177877\n",
+ "---------------------------------------------------------\n",
+ "No. of segments= 100\n",
+ "Segment size= 0.1\n",
+ "Estimated d= 293.915596452 m\n",
+ "et(%) -1.54799665905\n",
+ "---------------------------------------------------------\n",
+ "No. of segments= 100\n",
+ "Segment size= 0.1\n",
+ "Estimated d= 293.915596452 m\n",
+ "et(%) -1.54799665905\n",
+ "---------------------------------------------------------\n",
+ "No. of segments= 200\n",
+ "Segment size= 0.05\n",
+ "Estimated d= 289.43343055 m\n",
+ "et(%) 0.000594070904571\n",
+ "---------------------------------------------------------\n",
+ "No. of segments= 200\n",
+ "Segment size= 0.05\n",
+ "Estimated d= 289.43343055 m\n",
+ "et(%) 0.000594070904571\n",
+ "---------------------------------------------------------\n",
+ "No. of segments= 500\n",
+ "Segment size= 0.02\n",
+ "Estimated d= 290.332334709 m\n",
+ "et(%) -0.309977799375\n",
+ "---------------------------------------------------------\n",
+ "No. of segments= 1000\n",
+ "Segment size= 0.01\n",
+ "Estimated d= 289.883809248 m\n",
+ "et(%) -0.155012011658\n",
+ "---------------------------------------------------------\n",
+ "No. of segments= 2000\n",
+ "Segment size= 0.005\n",
+ "Estimated d= 289.435129352 m\n",
+ "et(%) 7.13401428866e-06\n",
+ "---------------------------------------------------------\n",
+ "No. of segments= 2000\n",
+ "Segment size= 0.005\n",
+ "Estimated d= 289.435129352 m\n",
+ "et(%) 7.13401428866e-06\n",
+ "---------------------------------------------------------\n",
+ "No. of segments= 5000\n",
+ "Segment size= 0.002\n",
+ "Estimated d= 289.435143766 m\n",
+ "et(%) 2.15393877364e-06\n",
+ "---------------------------------------------------------\n",
+ "No. of segments= 5000\n",
+ "Segment size= 0.002\n",
+ "Estimated d= 289.435143766 m\n",
+ "et(%) 2.15393877364e-06\n",
+ "---------------------------------------------------------\n",
+ "No. of segments= 10000\n",
+ "Segment size= 0.001\n",
+ "Estimated d= 289.480018962 m\n",
+ "et(%) -0.0155022506708\n",
+ "---------------------------------------------------------\n"
+ ]
+ }
+ ],
+ "source": [
+ "g=9.8##m/s**2# acceleration due to gravity\n",
+ "m=68.1##kg\n",
+ "c=12.5##kg/sec# drag coefficient\n",
+ "def f(t):\n",
+ " from numpy import exp\n",
+ " v=g*m*(1-exp(-c*t/m))/c\n",
+ " return v\n",
+ "tval=289.43515##m\n",
+ "a=0#\n",
+ "b=10#\n",
+ "fa=f(a)#\n",
+ "fb=f(b)#\n",
+ "from numpy import arange, exp\n",
+ "for i in arange(10,21,10):\n",
+ " n=i#\n",
+ " h=(b-a)/n#\n",
+ " print \"No. of segments=\",i\n",
+ " print \"Segment size=\",h\n",
+ " j=a+h#\n",
+ " s=0#\n",
+ " while j<b:\n",
+ " s=s+f(j)#\n",
+ " j=j+h#\n",
+ " \n",
+ " l=(b-a)*(fa+2*s+fb)/(2*n)#\n",
+ " Et=tval-l##error\n",
+ " et=Et*100/tval##percent relative error\n",
+ " print \"Estimated d=\",l,\"m\"\n",
+ " print et,\"et(%)\"\n",
+ " print \"---------------------------------------------------------\"\n",
+ "\n",
+ "for i in arange(50,101,50):\n",
+ " n=i#\n",
+ " h=(b-a)/n#\n",
+ " print \"No. of segments=\",i\n",
+ " print \"Segment size=\",h\n",
+ " j=a+h#\n",
+ " s=0#\n",
+ " while j<b:\n",
+ " s=s+f(j)#\n",
+ " j=j+h#\n",
+ " \n",
+ " l=(b-a)*(fa+2*s+fb)/(2*n)#\n",
+ " Et=tval-l##error\n",
+ " et=Et*100/tval##percent relative error\n",
+ " print \"Estimated d=\",l,\"m\"\n",
+ " print \"et(%)\",et\n",
+ " print \"---------------------------------------------------------\"\n",
+ "\n",
+ "for i in arange(100,201,100):\n",
+ " n=i#\n",
+ " h=(b-a)/n#\n",
+ " print \"No. of segments=\",i\n",
+ " print \"Segment size=\",h\n",
+ " j=a+h#\n",
+ " s=0#\n",
+ " while j<b:\n",
+ " s=s+f(j)#\n",
+ " j=j+h#\n",
+ " \n",
+ " l=(b-a)*(fa+2*s+fb)/(2*n)#\n",
+ " Et=tval-l##error\n",
+ " et=Et*100/tval##percent relative error\n",
+ " print \"Estimated d=\",l,\"m\"\n",
+ " print \"et(%)\",et\n",
+ " print \"---------------------------------------------------------\"\n",
+ "\n",
+ "for i in arange(200,501,300):\n",
+ " n=i#\n",
+ " h=(b-a)/n#\n",
+ " print \"No. of segments=\",i\n",
+ " print \"Segment size=\",h\n",
+ " j=a+h#\n",
+ " s=0#\n",
+ " while j<b:\n",
+ " s=s+f(j)#\n",
+ " j=j+h#\n",
+ " \n",
+ " l=(b-a)*(fa+2*s+fb)/(2*n)#\n",
+ " Et=tval-l##error\n",
+ " et=Et*100/tval##percent relative error\n",
+ " print \"Estimated d=\",l,\"m\"\n",
+ " print \"et(%)\",et\n",
+ " print \"---------------------------------------------------------\"\n",
+ "\n",
+ "for i in arange(1000,2001,1000):\n",
+ " n=i#\n",
+ " h=(b-a)/n#\n",
+ " print \"No. of segments=\",i\n",
+ " print \"Segment size=\",h\n",
+ " j=a+h#\n",
+ " s=0#\n",
+ " while j<b:\n",
+ " s=s+f(j)#\n",
+ " j=j+h#\n",
+ " \n",
+ " l=(b-a)*(fa+2*s+fb)/(2*n)#\n",
+ " Et=tval-l##error\n",
+ " et=Et*100/tval##percent relative error\n",
+ " print \"Estimated d=\",l,\"m\"\n",
+ " print \"et(%)\",et\n",
+ " print \"---------------------------------------------------------\"\n",
+ "\n",
+ "for i in arange(2000,5001,3000):\n",
+ " n=i#\n",
+ " h=(b-a)/n#\n",
+ " print \"No. of segments=\",i\n",
+ " print \"Segment size=\",h\n",
+ " j=a+h#\n",
+ " s=0#\n",
+ " while j<b:\n",
+ " s=s+f(j)#\n",
+ " j=j+h#\n",
+ " \n",
+ " l=(b-a)*(fa+2*s+fb)/(2*n)#\n",
+ " Et=tval-l##error\n",
+ " et=Et*100/tval##percent relative error\n",
+ " print \"Estimated d=\",l,\"m\"\n",
+ " print \"et(%)\",et\n",
+ " print \"---------------------------------------------------------\"\n",
+ "\n",
+ "for i in arange(5000,10001,5000):\n",
+ " n=i#\n",
+ " h=(b-a)/n#\n",
+ " print \"No. of segments=\",i\n",
+ " print \"Segment size=\",h\n",
+ " j=a+h#\n",
+ " s=0#\n",
+ " while j<b:\n",
+ " s=s+f(j)#\n",
+ " j=j+h#\n",
+ " \n",
+ " l=(b-a)*(fa+2*s+fb)/(2*n)#\n",
+ " Et=tval-l##error\n",
+ " et=Et*100/tval##percent relative error\n",
+ " print \"Estimated d=\",l,\"m\"\n",
+ " print \"et(%)\",et\n",
+ " print \"---------------------------------------------------------\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Ex : 21.4 Pg : 618"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 15,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "l= 1.37\n",
+ "The Error Et= 0.27\n",
+ "The percent relative error et= 16.645 %\n",
+ "The approximate error estimate without using the true value= 0.273\n"
+ ]
+ }
+ ],
+ "source": [
+ "def f(x):\n",
+ " y=(0.2+25*x-200*x**2+675*x**3-900*x**4+400*x**5)\n",
+ " return y\n",
+ "a=0#\n",
+ "b=0.8#\n",
+ "tval=1.640533#\n",
+ "n=2#\n",
+ "h=(b-a)/n#\n",
+ "fa=f(a)#\n",
+ "fb=f(b)#\n",
+ "fh=f(h)#\n",
+ "l=(b-a)*(fa+4*fh+fb)/(3*n)#\n",
+ "print\"l=\", round(l,2)\n",
+ "Et=tval-l##error\n",
+ "et=Et*100/tval##percent relative error\n",
+ "\n",
+ "#by using approximate error estimate\n",
+ "\n",
+ "#the fourth derivative of f\n",
+ "def g(x):\n",
+ " y=-21600+48000*x\n",
+ " return y\n",
+ "\n",
+ "f4x=quad(g,[0,0.8])/(b-a)##average value of fourth derivative\n",
+ "Ea=-(1/2880)*(f4x)*(b-a)**5#\n",
+ "print \"The Error Et=\",round(Et,2)\n",
+ "print \"The percent relative error et=\",round(et,3),\"%\"\n",
+ "print \"The approximate error estimate without using the true value=\",round(Ea,3)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Ex : 23.5 Pg : 620"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 16,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "l= 1.62\n",
+ "The Error Et= 0.02\n",
+ "The percent relative error et= 1.04 %\n",
+ "The approximate error estimate without using the true value= 0.017\n"
+ ]
+ }
+ ],
+ "source": [
+ "def f(x):\n",
+ " y=(0.2+25*x-200*x**2+675*x**3-900*x**4+400*x**5)\n",
+ " return y\n",
+ "a=0#\n",
+ "b=0.8#\n",
+ "tval=1.640533#\n",
+ "n=4#\n",
+ "h=(b-a)/n#\n",
+ "fa=f(a)#\n",
+ "fb=f(b)#\n",
+ "j=a+h#\n",
+ "s=0#\n",
+ "count=1#\n",
+ "while j<b:\n",
+ " if (-1)**count==-1:\n",
+ " s=s+4*f(j)#\n",
+ " else:\n",
+ " s=s+2*f(j)#\n",
+ " \n",
+ " count=count+1#\n",
+ " j=j+h#\n",
+ "\n",
+ "l=(b-a)*(fa+s+fb)/(3*n)#\n",
+ "print\"l=\", round(l,2)\n",
+ "Et=tval-l##error\n",
+ "et=Et*100/tval##percent relative error\n",
+ "\n",
+ "#by using approximate error estimate\n",
+ "\n",
+ "#the fou:rth derivative of f\n",
+ "def g(x):\n",
+ " y=-21600+48000*x\n",
+ " return y\n",
+ "f4x=quad(g,[0,0.8])/(b-a)##average value of fourth derivative\n",
+ "Ea=-(1/(180*4**4))*(f4x)*(b-a)**5#\n",
+ "print \"The Error Et=\",round(Et,2)\n",
+ "print \"The percent relative error et=\",round(et,3),\"%\"\n",
+ "print \"The approximate error estimate without using the true value=\",round(Ea,3)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Ex :23.6 Pg : 625"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 18,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Part A:\n",
+ "l= 1.519\n",
+ "The Error Et= 0.12\n",
+ "The percent relative error et= 7.398 %\n",
+ "The approximate error estimate without using the true value= 0.121\n",
+ "---------------------------------------------------\n",
+ "Part B:\n",
+ "l= 1.645\n",
+ "The Error Et= -0.005\n",
+ "The percent relative error et= -0.277 %\n"
+ ]
+ }
+ ],
+ "source": [
+ "def f(x):\n",
+ " y=(0.2+25*x-200*x**2+675*x**3-900*x**4+400*x**5)\n",
+ " return y\n",
+ "a=0#\n",
+ "b=0.8#\n",
+ "tval=1.640533#\n",
+ "#part a\n",
+ "n=3#\n",
+ "h=(b-a)/n#\n",
+ "fa=f(a)#\n",
+ "fb=f(b)#\n",
+ "j=a+h#\n",
+ "s=0#\n",
+ "count=1#\n",
+ "while j<b:\n",
+ " s=s+3*f(j)#\n",
+ " count=count+1#\n",
+ " j=j+h#\n",
+ "\n",
+ "l=(b-a)*(fa+s+fb)/(8)#\n",
+ "print \"Part A:\"\n",
+ "print \"l=\",round(l,3)\n",
+ "Et=tval-l##error\n",
+ "et=Et*100/tval##percent relative error\n",
+ "\n",
+ "#by using approximate error estimate\n",
+ "\n",
+ "#the fourth derivative of f\n",
+ "def g(x):\n",
+ " y=-21600+48000*x\n",
+ " return y\n",
+ "f4x=quad(g,[0,0.8])/(b-a)##average value of fourth derivative\n",
+ "Ea=-(1/6480)*(f4x)*(b-a)**5#\n",
+ "print \"The Error Et=\",round(Et,2)\n",
+ "print \"The percent relative error et=\",round(et,3),\"%\"\n",
+ "print \"The approximate error estimate without using the true value=\",round(Ea,3)\n",
+ "#part b\n",
+ "n=5#\n",
+ "h=(b-a)/n#\n",
+ "l1=(a+2*h-a)*(fa+4*f(a+h)+f(a+2*h))/6#\n",
+ "l2=(a+5*h-a-2*h)*(f(a+2*h)+3*(f(a+3*h)+f(a+4*h))+fb)/8#\n",
+ "l=l1+l2#\n",
+ "print \"---------------------------------------------------\"\n",
+ "print \"Part B:\"\n",
+ "print \"l=\", round(l,3)\n",
+ "Et=tval-l##error\n",
+ "et=Et*100/tval##percent relative error\n",
+ "print \"The Error Et=\", round(Et,3)\n",
+ "print \"The percent relative error et=\", round(et,3), \"%\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Ex : 23.7 Pg : 626"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 22,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "l= 1.59480096\n",
+ "The Error Et= 0.04573204\n",
+ "The percent relative error et= 2.78763304365 %\n"
+ ]
+ }
+ ],
+ "source": [
+ "def f(x):\n",
+ " y=(0.2+25*x-200*x**2+675*x**3-900*x**4+400*x**5)\n",
+ " return y\n",
+ "tval=1.640533#\n",
+ "x=[0, 0.12, 0.22, 0.32, 0.36, 0.4 ,0.44 ,0.54 ,0.64 ,0.7 ,0.8]\n",
+ "func=[]\n",
+ "for i in range(0,11):\n",
+ " func.append(f(x[i]))#\n",
+ "\n",
+ "l=0#\n",
+ "for i in range(0,10):\n",
+ " l=l+(x[i+1]-x[i])*(func[i]+func[i+1])/2#\n",
+ "\n",
+ "print \"l=\",l\n",
+ "Et=tval-l##error\n",
+ "et=Et*100/tval##percent relative error\n",
+ "print \"The Error Et=\",Et\n",
+ "print \"The percent relative error et=\",et,\"%\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Ex : 23.8 Pg : 230"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 23,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "l= 1.60364091733\n",
+ "The Error Et= 0.0368920826667\n",
+ "The percent relative error et= 2.2487863802 %\n"
+ ]
+ }
+ ],
+ "source": [
+ "def f(x):\n",
+ " y=(0.2+25*x-200*x**2+675*x**3-900*x**4+400*x**5)\n",
+ " return y\n",
+ "tval=1.640533#\n",
+ "x=[0, 0.12, 0.22, 0.32, 0.36, 0.4 ,0.44 ,0.54, 0.64, 0.7, 0.8]\n",
+ "func =[]\n",
+ "for i in range(0,11):\n",
+ " func.append(f(x[i]))\n",
+ "\n",
+ "l1=(x[1]-x[0])*((f(x[0])+f(x[1]))/2)#\n",
+ "l2=(x[3]-x[1])*(f(x[3])+4*f(x[2])+f(x[1]))/6#\n",
+ "l3=(x[6]-x[3])*(f(x[3])+3*(f(x[4])+f(x[5]))+f(x[6]))/8#\n",
+ "l4=(x[8]-x[6])*(f(x[6])+4*f(x[7])+f(x[8]))/6\n",
+ "l5=(x[9]-x[8])*((f(x[9])+f(x[8]))/2)#\n",
+ "l6=(x[10]-x[9])*((f(x[10])+f(x[9]))/2)#\n",
+ "l=l1+l2+l3+l4+l5+l6#\n",
+ "print \"l=\",l\n",
+ "Et=tval-l##error\n",
+ "et=Et*100/tval##percent relative error\n",
+ "print \"The Error Et=\",Et\n",
+ "print \"The percent relative error et=\",et,\"%\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Ex : 23.9 Pg : 629"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 25,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "The average termperature is= 53.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "def f(x,y):\n",
+ " t=2*x*y+2*x-x**2-2*y**2+72\n",
+ " return t\n",
+ "Len=8##m,length\n",
+ "wid=6##m,width\n",
+ "a=0#\n",
+ "b=Len#\n",
+ "n=2#\n",
+ "h=(b-a)/n#\n",
+ "a1=0#\n",
+ "b1=wid#\n",
+ "h1=(b1-a1)/n#\n",
+ "\n",
+ "fa=f(a,0)#\n",
+ "fb=f(b,0)#\n",
+ "fh=f(h,0)#\n",
+ "lx1=(b-a)*(fa+2*fh+fb)/(2*n)#\n",
+ "\n",
+ "fa=f(a,h1)#\n",
+ "fb=f(b,h1)#\n",
+ "fh=f(h,h1)#\n",
+ "lx2=(b-a)*(fa+2*fh+fb)/(2*n)#\n",
+ "\n",
+ "fa=f(a,b1)#\n",
+ "fb=f(b,b1)#\n",
+ "fh=f(h,b1)#\n",
+ "lx3=(b-a)*(fa+2*fh+fb)/(2*n)#\n",
+ "\n",
+ "l=(b1-a1)*(lx1+2*lx2+lx3)/(2*n)#\n",
+ "\n",
+ "avg_temp=l/(Len*wid)#\n",
+ "print\"The average termperature is=\", avg_temp"
+ ]
+ }
+ ],
+ "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
+}