{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# 15: Compound Interest" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Example number 15.1, Page number 15.4" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "amount is 4410.0 Rs\n" ] } ], "source": [ "#importing modules\n", "import math\n", "from __future__ import division\n", "\n", "#Variable declaration\n", "P=4000; #principal(Rs)\n", "R=5; #rate(%)\n", "T=2; #time(yrs)\n", "n=1;\n", "\n", "#Calculation\n", "A=P*(1+(R/(100*n)))**(n*T); #amount(Rs)\n", "\n", "#Result\n", "print \"amount is\",A,\"Rs\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Example number 15.2, Page number 15.4" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "compound interest is 662.0 Rs\n" ] } ], "source": [ "#importing modules\n", "import math\n", "from __future__ import division\n", "\n", "#Variable declaration\n", "P=2000; #principal(Rs)\n", "R=10; #rate(%)\n", "T=3; #time(yrs)\n", "\n", "#Calculation\n", "x=R/100;\n", "y=(1+x)**T;\n", "CI=P*(y-1); #compound interest(Rs)\n", "\n", "#Result\n", "print \"compound interest is\",CI,\"Rs\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Example number 15.3, Page number 15.5" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "principal is 800.0 Rs\n" ] } ], "source": [ "#importing modules\n", "import math\n", "from __future__ import division\n", "\n", "#Variable declaration\n", "R=10; #rate(%)\n", "T=2; #time(yrs)\n", "A=968; #amount(Rs)\n", "\n", "#Calculation\n", "P=A/(1+(R/100))**T; #principal(Rs)\n", "\n", "#Result\n", "print \"principal is\",P,\"Rs\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Example number 15.4, Page number 15.5" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "compound interest is 4921.0 Rs\n" ] } ], "source": [ "#importing modules\n", "import math\n", "from __future__ import division\n", "\n", "#Variable declaration\n", "P=64000; #principal(Rs)\n", "R=2.5; #rate(%)\n", "T=3; #time(yrs)\n", "\n", "#Calculation\n", "x=R/100;\n", "y=(1+x)**T;\n", "CI=P*(y-1); #compound interest(Rs)\n", "\n", "#Result\n", "print \"compound interest is\",CI,\"Rs\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Example number 15.5, Page number 15.5" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "compound interest in 1st case is 122 Rs\n", "compound interest in 2nd case is 121.2 Rs\n", "answer given in the book is wrong\n", "compound interest in 3rd case is 119.0 Rs\n", "answer varies due to rounding off errors\n" ] } ], "source": [ "#importing modules\n", "import math\n", "from __future__ import division\n", "\n", "#Variable declaration\n", "P=2000; #principal(Rs)\n", "R=8; #rate(%)\n", "T=9/12; #time(yrs)\n", "n1=4;\n", "n2=2;\n", "n3=1;\n", "\n", "#Calculation\n", "A1=P*(1+(R/(100*n1)))**(n1*T); #amount(Rs)\n", "CI1=A1-P; #compound interest in 1st case(Rs)\n", "A2=P*(1+(R/(100*n2)))**(n2*T); #amount(Rs)\n", "CI2=A2-P; #compound interest in 2nd case(Rs)\n", "A3=P*(1+(R/(100*n3)))**(n3*T); #amount(Rs)\n", "CI3=A3-P; #compound interest in 3rd case(Rs)\n", "\n", "#Result\n", "print \"compound interest in 1st case is\",int(CI1),\"Rs\"\n", "print \"compound interest in 2nd case is\",round(CI2,1),\"Rs\"\n", "print \"answer given in the book is wrong\"\n", "print \"compound interest in 3rd case is\",round(CI3),\"Rs\"\n", "print \"answer varies due to rounding off errors\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Example number 15.6, Page number 15.6" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "sum is 31250.0 Rs\n" ] } ], "source": [ "#importing modules\n", "import math\n", "from __future__ import division\n", "\n", "#Variable declaration\n", "R=4; #rate(%)\n", "T=2; #time(yrs)\n", "CI_SI=50; #difference between CI and SI(Rs)\n", "\n", "#Calculation\n", "x=(R/100)**2;\n", "P=CI_SI/x; #sum(Rs)\n", "\n", "#Result\n", "print \"sum is\",P,\"Rs\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Example number 15.7, Page number 15.6" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "difference between CI and SI is 20.0 Rs\n" ] } ], "source": [ "#importing modules\n", "import math\n", "from __future__ import division\n", "\n", "#Variable declaration\n", "R=10; #rate(%)\n", "T=2; #time(yrs)\n", "P=2000; #sum(Rs)\n", "\n", "#Calculation\n", "x=(R/100)**2;\n", "CI_SI=P*x; #difference between CI and SI(Rs)\n", "\n", "#Result\n", "print \"difference between CI and SI is\",CI_SI,\"Rs\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Example number 15.8, Page number 15.7" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "rate per annum is 9.0 %\n", "sum is 1500.0 Rs\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", "CI=282.15; #compound interest(Rs)\n", "SI=270; #simple interest(Rs)\n", "T=2; #time(yrs)\n", "\n", "#Calculation\n", "R=(CI-SI)*100*T/SI; #rate per annum(%)\n", "P=100*SI/(R*T); #sum(Rs)\n", "\n", "#Result\n", "print \"rate per annum is\",R,\"%\"\n", "print \"sum is\",P,\"Rs\"\n", "print \"answer given in the book is wrong\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Example number 15.9, Page number 15.7" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "sum is 500.0 Rs\n" ] } ], "source": [ "#importing modules\n", "import math\n", "from __future__ import division\n", "\n", "#Variable declaration\n", "R=10; #rate(%)\n", "T=3; #time(yrs)\n", "CI_SI=31/2; #difference between CI and SI(Rs)\n", "\n", "#Calculation\n", "x=R/100;\n", "y=(x**3)+(T*(x**2));\n", "P=CI_SI/y; #sum(Rs) \n", "\n", "#Result\n", "print \"sum is\",P,\"Rs\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Example number 15.10, Page number 15.7" ] }, { "cell_type": "code", "execution_count": 26, "metadata": { "collapsed": false }, "outputs": [ { "ename": "ValueError", "evalue": "math domain error", "output_type": "error", "traceback": [ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[1;31mValueError\u001b[0m Traceback (most recent call last)", "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 11\u001b[0m \u001b[0mDr\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mb\u001b[0m\u001b[1;33m;\u001b[0m \u001b[1;31m#denominator of fraction\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 12\u001b[0m \u001b[0md\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mNr\u001b[0m\u001b[1;33m**\u001b[0m\u001b[1;36m2\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m-\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m4\u001b[0m\u001b[1;33m*\u001b[0m\u001b[0mDr\u001b[0m\u001b[1;33m*\u001b[0m\u001b[0mNr\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m;\u001b[0m \u001b[1;31m#discriminant\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 13\u001b[1;33m \u001b[0mq\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m-\u001b[0m\u001b[0mNr\u001b[0m\u001b[1;33m-\u001b[0m\u001b[0mmath\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msqrt\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0md\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m/\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m2\u001b[0m\u001b[1;33m*\u001b[0m\u001b[0mDr\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m;\u001b[0m \u001b[1;31m#solution\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 14\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 15\u001b[0m \u001b[1;31m#Result\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", "\u001b[1;31mValueError\u001b[0m: math domain error" ] } ], "source": [ "#importing modules\n", "import math\n", "from __future__ import division\n", "\n", "#Variable declaration\n", "a=434;\n", "b=272;\n", "\n", "#Calculation\n", "Nr=a-b; #numerator of fraction\n", "Dr=b; #denominator of fraction\n", "d=(Nr**2)-(4*Dr*Nr); #discriminant\n", "q=(-Nr-math.sqrt(d))/(2*Dr); #solution\n", "\n", "#Result\n", "print \"value of q is\",q\n", "print \"solution for the problem does not exist and the answer given in the book is wrong\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Example number 15.11, Page number 15.8" ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "annual payment is 18522.0 Rs\n" ] } ], "source": [ "#importing modules\n", "import math\n", "from __future__ import division\n", "\n", "#Variable declaration\n", "R=5; #rate(%)\n", "A=50440; #debt amount(Rs)\n", "T=3; #time(yrs)\n", "\n", "#Calculation\n", "x=100/(100+R);\n", "y=x*(1+x+(x**2));\n", "a=A/y; #annual payment(Rs)\n", "\n", "#Result\n", "print \"annual payment is\",a,\"Rs\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Example number 15.12, Page number 15.8" ] }, { "cell_type": "code", "execution_count": 15, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "time is 5.0 years\n" ] } ], "source": [ "#importing modules\n", "import math\n", "from __future__ import division\n", "\n", "#Variable declaration\n", "P=1; #assume\n", "A=1.44*P; #amount(Rs)\n", "T=2; #time(yrs)\n", "N=2;\n", "\n", "#Calculation\n", "R=(math.sqrt(A/P)-1)*100; #rate(%)\n", "T=(N-1)*100/R; #time(yrs)\n", "\n", "#Result\n", "print \"time is\",T,\"years\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Example number 15.13, Page number 15.8" ] }, { "cell_type": "code", "execution_count": 16, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "rate per annum is 6.0 %\n" ] } ], "source": [ "#importing modules\n", "import math\n", "from __future__ import division\n", "\n", "#Variable declaration\n", "I2=238.50; #interest in second year(Rs)\n", "I1=225; #interest in first year(Rs)\n", "T=1; #time(yrs)\n", "\n", "#Calculation\n", "I=I2-I1; #interest on 1 year(Rs)\n", "R=100*I/(I1*T); #rate per annum(%)\n", "\n", "#Result\n", "print \"rate per annum is\",R,\"%\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Example number 15.14, Page number 15.9" ] }, { "cell_type": "code", "execution_count": 17, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "sum is 8000.0 Rs\n" ] } ], "source": [ "#importing modules\n", "import math\n", "from __future__ import division\n", "\n", "#Variable declaration\n", "CI_SI=20; #difference for 2 years(Rs)\n", "CISI=61; #difference for 3 yrs(Rs)\n", "T1=2; #time(yrs)\n", "T2=3; #time(yrs)\n", "\n", "#Calculation\n", "R=((CISI/CI_SI)-T2)*100; #rate(%)\n", "P=CI_SI*(100/R)**2; #sum(Rs) \n", "\n", "#Result\n", "print \"sum is\",P,\"Rs\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Example number 15.15, Page number 15.9" ] }, { "cell_type": "code", "execution_count": 18, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "rate per annum is 10.0 %\n" ] } ], "source": [ "#importing modules\n", "import math\n", "from __future__ import division\n", "\n", "#Variable declaration\n", "T=3; #time(yrs)\n", "P=1000; #sum(Rs)\n", "A=1331; #amount(Rs)\n", "\n", "#Calculation\n", "x=(A/P)**(1/T);\n", "R=100*(x-1); #rate per annum(%)\n", "\n", "#Result\n", "print \"rate per annum is\",R,\"%\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Example number 15.16, Page number 15.9" ] }, { "cell_type": "code", "execution_count": 22, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "time is 1.5 years\n" ] } ], "source": [ "#importing modules\n", "import math\n", "from __future__ import division\n", "\n", "#Variable declaration\n", "P=64000; #sum(Rs)\n", "CI=4921; #compound interest(Rs)\n", "R=5; #rate(%)\n", "n=2;\n", "\n", "#Calculation\n", "A=P+CI; #amount(Rs)\n", "x=A/P;\n", "y=(1+(R/(100*n)))**n;\n", "T=math.log(x)/math.log(y); #time(years)\n", "\n", "#Result\n", "print \"time is\",T,\"years\"" ] } ], "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 }