{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Chapter 21 Series"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 21_1 pgno:256"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "6\n",
      "-2\n"
     ]
    }
   ],
   "source": [
    "\n",
    "#ex(1) 7,13,19,25....\n",
    "common_diff=19-13\n",
    "print 6\n",
    "#ex(2) 6,4,2,0,-2\n",
    "common_diff=2-4\n",
    "print -2\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 21_2 pgno:256"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "-22\n"
     ]
    }
   ],
   "source": [
    "\n",
    "#ex(1) in the series 7,10,13,.... the common difference is 3. 10th trerm is ?\n",
    "nth_term=('7+(n-1)*3')\n",
    "term10=7+(10-1)*3\n",
    "#ex(2) i the series 6,2,-2,-6,....and d=-4\n",
    "nth_term=('6-(n-1)*4')\n",
    "term8=6+(8-1)*-4\n",
    "print term8\n",
    " "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 21_3 pgno:256"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "('the five terms are 4,     ,20', 8, 12, 16)\n"
     ]
    }
   ],
   "source": [
    "\n",
    "#insert 3 A.M's between 4 and 20\n",
    "\n",
    "#let 4,a,b,c,20 are in A.P. using, l=a+(n-1)*d\n",
    "d=(20-4)/(5-1);\n",
    "a=4+d;\n",
    "b=a+d;\n",
    "c=b+d;\n",
    "print(\"the five terms are 4,     ,20\",a,b,c)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 21_4 pgno:258"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "d=1.5\n"
     ]
    }
   ],
   "source": [
    "\n",
    "#sum of A.P of 8 terms is 90.1st term is 6.\n",
    "\n",
    "# using s=n*{2*a+(n-1)*d}/2 \n",
    "#substituting given values\n",
    "d=0;\n",
    "for d in range(0,100):\n",
    "  if(90==8/2*(2*6 + (8-1)*d)):\n",
    "  \tprint d\n",
    "print 'd=1.5'\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 21_5 pgno:259"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " As root -10 is inadmissible, the solution is n=9\n"
     ]
    }
   ],
   "source": [
    "import numpy\n",
    "# using s=n*{2*a+(n-1)*d}/2 \n",
    "a=3;d=3;s=135;\n",
    "#substituting given values\n",
    "n=('n');\n",
    "p='n/2*(6 + (n-1)*3)-135';\n",
    "#n=numpy.roots(p)\n",
    "print(\"\\n As root -10 is inadmissible, the solution is n=9\")\n",
    " "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 21_6 pgno:261"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "common_ratio R\n"
     ]
    }
   ],
   "source": [
    "\n",
    "#ex(1).1,2,4,8,...\n",
    "commom_ratio=4/2\n",
    "#ex(2). 1,1/2,1/4,1/8,....\n",
    "common_ratio=(1./4.)/(1./2.)\n",
    "#ex(3). 2,-6,18,-54\n",
    "common_ratio=-6/2\n",
    "#ex(4). R,R^2,R^3,R^4....\n",
    "R=('R');\n",
    "common_ratio='R**2/R'\n",
    "print 'common_ratio',R\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 21_7 pgno:262"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " the seventh term of the series is  192\n"
     ]
    }
   ],
   "source": [
    "\n",
    "#7th term of the series 3,6,12,....\n",
    "\n",
    "#in the series r=2, so using the formula\n",
    "# nth term=a*r^(n-1) \n",
    "a=3;n=7;#given data\n",
    "term7=3*(2)**(7-1);\n",
    "print\"\\n the seventh term of the series is \",term7\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 21_8 pgno:262"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "('\\n the eighth term of the series is ', -4374)\n"
     ]
    }
   ],
   "source": [
    "\n",
    "#8th term of the series 2,-6,18,-54,......\n",
    "\n",
    "#in the series r=-3, so using the formula\n",
    "# nth term=a*r^(n-1) \n",
    "a=2;n=8;#given data\n",
    "term8=2*(-3)**(8-1);\n",
    "print(\"\\n the eighth term of the series is \",term8)\n",
    " "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 21_9 pgno:262"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " the fifth term of the series is \n",
      "\n",
      "15.752961\n"
     ]
    }
   ],
   "source": [
    "\n",
    "#5th term of the series.1st term is 100 and common ratio(r) is 0.63\n",
    "\n",
    "# using the formula\n",
    "#nth term=a*r^(n-1) \n",
    "a=100;n=0.63;#given data\n",
    "print\"\\n the fifth term of the series is \\n\"\n",
    "\n",
    "term5=100*0.63**(5-1)\n",
    "print term5\n",
    "#3rd term of G.P is 4.5 and 9th is 16.2\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 21_10 pgno:263"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " the common ratio is :\n",
      "\n",
      "1.238\n"
     ]
    }
   ],
   "source": [
    "\n",
    "# nth term=a*r^(n-1)\n",
    "term3=4.5;#given data\n",
    "#'a*r^(3-1)=4.5  ---equ(1)'\n",
    "term9=16.2;#given\n",
    "#'a*r^(9-1)=16.2 ---equ(2)'\n",
    "print(\"\\n the common ratio is :\\n\");\n",
    "\n",
    "r=(16.2/4.5)**(1./6.)#equ(2)/equ(1)\n",
    "print round(r,3)\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 21_11 pgno:265"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "substituting the given values \n",
      "64.34375\n"
     ]
    }
   ],
   "source": [
    "\n",
    "#sum of 7 terms of the series 2,3,4,5,....\n",
    "\n",
    "r=3./2.;a=2.;n=7.;#given\n",
    "#using the formula\n",
    "S=a*(r**(n)-1)/(r-1)\n",
    "print (\"substituting the given values \")\n",
    "\n",
    "print round(S,1)\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 21_12 pgno:265"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "172.0\n"
     ]
    }
   ],
   "source": [
    "\n",
    "#sum of 7 terms of the series 4,-8,16,....\n",
    "\n",
    "r=-8./4.;a=4;n=7;#given\n",
    "#using the formula\n",
    "S=a*(r**(n)-1)/(r-1)\n",
    "#substituting the values \n",
    "print S\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 21_13 pgno:270"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2.67\n"
     ]
    }
   ],
   "source": [
    "\n",
    "#sum to infinity series 2 + 1/2 + 1/8 + ......\n",
    "\n",
    "a=2;r=1./4.;#given\n",
    "#using the formula\n",
    "S_infinity=a/(1-r)\n",
    "print round(S_infinity,2)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 21_14 pgno:270"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "4.17\n"
     ]
    }
   ],
   "source": [
    "\n",
    "#sum to infinity series 5 - 1 + 1/5 - ......\n",
    "\n",
    "a=5;r=-1./5.;#given\n",
    "#using the formula\n",
    "S_infinity=a/(1-r)\n",
    "print round(S_infinity,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
}
