{ "metadata": { "name": "", "signature": "sha256:4c0513ab1606f42cc2658f4efc57e03793ddba6911c2c7915b3159fc7138c6b8" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "heading", "level": 1, "metadata": {}, "source": [ "Chapter 26: Numerical Methods" ] }, { "cell_type": "heading", "level": 3, "metadata": {}, "source": [ "ILLUSTRATIVE EXAMPLE 26.8, Page number: 558" ] }, { "cell_type": "code", "collapsed": false, "input": [ "\n", "from __future__ import division\n", "from sympy import symbols,solve,log\n", "from math import exp\n", "\n", "#Variable Declaration:\n", "A,B,r,C = symbols('A B r C');\n", "\n", "#Calculation:\n", "res = solve([A + B*log(2)-log(3),A + B*log(4)-log(12)],[A,B])\n", "A = round(float(res[A]),4)\n", "B = round(float(res[B]))\n", "kA = round(exp(A),2)\n", "a = B\n", "\n", "#Result:\n", "print 'The equation for rate of reaction is: ',-r,'=',kA*C**a " ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "The equation for rate of reaction is: -r = 0.75*C**2.0\n" ] } ], "prompt_number": 9 }, { "cell_type": "heading", "level": 3, "metadata": {}, "source": [ "ILLUSTRATIVE EXAMPLE 26.9, Page number: 559" ] }, { "cell_type": "code", "collapsed": false, "input": [ "\n", "import scipy.stats as f\n", "\n", "#Variable Declaration:\n", "T = [-40,-20,0,10,12,30,40,50,60,80,100,150,200,250,300,400,500]\n", "u = [1.51,1.61,1.71,1.76,1.81,1.86,1.90,1.95,2.00,2.09,2.17,2.38,2.57,2.75,2.93,3.25,3.55]\n", "\n", "#Calculations:\n", "B,A,r_value, p_value, std_err = f.linregress(T,u)\n", "\n", "#Results:\n", "print 'The value of A in regression model is:',round(A,4)\n", "print 'The value of B in regression model is:',round(B,4)" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "The value of A in regression model is: 1.7484\n", "The value of B in regression model is: 0.0038\n" ] } ], "prompt_number": 10 }, { "cell_type": "heading", "level": 3, "metadata": {}, "source": [ "ILLUSTRATIVE EXAMPLE 26.11, Page number: 561" ] }, { "cell_type": "code", "collapsed": false, "input": [ "\n", "from __future__ import division\n", "from scipy.optimize import fmin_cobyla as optimize\n", "\n", "\n", "#Variable Declaration:\n", "def f(x):\t\n", " return -2.0*x[0] - 1.6*x[1]\n", "\n", "def c1(x):\n", " return 16820 - x[0]\n", "\n", "def c2(x):\n", " return 1152 - x[1]\n", "\n", "def c3(x):\n", " return 1500 - 0.08*x[0] - 0.11*x[1]\n", "\n", "def c4(x):\n", " return 6000 - 0.29*x[0] - 0.54*x[1]\n", "\n", "def c5(x):\n", " return 11000 - 0.63*x[0] - 0.35*x[1]\n", "\n", "def c6(x):\n", " return x[0]\n", "\n", "def c7(x):\n", " return x[1]\n", "\n", "#Calculation\n", "X = optimize(f,[16820,1152],[c1,c2,c3,c4,c5,c6], disp = 0)\n", "\n", "#Result:\n", "print \"Maximum Profit is $\",round(-f(X)), \"/day or $\", -365*f(X), \"/year\"" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "Maximum Profit is $ 35483.0 /day or $ 12951368.0 /year\n" ] } ], "prompt_number": 7 } ], "metadata": {} } ] }