diff options
author | Prashant S | 2020-04-14 10:25:32 +0530 |
---|---|---|
committer | GitHub | 2020-04-14 10:25:32 +0530 |
commit | 06b09e7d29d252fb2f5a056eeb8bd1264ff6a333 (patch) | |
tree | 2b1df110e24ff0174830d7f825f43ff1c134d1af /Numerical_Methods_Principles_by_Analysis/1-Background_to_Numerical_Methods.ipynb | |
parent | abb52650288b08a680335531742a7126ad0fb846 (diff) | |
parent | 476705d693c7122d34f9b049fa79b935405c9b49 (diff) | |
download | all-scilab-tbc-books-ipynb-master.tar.gz all-scilab-tbc-books-ipynb-master.tar.bz2 all-scilab-tbc-books-ipynb-master.zip |
Initial commit
Diffstat (limited to 'Numerical_Methods_Principles_by_Analysis/1-Background_to_Numerical_Methods.ipynb')
-rw-r--r-- | Numerical_Methods_Principles_by_Analysis/1-Background_to_Numerical_Methods.ipynb | 1383 |
1 files changed, 1383 insertions, 0 deletions
diff --git a/Numerical_Methods_Principles_by_Analysis/1-Background_to_Numerical_Methods.ipynb b/Numerical_Methods_Principles_by_Analysis/1-Background_to_Numerical_Methods.ipynb new file mode 100644 index 0000000..31fa91f --- /dev/null +++ b/Numerical_Methods_Principles_by_Analysis/1-Background_to_Numerical_Methods.ipynb @@ -0,0 +1,1383 @@ +{ +"cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Chapter 1: Background to Numerical Methods" + ] + }, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 1.10: Conversion_to_Binary_System_and_to_Base_N.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"//Example 1.10\n", +"//Conversion to Binary System and to Base N\n", +"//Page no. 9\n", +"clc;close;clear;\n", +"\n", +"b=dec2bin(oct2dec('1753'))\n", +"disp(b,'Binary form of 1753 is ='); //inbuilt function\n", +"b=dec2hex(oct2dec('1753'))\n", +"disp(b,'Hexadecimal form of 1753 is ='); //inbuilt function\n", +"//conversion from octal to binary\n", +"b=dec2bin(hex2dec('A478'))\n", +"disp(b,'Binary form of A478 is ='); //inbuilt function\n", +"b=dec2oct(hex2dec('A478'))\n", +"disp(b,'Octal form of A478 is ='); //inbuilt function\n", +"//conversion from octal to binary\n", +"s=dec2bin(oct2dec('3'));\n", +"s1=dec2bin(oct2dec('154')); //inbuilt function\n", +"printf('\n Octal form of 3.154 is = \n\n %s.00%s',s,s1)\n", +"s=dec2hex(oct2dec('3'));\n", +"s1=dec2hex(oct2dec('154')); //inbuilt function\n", +"printf('\n\n Hexadecimal form of 3.154 is = \n\n %s.%s',s,s1)" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 1.13: 1s_compliment_and_2s_compliment.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"//Example 1.13\n", +"//1s compliment and 2s compliment\n", +"//Page no. 11\n", +"clc;close;clear;\n", +"\n", +"function [x1]=com1(x) //function for 1s compliment\n", +" for i=8:-1:1\n", +" x=x/10;\n", +" xd=x-fix(x)\n", +" if(floor((xd*10)+0.1)==1)\n", +" x1(1,i)=0;\n", +" else\n", +" x1(1,i)=1;\n", +" end\n", +" x=x-xd;\n", +" end\n", +"endfunction\n", +"function [x1]=com2(x) //function for 2s compliment()\n", +" for i=8:-1:1\n", +" x=x/10;\n", +" xd=x-fix(x)\n", +" if(int((xd*10)+0.1)==1)\n", +" x1(1,i)=0;\n", +" else\n", +" x1(1,i)=1;\n", +" end\n", +" end\n", +" for i=8:-1:1\n", +" if (x1(1,i)==0) then\n", +" x1(1,i)=1;\n", +" break;\n", +" else\n", +" x1(1,i)=0;\n", +" end\n", +" \n", +" end\n", +"endfunction\n", +"a=[00010011,01110110,11101101,10000001,10000000,00000000];\n", +"for i=1:6\n", +" printf('1s Compliment of %.8i=',a(i));\n", +" disp(com1(a(i)))\n", +" printf('2s Compliment of %.8i=',a(i));\n", +" disp(com2(a(i)))\n", +" printf('\n\n')\n", +"end" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 1.14: 1s_compliment.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"//Example 1.14\n", +"//1s compliment\n", +"//Page no. 12\n", +"clc;close;clear;\n", +"\n", +"function [x1]=com1(x) //function for 1s compliment\n", +" for i=8:-1:1\n", +" x=x/10;\n", +" xd=x-fix(x)\n", +" if(floor((xd*10)+0.1)==1)\n", +" x1(1,i)=0;\n", +" else\n", +" x1(1,i)=1;\n", +" end\n", +" x=x-xd;\n", +" end\n", +"endfunction\n", +"a=[00010011,01110110,11101101,10000001,10000000,00000000];\n", +"for i=1:6\n", +" printf('1s Compliment of %.8i=',a(i));\n", +" disp(com1(a(i)))\n", +" printf('\n\n')\n", +"end" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 1.15: Addition_and_Subtraction.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"//Example 1.15\n", +"//Addition and Subtraction\n", +"//Page no. 13\n", +"clc;clear;close;\n", +"function [x1]=add(x,y) //function for addition of binaries\n", +" c=0;\n", +" for i=1:10\n", +" x1(1,i)=0\n", +" end\n", +" for i=10:-1:1\n", +" x=x/10;\n", +" xd=x-fix(x)\n", +" x=x-xd;\n", +" y=y/10;\n", +" yd=y-fix(y)\n", +" y=y-yd;\n", +" if c==1 then\n", +" if floor((xd*10)+0.1)==1 & floor((yd*10)+0.1)==1 then\n", +" x1(1,i)=1;c=1;\n", +" elseif floor((xd*10)+0.1)==0 & floor((yd*10)+0.1)==0\n", +" x1(1,i)=1;c=0;\n", +" else\n", +" x1(1,i)=0;c=0;\n", +" end\n", +" else\n", +" if floor((xd*10)+0.1)==1 & floor((yd*10)+0.1)==1 then\n", +" x1(1,i)=0;c=1;\n", +" elseif floor((xd*10)+0.1)==0 & floor((yd*10)+0.1)==0\n", +" x1(1,i)=0;c=0;\n", +" else\n", +" x1(1,i)=1;c=0;\n", +" end\n", +" end\n", +" end\n", +" disp(x1,'Addition of 173 and 141= ')\n", +"endfunction\n", +"function [x1]=sub(x,y) //function for subtraction of binaries\n", +" c=0;\n", +" for i=1:10\n", +" x1(1,i)=0\n", +" end\n", +" for i=10:-1:1\n", +" x=x/10;\n", +" xd=x-fix(x)\n", +" x=x-xd;\n", +" y=y/10;\n", +" yd=y-fix(y)\n", +" y=y-yd;\n", +" if c==1 then\n", +" if floor((xd*10)+0.1)==0 & floor((yd*10)+0.1)==1 then\n", +" x1(1,i)=0;c=1;\n", +" elseif floor((xd*10)+0.1)==0 & floor((yd*10)+0.1)==0\n", +" x1(1,i)=1;c=0;\n", +" elseif floor((xd*10)+0.1)==1 & floor((yd*10)+0.1)==1\n", +" x1(1,i)=1;c=1;\n", +" elseif floor((xd*10)+0.1)==1 & floor((yd*10)+0.1)==0\n", +" x1(1,i)=0;c=0;\n", +" end\n", +" else\n", +" if floor((xd*10)+0.1)==1 & floor((yd*10)+0.1)==1 then\n", +" x1(1,i)=1;c=1;\n", +" elseif floor((xd*10)+0.1)==0 & floor((yd*10)+0.1)==0\n", +" x1(1,i)=0;c=0;\n", +" elseif floor((xd*10)+0.1)==1 & floor((yd*10)+0.1)==0\n", +" x1(1,i)=1;c=0;\n", +" elseif floor((xd*10)+0.1)==0 & floor((yd*10)+0.1)==1\n", +" x1(1,i)=1;c=1;\n", +" end\n", +" end\n", +" end\n", +" disp(x1,'Subtraction of 45 from 228= ')\n", +"endfunction\n", +"add(10101101,10001101)\n", +"sub(11100100,00101101)" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 1.16: Additio.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"//Example 1.16\n", +"//Addition\n", +"//Page no. 14\n", +"clc;close;clear;\n", +"\n", +"function [x1]=add(x,y) //function for addition of binaries\n", +" c=0;\n", +" printf('Addition of %.4i and %.4i= ',x,y)\n", +" for i=1:4\n", +" x1(1,i)=0\n", +" end\n", +" for i=4:-1:1\n", +" x=x/10;\n", +" xd=x-fix(x)\n", +" x=x-xd;\n", +" y=y/10;\n", +" yd=y-fix(y)\n", +" y=y-yd;\n", +" if c==1 then\n", +" if floor((xd*10)+0.1)==1 & floor((yd*10)+0.1)==1 then\n", +" x1(1,i)=1;c=1;\n", +" elseif floor((xd*10)+0.1)==0 & floor((yd*10)+0.1)==0\n", +" x1(1,i)=1;c=0;\n", +" else\n", +" x1(1,i)=0;c=1;\n", +" end\n", +" else\n", +" if floor((xd*10)+0.1)==1 & floor((yd*10)+0.1)==1 then\n", +" x1(1,i)=0;c=1;\n", +" elseif floor((xd*10)+0.1)==0 & floor((yd*10)+0.1)==0\n", +" x1(1,i)=0;c=0;\n", +" else\n", +" x1(1,i)=1;c=0;\n", +" end\n", +" end\n", +" end\n", +" \n", +" disp(x1)\n", +"endfunction\n", +"add(0010,0101);\n", +"add(1110,1011);\n", +"add(1110,0101);\n", +"add(0010,1011);\n", +"add(1110,0010);\n", +"add(0000,0000);" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 1.17: Additio.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"//Example 1.17\n", +"//Addition\n", +"//Page no. 14\n", +"clc;close;clear;\n", +"\n", +"function [x1]=add(x,y) //function for addition of binaries\n", +" c=0;\n", +" printf('Addition of %.4i and %.4i= ',x,y)\n", +" for i=1:5\n", +" x1(1,i)=0\n", +" end\n", +" for i=5:-1:1\n", +" x=x/10;\n", +" xd=x-fix(x)\n", +" x=x-xd;\n", +" y=y/10;\n", +" yd=y-fix(y)\n", +" y=y-yd;\n", +" if c==1 then\n", +" if floor((xd*10)+0.1)==1 & floor((yd*10)+0.1)==1 then\n", +" x1(1,i)=1;c=1;\n", +" elseif floor((xd*10)+0.1)==0 & floor((yd*10)+0.1)==0\n", +" x1(1,i)=1;c=0;\n", +" else\n", +" x1(1,i)=0;c=1;\n", +" end\n", +" else\n", +" if floor((xd*10)+0.1)==1 & floor((yd*10)+0.1)==1 then\n", +" x1(1,i)=0;c=1;\n", +" elseif floor((xd*10)+0.1)==0 & floor((yd*10)+0.1)==0\n", +" x1(1,i)=0;c=0;\n", +" else\n", +" x1(1,i)=1;c=0;\n", +" end\n", +" end\n", +" end\n", +" \n", +" disp(x1)\n", +"endfunction\n", +"\n", +"add(0010,0101);\n", +"add(1101,1010);\n", +"add(1101,0101);\n", +"add(0010,1010);\n", +"add(1101,0010);\n", +"add(1111,0000);" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 1.18: Additio.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"//Example 1.18\n", +"//Addition\n", +"//Page no. 15\n", +"clc;close;clear;\n", +"\n", +"function [x1]=add(x,y) //function for addition of binaries\n", +" c=0;\n", +" printf('Addition of %.4i and %.4i= ',x,y)\n", +" for i=1:5\n", +" x1(1,i)=0\n", +" end\n", +" for i=5:-1:1\n", +" x=x/10;\n", +" xd=x-fix(x)\n", +" x=x-xd;\n", +" y=y/10;\n", +" yd=y-fix(y)\n", +" y=y-yd;\n", +" if c==1 then\n", +" if floor((xd*10)+0.1)==1 & floor((yd*10)+0.1)==1 then\n", +" x1(1,i)=1;c=1;\n", +" elseif floor((xd*10)+0.1)==0 & floor((yd*10)+0.1)==0\n", +" x1(1,i)=1;c=0;\n", +" else\n", +" x1(1,i)=0;c=1;\n", +" end\n", +" else\n", +" if floor((xd*10)+0.1)==1 & floor((yd*10)+0.1)==1 then\n", +" x1(1,i)=0;c=1;\n", +" elseif floor((xd*10)+0.1)==0 & floor((yd*10)+0.1)==0\n", +" x1(1,i)=0;c=0;\n", +" else\n", +" x1(1,i)=1;c=0;\n", +" end\n", +" end\n", +" end\n", +" \n", +" disp(x1)\n", +"endfunction\n", +"\n", +"add(0100,0101);\n", +"add(1100,1011);\n", +"add(1000,1000);" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 1.19: Additio.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"//Example 1.19\n", +"//Addition\n", +"//Page no. 15\n", +"clc;close;clear;\n", +"\n", +"function [x1]=add(x,y) //function for addition of binaries\n", +" c=0;\n", +" printf('Addition of %.4i and %.4i= ',x,y)\n", +" for i=1:5\n", +" x1(1,i)=0\n", +" end\n", +" for i=5:-1:1\n", +" x=x/10;\n", +" xd=x-fix(x)\n", +" x=x-xd;\n", +" y=y/10;\n", +" yd=y-fix(y)\n", +" y=y-yd;\n", +" if c==1 then\n", +" if floor((xd*10)+0.1)==1 & floor((yd*10)+0.1)==1 then\n", +" x1(1,i)=1;c=1;\n", +" elseif floor((xd*10)+0.1)==0 & floor((yd*10)+0.1)==0\n", +" x1(1,i)=1;c=0;\n", +" else\n", +" x1(1,i)=0;c=1;\n", +" end\n", +" else\n", +" if floor((xd*10)+0.1)==1 & floor((yd*10)+0.1)==1 then\n", +" x1(1,i)=0;c=1;\n", +" elseif floor((xd*10)+0.1)==0 & floor((yd*10)+0.1)==0\n", +" x1(1,i)=0;c=0;\n", +" else\n", +" x1(1,i)=1;c=0;\n", +" end\n", +" end\n", +" end\n", +" \n", +" disp(x1)\n", +"endfunction\n", +"\n", +"add(0010,0101);\n", +"add(11110,11011);\n", +"add(1000,0101);\n", +"add(00010,11011);\n", +"add(11110,00010);\n", +"add(11111,0000);" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 1.1: Conversion_to_Decimal_System.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"//Example 1.1\n", +"//Conversion to Decimal System\n", +"//Page no. 4\n", +"clc;close;clear;\n", +"function [s]=bas2dec(x,b)\n", +" xi=int(x)\n", +" xd=x-int(x)\n", +" s=0\n", +" for i=1:10\n", +" xi=xi/10\n", +" s=s+(10*(xi-fix(xi))*b^(i-1))\n", +" xi=int(xi)\n", +" if(xi==0)\n", +" break\n", +" end\n", +" end\n", +" for i=1:1\n", +" xd=xd*10;\n", +" s=s+(ceil(xd)/b^(i))\n", +" xd=xd-fix(xd)\n", +" if(xd==0)\n", +" break\n", +" end\n", +" end\n", +"endfunction\n", +"\n", +"//conversion from hexadecimal to decimal system\n", +"disp(hex2dec('1A2C'),'1A2C='); //inbuit function\n", +"\n", +"//conversion from hexadecimal to decimal system\n", +"disp(bas2dec(428.5,8),'428.5=') //inline function\n", +"\n", +"//conversion from hexadecimal to decimal system\n", +"disp(bas2dec(120.1,3),'120.1=') //inline function" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 1.20: Subtractio.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"//Example 1.20\n", +"//Subtraction\n", +"//Page no. 16\n", +"clc;close;clear;\n", +"function [x1]=add(x,y) //function for addition of binaries\n", +" c=0;\n", +" for i=1:5\n", +" x1(1,i)=0\n", +" end\n", +" for i=5:-1:1\n", +" x=x/10;\n", +" xd=x-fix(x)\n", +" x=x-xd;\n", +" y=y/10;\n", +" yd=y-fix(y)\n", +" y=y-yd;\n", +" if c==1 then\n", +" if floor((xd*10)+0.1)==1 & floor((yd*10)+0.1)==1 then\n", +" x1(1,i)=1;c=1;\n", +" elseif floor((xd*10)+0.1)==0 & floor((yd*10)+0.1)==0\n", +" x1(1,i)=1;c=0;\n", +" else\n", +" x1(1,i)=0;c=0;\n", +" end\n", +" else\n", +" if floor((xd*10)+0.1)==1 & floor((yd*10)+0.1)==1 then\n", +" x1(1,i)=0;c=1;\n", +" elseif floor((xd*10)+0.1)==0 & floor((yd*10)+0.1)==0\n", +" x1(1,i)=0;c=0;\n", +" else\n", +" x1(1,i)=1;c=0;\n", +" end\n", +" end\n", +" end\n", +" disp(x1,'Addition of 173 and 141= ')\n", +"endfunction\n", +"\n", +"add(0100,1011);\n", +"add(1100,0101);\n", +"add(1000,1000);" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 1.23: Multiplicatio.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"//Example 1.23\n", +"//Multiplication\n", +"//Page no. 18\n", +"clc;clear;close;\n", +"\n", +"function [x1]=mul(x,y)\n", +" for i=1:8\n", +" x1(1,i)=0\n", +" end\n", +" printf('Multiplication of %.4i and %.4i = ',x,y)\n", +" x=x*y;\n", +" c=0;\n", +" for i=8:-1:1\n", +" x=x/10;\n", +" xd=floor((x-fix(x))*10+0.1)\n", +" if c==1 then\n", +" if xd==0 then\n", +" x1(1,i)=1;c=0\n", +" elseif xd==1\n", +" x1(1,i)=0;\n", +" c=1;\n", +" elseif xd==2\n", +" x1(1,i)=1;c=1;\n", +" end\n", +" else\n", +" if xd==0 | xd==1 then\n", +" x1(1,i)=xd;c=0\n", +" elseif xd==2\n", +" x1(1,i)=0;\n", +" i=i-1;c=1;\n", +" end\n", +" end\n", +" end\n", +" disp(x1)\n", +"endfunction\n", +"mul(1110,1011);" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 1.24: Multiplicatio.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"//Example 1.24\n", +"//Multiplication\n", +"//Page no. 18\n", +"clc;clear;close;\n", +"\n", +"function [x1]=mul(x,y)\n", +" for i=1:8\n", +" x1(1,i)=0\n", +" end\n", +" printf('Multiplication of %.4i and %.4i = ',x,y)\n", +" x=x*y;\n", +" c=0;\n", +" for i=8:-1:1\n", +" x=x/10;\n", +" xd=floor((x-fix(x))*10+0.1)\n", +" if c==1 then\n", +" if xd==0 then\n", +" x1(1,i)=1;c=0\n", +" elseif xd==1\n", +" x1(1,i)=0;\n", +" c=1;\n", +" elseif xd==2\n", +" x1(1,i)=1;c=1;\n", +" end\n", +" else\n", +" if xd==0 | xd==1 then\n", +" x1(1,i)=xd;c=0\n", +" elseif xd==2\n", +" x1(1,i)=0;\n", +" i=i-1;c=1;\n", +" end\n", +" end\n", +" end\n", +" disp(x1)\n", +"endfunction\n", +"mul(1110,1011);" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 1.25: Divisio.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"//Example 1.25\n", +"//Division\n", +"//Page no. 19\n", +"clc;close;clear;\n", +"function [co]=com(x,y)\n", +" co=1;\n", +" for i=1:length(x)\n", +" if x(i)>y(i) then\n", +" break\n", +" elseif x(i)==y(i)\n", +" continue\n", +" else\n", +" co=0;break\n", +" end\n", +" end\n", +"endfunction\n", +"function [x1]=sub(x,y) //function for subtraction of binaries\n", +" c=0;m=0;\n", +" for i=1:5\n", +" x1(1,i)=0\n", +" end\n", +" for i=5:-1:1\n", +" if c==1 then\n", +" if x(i)==0 & y(i)==1 then\n", +" x1(1,i)=0;c=1;\n", +" elseif x(i)==0 & y(i)==0\n", +" x1(1,i)=1;c=0;\n", +" elseif x(i)==1 & y(i)==1\n", +" x1(1,i)=1;c=1;\n", +" elseif x(i)==1 & y(i)==0\n", +" x1(1,i)=0;c=0;\n", +" end\n", +" else\n", +" if x(i)==1 & y(i)==1 then\n", +" x1(1,i)=0;c=0;\n", +" elseif x(i)==0 & y(i)==0\n", +" x1(1,i)=0;c=0;\n", +" elseif x(i)==1 & y(i)==0\n", +" x1(1,i)=1;c=0;\n", +" elseif x(i)==0 & y(i)==1\n", +" x1(1,i)=1;c=1;\n", +" end\n", +" end\n", +" end\n", +" disp(x1,'Remainder = ')\n", +"endfunction\n", +"d1=11011001;d2=01011;d22=[0,0,0,0,0]\n", +"for i=8:-1:1\n", +" d3=d1/10;\n", +" div(1,i)=int(10*(d3-int(d3)))\n", +" d1=d1/10\n", +"end\n", +"for i=5:-1:1\n", +" d3=d2/10;\n", +" d21(1,i)=int(10*(d3-int(d3))+0.5)\n", +" d2=d2/10\n", +"end\n", +"div1(1,1)=0\n", +"for j=1:4\n", +" div1(1,j+1)=div(1,j)\n", +"end\n", +"for i1=1:5\n", +" printf('After Step %i : \n',i1)\n", +" if com(div1,d21)==1 then\n", +" dis(1,i1)=1\n", +" n=sub(div1,d21)\n", +" else\n", +" dis(1,i1)=0\n", +" n=sub(div1,d22)\n", +"end\n", +"disp(dis,'Divisor = ')\n", +"if i1==5 then\n", +" break\n", +"end\n", +" for j=1:5\n", +" if j<5 then\n", +" div1(1,j)=n(j+1)\n", +" else\n", +" div1(1,j)=div(1,i1+4)\n", +" end\n", +" end\n", +"\n", +"printf('\n\n\n\n')\n", +"end" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 1.26: Multiplicatio.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"//Example 1.26\n", +"//Multiplication\n", +"//Page no. 19\n", +"clc;clear;close;\n", +"\n", +"\n", +"function [x1]=mul(x,y)\n", +" for i=1:8\n", +" x1(1,i)=0\n", +" end\n", +" printf('Multiplication of %.4i and %.4i = ',x,y)\n", +" x=x*y;\n", +" c=0;\n", +" for i=10:-1:1\n", +" x=x/10;\n", +" xd=floor((x-fix(x))*10+0.1)\n", +" if c==1 then\n", +" if xd==0 then\n", +" x1(1,i)=1;c=0\n", +" elseif xd==1\n", +" x1(1,i)=0;\n", +" c=1;\n", +" elseif xd==2\n", +" x1(1,i)=1;c=1;\n", +" end\n", +" else\n", +" if xd==0 | xd==1 then\n", +" x1(1,i)=xd;c=0\n", +" elseif xd==2\n", +" x1(1,i)=0;\n", +" i=i-1;c=1;\n", +" end\n", +" end\n", +" end\n", +" for i=1:10\n", +" if x1(1,i)==1 then\n", +" x1(1,i-1)=1;\n", +" break\n", +" end\n", +" end\n", +" disp(x1)\n", +"endfunction\n", +"mul(1110,1011);" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 1.29: Normalized_Floating_Point_Representation.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"//Example 1.29\n", +"//Normalized Floating Point Representation\n", +"//Page no. 23\n", +"clc;clear;close;\n", +"\n", +"function []=fp(x)\n", +" x1=x;\n", +" if x>0 then\n", +" for i=1:10\n", +" x=x/10\n", +" if int(x)==0 then\n", +" break\n", +" end\n", +" end\n", +" printf('\n %i\nNormalized Floating Point Representation of %g = %.4f x 10',i,x1,x)\n", +" else\n", +" for i=1:10\n", +" x=x*10\n", +" if ceil(x)~=0 then\n", +" break\n", +" end\n", +" end\n", +" x=x/10;i=i-1;\n", +" printf('\n -%i\nNormalized Floating Point Representation of %g = %.4f x 10',i,x1,x)\n", +" end\n", +" \n", +"endfunction\n", +"\n", +"x=[25.12,-0.00287,87000];\n", +"for i=1:3\n", +" fp(x(i))\n", +"end" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 1.2: Conversion_Using_Shortcut_Method.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"//Example 1.2\n", +"//Conversion Using Shortcut Method\n", +"//Page no. 4\n", +"clc;close;clear;\n", +"A=10;C=12;\n", +"d=(((1)*16+A)*16+2)*16+C;\n", +"disp(d,'Decimal form of 1A2C is =');" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 1.30: Add.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"//Example 1.30\n", +"//Add\n", +"//Page no. 26\n", +"clc;clear;close;\n", +"a=0.4532e7;b=0.5427e7;\n", +"c=a+b\n", +"printf('Addition of %.6g and %.6g = %.6g',a,b,c)" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 1.31: Add.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"//Example 1.31\n", +"//Add\n", +"//Page no. 26\n", +"clc;clear;close;\n", +"a=0.4532e5;b=0.5427e7;\n", +"c=a+b\n", +"printf('Addition of %.4g and %.6g = %.6g',a,b,c)" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 1.32: Add.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"//Example 1.32\n", +"//Add\n", +"//Page no. 26\n", +"clc;clear;close;\n", +"a=0.4532e3;b=0.5427e7;\n", +"c=a+b\n", +"printf('Addition of %.2g and %.6g = %.4g',a,b,c)" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 1.33: Add.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"//Example 1.33\n", +"//Add\n", +"//Page no. 27\n", +"clc;clear;close;\n", +"a=[0.4632e3,0.4632e99];b=[0.5427e3,0.5427e99];\n", +"\n", +"for i=1:2\n", +" c(i)=a(i)+b(i)\n", +" printf('\nAddition of %.2g and %.2g = %.5g\n',a(i),b(i),c(i))\n", +"end" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 1.34: Subtractio.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"//Example 1.34\n", +"//Subtraction\n", +"//Page no. 27\n", +"clc;clear;close;\n", +"a=[0.5427e-3,0.9627e4,0.9627e-99];b=[0.9632e-4,0.9622e4,0.9622e-99];\n", +"for i=1:3\n", +" c(i)=a(i)-b(i)\n", +" printf('\nSubtraction of %.2g from %.3g = %.6g\n',a(i),b(i),c(i))\n", +"end" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 1.35: Multiplicatio.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"//Example 1.35\n", +"//Multiplication\n", +"//Page no. 28\n", +"clc;clear;close;\n", +"a=[0.9632e12,0.1132e12,0.1132e52,0.1132e-52];b=[0.5427e-15,0.1027e15,0.1027e50,0.1027e-50];\n", +"for i=1:4\n", +" c(i)=a(i)*b(i)\n", +" printf('\nMultiplication of %.3g and %.2g = %.6g\n',a(i),b(i),c(i))\n", +"end" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 1.36: Divisio.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"//Example 1.36\n", +"//Division\n", +"//Page no. 28\n", +"clc;clear;close;\n", +"a=[0.1132e1,0.1132e-6,0.1132e6];b=[0.1000e-99,0.1000e99,0.1000e3];\n", +"for i=1:3\n", +" c(i)=a(i)/b(i)\n", +" printf('\nDivision of %.2g by %.3g= %.3g\n',a(i),b(i),c(i))\n", +"end" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 1.3: Conversion_to_Base_B_from_Decimal_System.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"//Example 1.3\n", +"//Conversion to Base B from Decimal System\n", +"//Page no. 5\n", +"clc;close;clear;\n", +"//conversion from binary to octal\n", +"disp(dec2oct(bin2dec('10101101110')),'Octal form of 10101101110 is ='); //inbuilt function\n", +"\n", +"//conversion from binary to hexadecimal\n", +"disp(dec2hex(bin2dec('10101101110')),'Hexadecimal form of 10101101110 is ='); //inbuilt function\n", +"\n", +"//conversion from binary to octal\n", +"s=dec2oct(bin2dec('1011'));\n", +"s1=dec2oct(bin2dec('110011010100')); //inbuilt function\n", +"printf('\n Octal form of 1011.1100110101 is = \n\n %s.%s',s,s1)\n", +"\n", +"//conversion from binary to hexadecimal\n", +"s=dec2hex(bin2dec('1011'));\n", +"s1=dec2hex(bin2dec('110011010100')); //inbuilt function\n", +"printf('\n\n Hexadecimal form of 1011.1100110101 is = \n\n %s.%s',s,s1)" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 1.4: Conversion_to_Binary_System.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"//Example 1.4\n", +"//Conversion to Binary System\n", +"//Page no. 6\n", +"clc;close;clear;\n", +"//conversion from octal to binary\n", +"disp(dec2bin(oct2dec('1753')),'Binary form of 1753 is ='); //inbuilt function\n", +"\n", +"//conversion from octal to binary\n", +"disp(dec2bin(hex2dec('A478')),'Binary form of A478 is ='); //inbuilt function\n", +"\n", +"//conversion from octal to binary\n", +"s=dec2bin(oct2dec('3'));\n", +"s1=dec2bin(oct2dec('154')); //inbuilt function\n", +"printf('\n Octal form of 3.154 is = \n\n %s.00%s',s,s1)" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 1.5: Conversion_to_Binary_System.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"//Example 1.5\n", +"//Conversion to Binary System\n", +"//Page no. 6\n", +"clc;close;clear;\n", +"//conversion from octal to binary\n", +"b=dec2bin(oct2dec('1753'))\n", +"disp(b,'Binary form of 1753 is ='); //inbuilt function\n", +"b=dec2hex(oct2dec('1753'))\n", +"disp(b,'Hexadecimal form of 1753 is ='); //inbuilt function\n", +"//conversion from octal to binary\n", +"b=dec2bin(hex2dec('A478'))\n", +"disp(b,'Binary form of A478 is ='); //inbuilt function\n", +"b=dec2oct(hex2dec('A478'))\n", +"disp(b,'Octal form of A478 is ='); //inbuilt function\n", +"//conversion from octal to binary\n", +"s=dec2bin(oct2dec('3'));\n", +"s1=dec2bin(oct2dec('154')); //inbuilt function\n", +"printf('\n Octal form of 3.154 is = \n\n %s.00%s',s,s1)\n", +"s=dec2hex(oct2dec('3'));\n", +"s1=dec2hex(oct2dec('154')); //inbuilt function\n", +"printf('\n\n Hexadecimal form of 3.154 is = \n\n %s.%s',s,s1)" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 1.6: Conversion_to_Decimal_Number.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"//Example 1.6\n", +"//Conversion to Decimal Number\n", +"//Page no. 7\n", +"clc;close;clear;\n", +"\n", +"disp(dec2bin(182),'Binary of 182=') //inbuilt function" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 1.7: Conversion_to_Decimal_Number.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"//Example 1.7\n", +"//Conversion to Decimal Number\n", +"//Page no. 7\n", +"clc;close;clear;\n", +"\n", +"disp(dec2oct(467),'Octal of 467=') //inbuilt function" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 1.8: Conversion_to_Base_B_from_Binary_System.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"//Example 1.8\n", +"//Conversion to Base B from Binary System\n", +"//Page no. 8\n", +"clc;close;clear;\n", +"//conversion from binary to octal\n", +"disp(dec2oct(bin2dec('10101101110')),'Octal form of 10101101110 is ='); //inbuilt function\n", +"\n", +"//conversion from binary to hexadecimal\n", +"disp(dec2hex(bin2dec('10101101110')),'Hexadecimal form of 10101101110 is ='); //inbuilt function\n", +"\n", +"//conversion from binary to octal\n", +"s=dec2oct(bin2dec('1011'));\n", +"s1=dec2oct(bin2dec('110011010100')); //inbuilt function\n", +"printf('\n Octal form of 1011.1100110101 is = \n\n %s.%s',s,s1)\n", +"\n", +"//conversion from binary to hexadecimal\n", +"s=dec2hex(bin2dec('1011'));\n", +"s1=dec2hex(bin2dec('110011010100')); //inbuilt function\n", +"printf('\n\n Hexadecimal form of 1011.1100110101 is = \n\n %s.%s',s,s1)" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 1.9: Conversion_to_Binary_System.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"//Example 1.9\n", +"//Conversion to Binary System\n", +"//Page no. 8\n", +"clc;close;clear;\n", +"//conversion from octal to binary\n", +"disp(dec2bin(oct2dec('1753')),'Binary form of 1753 is ='); //inbuilt function\n", +"\n", +"//conversion from octal to binary\n", +"disp(dec2bin(hex2dec('A478')),'Binary form of A478 is ='); //inbuilt function\n", +"\n", +"//conversion from octal to binary\n", +"s=dec2bin(oct2dec('3'));\n", +"s1=dec2bin(oct2dec('154')); //inbuilt function\n", +"printf('\n Octal form of 3.154 is = \n\n %s.00%s',s,s1)" + ] + } +], +"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 +} |