diff options
Diffstat (limited to 'Discrete_Mathematics_by_S_Lipschutz/3-Functions_and_Algorithms.ipynb')
-rw-r--r-- | Discrete_Mathematics_by_S_Lipschutz/3-Functions_and_Algorithms.ipynb | 146 |
1 files changed, 146 insertions, 0 deletions
diff --git a/Discrete_Mathematics_by_S_Lipschutz/3-Functions_and_Algorithms.ipynb b/Discrete_Mathematics_by_S_Lipschutz/3-Functions_and_Algorithms.ipynb new file mode 100644 index 0000000..82c3aae --- /dev/null +++ b/Discrete_Mathematics_by_S_Lipschutz/3-Functions_and_Algorithms.ipynb @@ -0,0 +1,146 @@ +{ +"cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Chapter 3: Functions and Algorithms" + ] + }, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 3.10: Polynomial_evaluation.sci" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"x = poly(0, 'x');\n", +"p = 2*x^3-7*x^2+4*x-15;\n", +"disp(p,'the polynomial is')\n", +"k=horner(p,5);\n", +"disp(k,'value of the polynomial at x=5 is')" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 3.11: Greatest_Common_Divisor.sci" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"V=int32([258,60]);\n", +"thegcd=gcd(V);\n", +"disp(thegcd,'the gcd of the two numbers 258 and 60 is')" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 3.8: Recursively_defined_functions.sci" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"function[k]=fact(a)\n", +"k=-1;\n", +"if(a<0|a>200)\n", +"disp('Invalid');\n", +"break;\n", +" else\n", +"if(a==1|a==0)\n", +"k=1;\n", +" else\n", +"k=a*fact(a-1);\n", +"end\n", +"end\n", +"endfunction\n", +"a=4;\n", +"p=fact(a);\n", +"disp(p,'the value of 4! is')" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 3.9: Cardinality.sci" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"x=1;\n", +"y=2;\n", +"z=3;\n", +"A=[x,y,z];\n", +"disp('cardinality of set A is:')\n", +"length(A) \n", +"B=[1,3,5,7,9]\n", +"disp('cardinality of set B is:')\n", +"length(B)\n", +"\n", +"// 3.9 (b)\n", +"disp('the set E has the following elements)\n", +"E=[2,4,6 %inf] //set E is the set of all positive even numbers and N is the set of all natural numbers\n", +"disp('function f:N to E is defined.So,E has the same cardinality as N')\n", +"disp('set E is countably infinite:')\n", +"for x=2:2:%inf\n", +"y=2*x;\n", +"disp(y)\n", +"end" + ] + } +], +"metadata": { + "kernelspec": { + "display_name": "Scilab", + "language": "scilab", + "name": "scilab" + }, + "language_info": { + "file_extension": ".sce", + "help_links": [ + { + "text": "MetaKernel Magics", + "url": "https://github.com/calysto/metakernel/blob/master/metakernel/magics/README.md" + } + ], + "mimetype": "text/x-octave", + "name": "scilab", + "version": "0.7.1" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} |