summaryrefslogtreecommitdiff
path: root/Numerical_Methods_Principles_by_Analysis/5-Solutions_of_Algebraic_and_Transcendental_Equations.ipynb
diff options
context:
space:
mode:
Diffstat (limited to 'Numerical_Methods_Principles_by_Analysis/5-Solutions_of_Algebraic_and_Transcendental_Equations.ipynb')
-rw-r--r--Numerical_Methods_Principles_by_Analysis/5-Solutions_of_Algebraic_and_Transcendental_Equations.ipynb1738
1 files changed, 1738 insertions, 0 deletions
diff --git a/Numerical_Methods_Principles_by_Analysis/5-Solutions_of_Algebraic_and_Transcendental_Equations.ipynb b/Numerical_Methods_Principles_by_Analysis/5-Solutions_of_Algebraic_and_Transcendental_Equations.ipynb
new file mode 100644
index 0000000..55b874c
--- /dev/null
+++ b/Numerical_Methods_Principles_by_Analysis/5-Solutions_of_Algebraic_and_Transcendental_Equations.ipynb
@@ -0,0 +1,1738 @@
+{
+"cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter 5: Solutions of Algebraic and Transcendental Equations"
+ ]
+ },
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 5.10: Newton_Raphson_Method.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//Example 5.10\n",
+"//Newton Raphson Method\n",
+"//Page no. 167\n",
+"clc;clear;close;\n",
+"deff('x=f(x)','x=x*exp(-x)')\n",
+"deff('x=f1(x)','x=exp(-x)-x*exp(-x)')\n",
+"printf('n\txn\t\t\f(xn)\t\tf1(xn)\t\tXn+1\t\tError\n')\n",
+"printf('-----------------------------------------------------------------------------------------------------\n')\n",
+"x0=2;e=0.00001\n",
+"for i=1:11\n",
+" x1=x0-f(x0)/f1(x0)\n",
+" e1=abs(x0-x1)\n",
+" printf(' %i\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\n',i-1,x0,f(x0),f1(x0),x1,e1)\n",
+" x0=x1;\n",
+" if abs(x0)<e then\n",
+" break;\n",
+" end\n",
+"end\n",
+"printf('\n\nTherefore, this is not convergent (i.e.) divergent')"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 5.11: Newton_Raphson_Method.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//Example 5.11\n",
+"//Newton Raphson Method\n",
+"//Page no. 167\n",
+"clc;clear;close;\n",
+"deff('x=f(x)','x=x^3-x-3')\n",
+"deff('x=f1(x)','x=3*x^2-1')\n",
+"printf('n\txn\t\t\f(xn)\t\tf1(xn)\t\tXn+1\t\tError\n')\n",
+"printf('-----------------------------------------------------------------------------------------------------\n')\n",
+"x0=0;e=0.00001\n",
+"for i=1:11\n",
+" x1=x0-f(x0)/f1(x0)\n",
+" e1=abs(x0-x1)\n",
+" printf(' %i\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\n',i-1,x0,f(x0),f1(x0),x1,e1)\n",
+" x0=x1;\n",
+" if abs(x0)<e then\n",
+" break;\n",
+" end\n",
+"end\n",
+"printf('\n\nTherefore, it is cyclic in nature')"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 5.12: Newton_Raphson_Method.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//Example 5.12\n",
+"//Newton Raphson Method\n",
+"//Page no. 168\n",
+"clc;clear;close;\n",
+"deff('x=f(x)','x=atan(x)')\n",
+"deff('x=f1(x)','x=1/(1+x^2)')\n",
+"printf('n\txn\t\t\f(xn)\t\tf1(xn)\t\tXn+1\t\tError\n')\n",
+"printf('-----------------------------------------------------------------------------------------------------\n')\n",
+"x0=1.45;e=0.00001\n",
+"for i=1:12\n",
+" x1=x0-f(x0)/f1(x0)\n",
+" e1=abs(x0-x1)\n",
+" printf(' %i\t%.5g \t\t%.5g\t\t%.5g \t\t%.5g \t\t%.5g\n',i-1,x0,f(x0),f1(x0),x1,e1)\n",
+" x0=x1;\n",
+" if abs(x0)<e then\n",
+" break;\n",
+" end\n",
+"end\n",
+"printf('\n\nTherefore, it is divergent')"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 5.13: Secant_Method.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//Example 5.13\n",
+"//Secant Method\n",
+"//Page no. 170\n",
+"clc;clear;close;\n",
+"deff('x=f(x)','x=exp(x)-3*x-sin(x)')\n",
+"deff('x=f1(x)','x=exp(x)-3-cos(x)')\n",
+"printf('n\txn\t\tf(xn)\t\tXn+1\t\tf(Xn+1)\t\tXn+2\t\tError\n')\n",
+"printf('----------------------------------------------------------------------------------------------------------\n')\n",
+"x0=0.567123008;x1=1;e=0.00001\n",
+"for i=1:9\n",
+" x2=x1-f(x1)*(x1-x0)/(f(x1)-f(x0))\n",
+" e1=abs(x0-x2)\n",
+" printf(' %i\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\n',i-1,x0,f(x0),x1,f(x1),x2,e1)\n",
+" x0=x1;\n",
+" x1=x2\n",
+" if abs(x0)<e then\n",
+" break;\n",
+" end\n",
+"end\n",
+"printf('\n\nTherefore, the root is %.10f',x2)"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 5.14: Kizner_Method.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//Example 5.14\n",
+"//Kizner Method\n",
+"//Page no. 172\n",
+"clc;clear;close;\n",
+"h2=0.00001\n",
+"deff('x=f(x)','x=2*x-3-cos(x)')\n",
+"deff('y=f1(x,y)','y=h2/(-x+y)') //function for differentiation\n",
+"printf('n\th\tc\txn\t\tf(xn)\t\tF(xn)\t\tk1\t\t v\t\tXn+1\n')\n",
+"printf('--------------------------------------------------------------------------------------------------------------------\n')\n",
+"x0=2;e=0.00001;h=0.5;c=0.5;\n",
+"for i=1:11\n",
+" h1=-f(x0);\n",
+" F=f1(f(x0),f(x0+h2))\n",
+" k1=h1*F/2;\n",
+" v=h*f(x0)/(c*(f(x0+c+h)-f(x0+c)))-k1/c;\n",
+" a=0;\n",
+" for j=0:3\n",
+" a=a+(v^j)/factorial(j+1)\n",
+" end\n",
+" x1=x0+k1*a\n",
+" printf(' %i\t%g\t%g\t%.6f\t%.6f\t%.6f\t%.8f\t %.5f\t%.6f\n',i-1,h,c,x0,f(x0),F,k1,v,x1)\n",
+" x0=x1;\n",
+" if abs(x0)<e then\n",
+" break;\n",
+" end\n",
+"end\n",
+"printf('\n\nTherefore, the solution is %.10f',x1)"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 5.15: Brent_Method.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//Example 5.15\n",
+"//Brent Method\n",
+"//Page no. 173\n",
+"clc;clear;close;\n",
+"deff('y=f(x)','y=x^2+x-2')\n",
+"x1=0;x2=0.5;x3=2;\n",
+"r=f(x2)/f(x3);s=f(x2)/f(x1);t=f(x1)/f(x3);\n",
+"q=(t-1)*(r-1)*(s-1);\n",
+"p=r*t*(s-1)*(x2-x3)-s*(1-r)*(x2-x1)+(t*s-r)*x2\n",
+"printf('Root is : %.10g',x2+(p/q))"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 5.19: Horner_Method.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//Example 5.19\n",
+"//Horner Method\n",
+"//Page no. 177\n",
+"clc;clear;close;\n",
+"deff('y=f(x,a1,a2,a3,a4)','y=a1*x^3+a2*x^2+a3*x+a4')\n",
+"\n",
+"k=1;m=2;\n",
+"a=[4;-13;-31;-275];\n",
+"for i=1:10\n",
+" s=1;\n",
+" si=f(s,a(1),a(2),a(3),a(4))*abs(1/f(s,a(1),a(2),a(3),a(4)))\n",
+" while 1\n",
+" a1=f(s,a(1),a(2),a(3),a(4))*abs(1/f(s,a(1),a(2),a(3),a(4)))\n",
+" if si~=a1 then\n",
+" d(i)=s-1\n",
+" break\n",
+" end\n",
+" si=a1;\n",
+" s=s+1;\n",
+" end \n",
+" b(1)=a(1)\n",
+" for j=1:3\n",
+" for k=1:4-j\n",
+" b(k+1)=a(k+1)+b(k)*d(i)\n",
+" a(k+1)=b(k+1)\n",
+" end\n",
+" end\n",
+" for j=1:3\n",
+" a(j+1)=10^j*a(j+1)\n",
+" end\n",
+"end\n",
+"printf('The positive root is %i.',d(1))\n",
+"for i=2:10\n",
+" printf('%i',d(i))\n",
+"end"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 5.1: Bisection_Method.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//Example 5.1\n",
+"//Bisection Method\n",
+"//Page no. 145\n",
+"clc;clear;close;\n",
+"deff('y=f(x)','y=2^x-3*x')\n",
+"x1=0;x2=2;e=0.001;i=0;\n",
+"printf('Iteration\tx1\t\tx2\t\tz\t\tf(z)\n')\n",
+"printf('--------------------------------------------------------------------------\n')\n",
+"while abs(x1-x2)>e\n",
+" z=(x1+x2)/2\n",
+" printf(' %i\t\t%f\t%f\t%f\t%f\n',i,x1,x2,z,f(z))\n",
+" if f(z)*f(x1)>0\n",
+" x1=z\n",
+" else\n",
+" x2=z\n",
+" end\n",
+" i=i+1\n",
+"end\n",
+"printf('\n\nThe solution of this equation is %g after %i Iterations',z,i-1)"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 5.20: Laguerre_Method.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//Example 5.20\n",
+"//Laguerre Method\n",
+"//Page no. 180\n",
+"clc;clear;close;\n",
+"deff('y=f(x)','y=x^3+x^2+10*x-20')\n",
+"deff('y=f1(x)','y=3*x^2+2*x+10')\n",
+"deff('y=f2(x)','y=6*x+2')\n",
+"n=3;\n",
+"printf('i\tn\txi\t\tP(x)\t\tP1(x)\t\tP2(x)\t\tProot\t\tNroot\n')\n",
+"printf('---------------------------------------------------------------------------------------------------------\n')\n",
+"xi=1\n",
+"for i=0:9\n",
+" Proot=xi-(n*f(xi))/(f1(xi)+sqrt((n-1)*f1(xi)^2-n*f(xi)*f2(xi)))\n",
+" Nroot=xi-(n*f(xi))/(f1(xi)-sqrt((n-1)*f1(xi)^2-n*f(xi)*f2(xi)))\n",
+" printf(' %i\t%i\t%f\t%f\t%f\t%f\t%f\t%f\n',i,n,xi,f(xi),f1(xi),f2(xi),Proot,Nroot)\n",
+" xi=Proot\n",
+"end\n",
+"printf('\n\nProot = %f\n\nNroot = %f',Proot,Nroot)"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 5.21: Mullers_Method.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//Example 5.21\n",
+"//Mullers Method\n",
+"//Page no. 182\n",
+"clc;clear;close;\n",
+"\n",
+"deff('y=f(x)','y=x^3-x-4')\n",
+"zi=[1;2;3];\n",
+"s=['i','z2','z0','z1','f2','f0','f1','a0','a1','a2','zr+','zr-']\n",
+"li(1)=(zi(3,1)-zi(2,1))/(zi(2,1)-zi(1,1))\n",
+"hi(1)=zi(3,1)-zi(2,1);\n",
+"for i=2:6\n",
+" for j=1:3\n",
+" fz(j,i-1)=f(zi(j,i-1))\n",
+" end\n",
+" di(i-1)=1+li(i-1)\n",
+" gi(i-1)=fz(1,i-1)*li(i-1)^2-fz(2,i-1)*di(i-1)^2+fz(3,i-1)*(li(i-1)+di(i-1))\n",
+" D1(i-1)=gi(i-1)+sqrt(gi(i-1)^2-4*fz(3,i-1)*di(i-1)*li(i-1)*(fz(1,i-1)*li(i-1)-fz(2,i-1)*di(i-1)+fz(3,i-1)))\n",
+" D2(i-1)=gi(i-1)-sqrt(gi(i-1)^2-4*fz(3,i-1)*di(i-1)*li(i-1)*(fz(1,i-1)*li(i-1)-fz(2,i-1)*di(i-1)+fz(3,i-1)))\n",
+" if abs(D1(i-1))>abs(D2(i-1)) then\n",
+" li(i)=-2*fz(3,i-1)*di(i-1)/D1(i-1)\n",
+" else\n",
+" li(i)=-2*fz(3,i-1)*di(i-1)/D2(i-1)\n",
+" end\n",
+" hi(i)=li(i)*hi(i-1);\n",
+" z(i-1)=zi(3,i-1)+hi(i)\n",
+" for j=1:2\n",
+" zi(j,i)=zi(j+1,i-1)\n",
+" end\n",
+" zi(3,i)=z(i-1)\n",
+"end\n",
+"for i=1:12\n",
+" if i==1 then\n",
+" printf(s(i))\n",
+" for j=1:5\n",
+" printf('\t\t\t%i',j-1)\n",
+" end\n",
+" elseif i<=4\n",
+" printf('\n %s',s(i))\n",
+" for j=1:5\n",
+" printf('\t\t%.10f',zi(i-1,j))\n",
+" end\n",
+" elseif i<=7\n",
+" printf('\n %s',s(i))\n",
+" for j=1:5\n",
+" printf('\t\t%.10f',fz(i-4,j))\n",
+" end\n",
+" elseif i<=8\n",
+" printf('\n %s',s(i))\n",
+" for j=1:5\n",
+" printf('\t\t%.10f',li(j))\n",
+" end\n",
+" elseif i<=9\n",
+" printf('\n %s',s(i))\n",
+" for j=1:5\n",
+" printf('\t\t%.10f',di(j))\n",
+" end\n",
+" elseif i<=10\n",
+" printf('\n %s',s(i))\n",
+" for j=1:5\n",
+" printf('\t\t%.10f',gi(j))\n",
+" end\n",
+" elseif i<=11\n",
+" printf('\n %s',s(i))\n",
+" for j=1:5\n",
+" printf('\t\t%.10f',z(j))\n",
+" end\n",
+" elseif i<=12\n",
+" printf('\n %s',s(i))\n",
+" for j=1:5\n",
+" printf('\t\t%.10f',zi(j))\n",
+" end\n",
+" end\n",
+"end\n",
+"printf('\n\nAt the end of the %i iteration, the root of the equation is %.10f',j-2,z(j))"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 5.22: Mullers_Method.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//Example 5.22\n",
+"//Mullers Method\n",
+"//Page no. 183\n",
+"clc;clear;close;\n",
+"\n",
+"deff('y=f(x)','y=x^3-x-4')\n",
+"zi=[1;2;3];\n",
+"s=['i','z0','z1','z2','f0','f1','f2','li','di','gi','li+1','hi','hi+1','zi+1','D+','D_']\n",
+"li(1)=(zi(3,1)-zi(2,1))/(zi(2,1)-zi(1,1))\n",
+"hi(1)=zi(3,1)-zi(2,1);\n",
+"for i=2:6\n",
+" for j=1:3\n",
+" fz(j,i-1)=f(zi(j,i-1))\n",
+" end\n",
+" di(i-1)=1+li(i-1)\n",
+" gi(i-1)=fz(1,i-1)*li(i-1)^2-fz(2,i-1)*di(i-1)^2+fz(3,i-1)*(li(i-1)+di(i-1))\n",
+" D1(i-1)=gi(i-1)+sqrt(gi(i-1)^2-4*fz(3,i-1)*di(i-1)*li(i-1)*(fz(1,i-1)*li(i-1)-fz(2,i-1)*di(i-1)+fz(3,i-1)))\n",
+" D2(i-1)=gi(i-1)-sqrt(gi(i-1)^2-4*fz(3,i-1)*di(i-1)*li(i-1)*(fz(1,i-1)*li(i-1)-fz(2,i-1)*di(i-1)+fz(3,i-1)))\n",
+" if abs(D1(i-1))>abs(D2(i-1)) then\n",
+" li(i)=-2*fz(3,i-1)*di(i-1)/D1(i-1)\n",
+" else\n",
+" li(i)=-2*fz(3,i-1)*di(i-1)/D2(i-1)\n",
+" end\n",
+" hi(i)=li(i)*hi(i-1);\n",
+" z(i-1)=zi(3,i-1)+hi(i)\n",
+" for j=1:2\n",
+" zi(j,i)=zi(j+1,i-1)\n",
+" end\n",
+" zi(3,i)=z(i-1)\n",
+"end\n",
+"for i=1:16\n",
+" if i==1 then\n",
+" printf(s(i))\n",
+" for j=1:5\n",
+" printf('\t\t\t%i',j-1)\n",
+" end\n",
+" elseif i<=4\n",
+" printf('\n %s',s(i))\n",
+" for j=1:5\n",
+" printf('\t\t%.10f',zi(i-1,j))\n",
+" end\n",
+" elseif i<=7\n",
+" printf('\n %s',s(i))\n",
+" for j=1:5\n",
+" printf('\t\t%.10f',fz(i-4,j))\n",
+" end\n",
+" elseif i<=8\n",
+" printf('\n %s',s(i))\n",
+" for j=1:5\n",
+" printf('\t\t%.10f',li(j))\n",
+" end\n",
+" elseif i<=9\n",
+" printf('\n %s',s(i))\n",
+" for j=1:5\n",
+" printf('\t\t%.10f',di(j))\n",
+" end\n",
+" elseif i<=10\n",
+" printf('\n %s',s(i))\n",
+" for j=1:5\n",
+" printf('\t\t%.10f',gi(j))\n",
+" end\n",
+" elseif i<=11\n",
+" printf('\n %s',s(i))\n",
+" for j=1:5\n",
+" printf('\t\t%.10f',li(j+1))\n",
+" end\n",
+" elseif i<=12\n",
+" printf('\n %s',s(i))\n",
+" for j=1:5\n",
+" printf('\t\t%.10f',hi(j))\n",
+" end\n",
+" elseif i<=13\n",
+" printf('\n %s',s(i))\n",
+" for j=1:5\n",
+" printf('\t\t%.10f',hi(j+1))\n",
+" end\n",
+" elseif i<=14\n",
+" printf('\n %s',s(i))\n",
+" for j=1:5\n",
+" printf('\t\t%.10f',z(j))\n",
+" end\n",
+" elseif i<=15\n",
+" printf('\n %s',s(i))\n",
+" for j=1:5\n",
+" printf('\t\t%.10f',D1(j))\n",
+" end\n",
+" elseif i<=16\n",
+" printf('\n %s',s(i))\n",
+" for j=1:5\n",
+" printf('\t\t%.10f',D2(j))\n",
+" end\n",
+" end\n",
+"end\n",
+"printf('\n\nAt the end of the %ith iteration, the root of the equation is %.10f',j-1,z(j))"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 5.23: Bairstow_Hitchcock_Method.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//Example 5.23\n",
+"//Bairstow Hitchcock Method\n",
+"//Page no. 187\n",
+"clc;clear;close;\n",
+"deff('y=f(x,p,q)','y=x^2+p*z+q')\n",
+"a=[1,-1,1,-1,1]\n",
+"a=a';a=[a,a,a,a,a]\n",
+"printf('Iteration-->')\n",
+"for i=1:5\n",
+" printf('\t%i\t',i)\n",
+"end\n",
+"printf('\n------------------------------------------------------------------------------------------')\n",
+"p(1,1)=-1.2;q(1,1)=0.95;\n",
+"s=['b1','b2','b3','b4','c1','c2','c3','c4','c','dp','dq','p','q']\n",
+"//s1=[b1;b2;b3;b4;c1;c2;c3;c4;c;dp;dq;p;q]\n",
+"for i=1:5\n",
+" b(1,i)=0;b(2,i)=a(1,i);c(1,i)=0;c(2,i)=a(1,i);\n",
+" for k=1:4\n",
+" b(k+2,i)=a(k+1,i)-p(1,i)*b(k+1,i)-q(1,i)*b(k,i)\n",
+" c(k+2,i)=b(k+2,i)-p(1,i)*c(k+1,i)-q(1,i)*c(k,i)\n",
+" end\n",
+" cb(1,i)=c(6,i)-b(6,i);\n",
+" dq(1,i)=(b(6,i)*c(4,i)-b(5,i)*cb(1,i))/(c(4,i)^2-cb(1,i)*c(3,i))\n",
+" dp(1,i)=(b(5,i)*c(4,i)-b(6,i)*c(3,i))/(c(4,i)^2-cb(1,i)*c(3,i))\n",
+" p(1,i+1)=p(1,i)+dp(1,i);q(1,i+1)=q(1,i)+dq(1,i);\n",
+"end\n",
+"for j=1:13\n",
+" printf('\n %s\t\t',s(j))\n",
+" if j<5 then\n",
+" for i=1:5\n",
+" printf('%.9f\t',b(j+2,i))\n",
+" end\n",
+" elseif j<9 then\n",
+" for i=1:5\n",
+" printf('%.9f\t',c(j-2,i))\n",
+" end\n",
+" elseif j<10\n",
+" for i=1:5\n",
+" printf('%.9f\t',cb(1,i))\n",
+" end\n",
+" elseif j<11\n",
+" for i=1:5\n",
+" printf('%.9f\t',dp(1,i))\n",
+" end\n",
+" elseif j<12\n",
+" for i=1:5\n",
+" printf('%.9f\t',dq(1,i))\n",
+" end\n",
+" elseif j<13\n",
+" for i=1:5\n",
+" printf('%.9f\t',p(1,i+1))\n",
+" end\n",
+" else\n",
+" for i=1:5\n",
+" printf('%.9f\t',q(1,i+1))\n",
+" end\n",
+" end\n",
+"end\n",
+"z=poly(0,'z');\n",
+"a=f(z,p(1,i+1),q(1,i+1));\n",
+"printf('\n\nRoots for Quadratic Equation Q = ')\n",
+"disp(a)\n",
+"a=roots(a)\n",
+"printf('\n\tare\n')\n",
+"disp(a(1))\n",
+"disp(a(2))\n",
+"\n",
+""
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 5.24: Bernoulli_Method.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//Example 5.24\n",
+"//Bernoulli Method\n",
+"//Page no. 189\n",
+"clc;clear;close;\n",
+"\n",
+"a=[1,-8,-15,10];\n",
+"for i=1:2\n",
+" c(i)=0;\n",
+"end\n",
+"c(3)=1;\n",
+"for k=4:13\n",
+" c(k)=-(a(2)*c(k-1)+a(3)*c(k-2)+a(4)*c(k-3))\n",
+" r(k-3)=c(k)/c(k-1) \n",
+"end\n",
+"disp(c,'Ck Values')\n",
+"disp(r,'Rk Values')\n",
+"disp(r(k-3),'Therefore the exact root is = ')"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 5.25: Graeffe_Method.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//Example 5.25\n",
+"//Graeffe Method\n",
+"//Page no. 191\n",
+"clc;clear;close;\n",
+"\n",
+"a=[1,-6,11,-6]\n",
+"k=0;\n",
+"for k=2:6\n",
+" for i=1:4\n",
+" a(k,i)=(-1)^(i-1)*(a(k-1,i))^2\n",
+" j=1;\n",
+" while i+j<5 & i+j>2\n",
+" a(k,i)=a(k,i)+(-1)^(i-j-1)*2*(a(k-1,i-j))*a(k-1,i+j)\n",
+" break\n",
+" j=j+1;\n",
+" end\n",
+" end\n",
+"end\n",
+"printf('\t\t\t\ta1\t\t\t\ta2\t\t\t\ta3\n k\ta0\ta1\t\t--\t\ta2\t\t--\t\ta3\t\t--\t\n\t\t\t\ta0\t\t\t\ta1\t\t\t\ta2')\n",
+"printf('\n----------------------------------------------------------------------------------------------------\n')\n",
+"for i=1:4\n",
+" printf(' %i\t%g\t%.4g\t\t%.5g\t\t%.9g\t\t%.8g\t%g\t\t%.10g\n',i-1,a(i,1),a(i,2),abs(a(i,2)/a(i,1))^(1/(2^(i-1))),a(i,3),abs(a(i,3)/a(i,2))^(1/(2^(i-1))),a(i,4),abs(a(i,4)/a(i,3))^(1/(2^(i-1))))\n",
+"end\n",
+"for i=5:6\n",
+" printf(' %i\t%g\t%.4g\t%.5g\t\t%.9g\t%.8g\t%.7g\t%.10g\n',i-1,a(i,1),a(i,2),abs(a(i,2)/a(i,1))^(1/(2^(i-1))),a(i,3),abs(a(i,3)/a(i,2))^(1/(2^(i-1))),a(i,4),abs(a(i,4)/a(i,3))^(1/(2^(i-1))))\n",
+"end\n",
+"printf('\n\nThe Absolute Values of the roots are %g, %.8g and %g',abs(a(i,2)/a(i,1))^(1/(2^(i-1))),abs(a(i,3)/a(i,2))^(1/(2^(i-1))),abs(a(i,4)/a(i,3))^(1/(2^(i-1))))"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 5.26: QD_Method.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//Example 5.26\n",
+"//QD Method\n",
+"//Page no. 194\n",
+"clc;clear;close;\n",
+"\n",
+"a=[32,-48,18,-1]\n",
+"for i=1:5\n",
+" e(i,1)=0;\n",
+" e(i,4)=0;\n",
+"end\n",
+"q(1,1)=-a(2)/a(1);\n",
+"q(1,2)=0;q(1,3)=0;\n",
+"e(1,2)=a(3)/a(2);\n",
+"e(1,3)=a(4)/a(3);\n",
+"for i=2:16\n",
+" for j=1:3\n",
+" q(i,j)=e(i-1,j+1)+q(i-1,j)-e(i-1,j)\n",
+" end\n",
+" for j=1:2\n",
+" e(i,j+1)=e(i-1,j+1)*q(i,j+1)/q(i,j)\n",
+" end\n",
+"end\n",
+"printf('e0\t\tq1\t\te1\t\tq2\t\te2\t\tq3\t\te3\n')\n",
+"printf('------------------------------------------------------------------------------------------------------------\n')\n",
+"for i=1:14\n",
+" for j=1:3\n",
+" printf('\t\t%.10f\t',q(i,j))\n",
+" end\n",
+" printf('\n')\n",
+" for j=1:4\n",
+" printf('%.10f\t\t\t',e(i,j))\n",
+" end\n",
+" printf('\n')\n",
+"end\n",
+"printf('\t\t%.10f\t\t\t%.10f\t\t\t%.10f\n',q(15,1),q(15,2),q(15,3))\n",
+"printf('\nThe exact roots are \t%.10f and %.10f',q(15,1),q(15,3))"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 5.27: Linear_Iteration_Method.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//Example 5.27\n",
+"//Linear Iteration Method\n",
+"//Page no. 198\n",
+"clc;clear;close;\n",
+"\n",
+"deff('x=f(x)','x=20/(x^2+2*x+10)')\n",
+"printf('n\tx\t\tf(x)\n')\n",
+"printf('-------------------------------------\n')\n",
+"x=1;\n",
+"for i=1:19\n",
+" printf(' %i\t%.10f\t%.10f\n',i,x,f(x))\n",
+" x1=x;\n",
+" x=f(x);\n",
+"end\n",
+"printf('\n\nx = %.10f',x1)"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 5.28: Aitkens_Method.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//Example 5.28\n",
+"//Aitkens Method\n",
+"//Page no. 199\n",
+"clc;clear;close;\n",
+"\n",
+"deff('x=f(x)','x=20/(x^2+2*x+10)')\n",
+"printf('n\tx0\t\tx1\t\tx2\t\tx3\t\ty\t\tdx0\n')\n",
+"printf('-----------------------------------------------------------------------------------------------------\n')\n",
+"x0=1;e=0.0001\n",
+"for i=1:3\n",
+" x1=f(x0);x2=f(x1);x3=f(x2);\n",
+" y=x3-((x3-x2)^2)/(x3-2*x2+x1)\n",
+" dx0=y-x0;\n",
+" \n",
+" printf(' %i\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\n',i,x0,x1,x2,x3,y,dx0)\n",
+" x0=y;\n",
+" if abs(x0)<e then\n",
+" break;\n",
+" end\n",
+"end\n",
+"printf('\n\nThe solution of this equation after %i Iterations is %.10f',i,y)"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 5.29: Newton_Raphson_Method.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//Example 5.29\n",
+"//Newton Raphson Method\n",
+"//Page no. 199\n",
+"clc;clear;close;\n",
+"deff('x=f(x)','x=x^3+2*x^2+10*x-20')\n",
+"deff('x=f1(x)','x=3*x^2+4*x+10')\n",
+"printf('n\txn\t\t\f(xn)\t\tf1(xn)\t\tXn+1\t\tError\n')\n",
+"printf('-----------------------------------------------------------------------------------------------------\n')\n",
+"x0=01;e=0.00001\n",
+"for i=1:4\n",
+" x1=x0-f(x0)/f1(x0)\n",
+" e1=abs(x0-x1)\n",
+" printf(' %i\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\n',i-1,x0,f(x0),f1(x0),x1,e1)\n",
+" x0=x1;\n",
+" if abs(x0)<e then\n",
+" break;\n",
+" end\n",
+"end\n",
+"printf('\n\nThe solution of this equation after %i Iterations is %.10f',i,x1)"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 5.2: Bisection_Method.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//Example 5.2\n",
+"//Bisection Method\n",
+"//Page no. 147\n",
+"clc;clear;close;\n",
+"deff('y=f(x)','y=x^x-2*x+2')\n",
+"x1=0;x2=2;e=0.001;i=0;\n",
+"printf('Iteration\tx1\t\tx2\t\tz\t\tf(z)\n')\n",
+"printf('--------------------------------------------------------------------------\n')\n",
+"while abs(x1-x2)>e\n",
+" z=(x1+x2)/2\n",
+" printf(' %i\t\t%f\t%f\t%f\t%f\n',i,x1,x2,z,f(z))\n",
+" if f(z)*f(x1)>0\n",
+" x1=z\n",
+" else\n",
+" x2=z\n",
+" end\n",
+" i=i+1\n",
+"end\n",
+"printf('\n\nThe solution of this equation is %g after %i Iterations',z,i-1)\n",
+"\n",
+"printf('\n\n\nNote : There are computational errors in the answer given by the book for this example')"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 5.31: Secant_Method.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//Example 5.31\n",
+"//Secant Method\n",
+"//Page no. 200\n",
+"clc;clear;close;\n",
+"deff('x=f(x)','x=(x-0.6)*(x-1.3)^2*(x-2)^3+0.01234*log(x)')\n",
+"printf('n\txn\t\tf(xn)\t\tXn+1\t\tf(Xn+1)\t\tXn+2\t\tError\n')\n",
+"printf('----------------------------------------------------------------------------------------------------------\n')\n",
+"x0=0.1;x1=1.2;e=0.00001\n",
+"for i=1:7\n",
+" x2=x1-f(x1)*(x1-x0)/(f(x1)-f(x0))\n",
+" e1=abs(x0-x2)\n",
+" printf(' %i\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\n',i-1,x0,f(x0),x1,f(x1),x2,e1)\n",
+" x0=x1;\n",
+" x1=x2\n",
+" if abs(x0)<e then\n",
+" break;\n",
+" end\n",
+"end\n",
+"printf('\n\nTherefore, the root is %.10f',x2)"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 5.32: Regula_Falsi_Newton_Raphson_and_Mullers_Method.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//Example 5.32\n",
+"//Regula Falsi, Newton Raphson and Mullers Method\n",
+"//Page no. 201\n",
+"clc;clear;close;\n",
+"deff('x=f(x)','x=x^5-3.7*x^4+7.4*x^3-10.8*x^2+10.8*x-6.8')\n",
+"deff('x=f1(x)','x=5*x^4-4*3.7*x^3+3*7.4*x^2-21.6*x+10.8')\n",
+"//newton raphson\n",
+"printf('n\txn\t\t\f(xn)\t\tf1(xn)\t\tXn+1\t\tError\n')\n",
+"printf('-----------------------------------------------------------------------------------------------------\n')\n",
+"x0=1.5;e=0.00001\n",
+"for i=1:4\n",
+" x1=x0-f(x0)/f1(x0)\n",
+" e1=abs(x0-x1)\n",
+" printf(' %i\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\n',i-1,x0,f(x0),f1(x0),x1,e1)\n",
+" x0=x1;\n",
+" if abs(x0)<e then\n",
+" break;\n",
+" end\n",
+"end\n",
+"printf('\n\nThe solution of this equation by newton raphshon after %i Iterations is %.10f\n\n\n',i,x1)\n",
+"\n",
+"//regula falsi\n",
+"x1=1;x2=2;e=0.00001\n",
+"printf('n\tx1\t\tf(x1)\t\tx2\t\tf(x2)\t\tx3\t\tf(x3)')\n",
+"printf('\n-------------------------------------------------------------------------------------------------\n')\n",
+"for i=0:7\n",
+" x3=x2*f(x1)/(f(x1)-f(x2))+x1*f(x2)/(f(x2)-f(x1))\n",
+" printf(' %i\t%f\t%f\t%f\t%f\t%f\t%f\n',i,x1,f(x1),x2,f(x2),x3,f(x3))\n",
+" if f(x1)*f(x3)>0 then\n",
+" x1=x3\n",
+" else\n",
+" x2=x3\n",
+" end\n",
+" if abs(f(x3))<e then\n",
+" break\n",
+" end\n",
+"end\n",
+"printf('\n\nTherefore the solution by regula falsi method after %i iterations is %.10g',i,x3)\n",
+"\n",
+"//mullers method\n",
+"zi=[1;2;3];\n",
+"s=['i','z0','z1','z2','f0','f1','f2','li','di','gi','li+1','hi','hi+1','zi+1','D+','D_']\n",
+"li(1)=(zi(3,1)-zi(2,1))/(zi(2,1)-zi(1,1))\n",
+"hi(1)=zi(3,1)-zi(2,1);\n",
+"for i=2:6\n",
+" for j=1:3\n",
+" fz(j,i-1)=f(zi(j,i-1))\n",
+" end\n",
+" di(i-1)=1+li(i-1)\n",
+" gi(i-1)=fz(1,i-1)*li(i-1)^2-fz(2,i-1)*di(i-1)^2+fz(3,i-1)*(li(i-1)+di(i-1))\n",
+" D1(i-1)=gi(i-1)+sqrt(gi(i-1)^2-4*fz(3,i-1)*di(i-1)*li(i-1)*(fz(1,i-1)*li(i-1)-fz(2,i-1)*di(i-1)+fz(3,i-1)))\n",
+" D2(i-1)=gi(i-1)-sqrt(gi(i-1)^2-4*fz(3,i-1)*di(i-1)*li(i-1)*(fz(1,i-1)*li(i-1)-fz(2,i-1)*di(i-1)+fz(3,i-1)))\n",
+" if abs(D1(i-1))>abs(D2(i-1)) then\n",
+" li(i)=-2*fz(3,i-1)*di(i-1)/D1(i-1)\n",
+" else\n",
+" li(i)=-2*fz(3,i-1)*di(i-1)/D2(i-1)\n",
+" end\n",
+" hi(i)=li(i)*hi(i-1);\n",
+" z(i-1)=zi(3,i-1)+hi(i)\n",
+" for j=1:2\n",
+" zi(j,i)=zi(j+1,i-1)\n",
+" end\n",
+" zi(3,i)=z(i-1)\n",
+"end\n",
+"printf('\n\n ')\n",
+"for i=1:16\n",
+" if i==1 then\n",
+" printf(s(i))\n",
+" for j=1:5\n",
+" printf('\t\t\t %i',j-1)\n",
+" end\n",
+" printf('\n----------------------------------------------------------------------------------------------------------------------------------')\n",
+" elseif i<=4\n",
+" printf('\n %s',s(i))\n",
+" for j=1:5\n",
+" printf('\t\t%.10f',zi(i-1,j))\n",
+" end\n",
+" elseif i<=7\n",
+" printf('\n %s',s(i))\n",
+" for j=1:5\n",
+" printf('\t\t%.10f',fz(i-4,j))\n",
+" end\n",
+" elseif i<=8\n",
+" printf('\n %s',s(i))\n",
+" for j=1:5\n",
+" printf('\t\t%.10f',li(j))\n",
+" end\n",
+" elseif i<=9\n",
+" printf('\n %s',s(i))\n",
+" for j=1:5\n",
+" printf('\t\t%.10f',di(j))\n",
+" end\n",
+" elseif i<=10\n",
+" printf('\n %s',s(i))\n",
+" for j=1:5\n",
+" printf('\t\t%.10f',gi(j))\n",
+" end\n",
+" elseif i<=11\n",
+" printf('\n %s',s(i))\n",
+" for j=1:5\n",
+" printf('\t\t%.10f',li(j+1))\n",
+" end\n",
+" elseif i<=12\n",
+" printf('\n %s',s(i))\n",
+" for j=1:5\n",
+" printf('\t\t%.10f',hi(j))\n",
+" end\n",
+" elseif i<=13\n",
+" printf('\n %s',s(i))\n",
+" for j=1:5\n",
+" printf('\t\t%.10f',hi(j+1))\n",
+" end\n",
+" elseif i<=14\n",
+" printf('\n %s',s(i))\n",
+" for j=1:5\n",
+" printf('\t\t%.10f',z(j))\n",
+" end\n",
+" elseif i<=15\n",
+" printf('\n %s',s(i))\n",
+" for j=1:5\n",
+" printf('\t\t%.10f',D1(j))\n",
+" end\n",
+" elseif i<=16\n",
+" printf('\n %s',s(i))\n",
+" for j=1:5\n",
+" printf('\t\t%.10f',D2(j))\n",
+" end\n",
+" end\n",
+"end\n",
+"printf('\n\nAt the end of the %ith iteration by mullers method, the root of the equation is %.10f',j-1,z(j))"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 5.33: Newton_Raphson_and_Mullers_Method.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//Example 5.33\n",
+"//Newton Raphson and Mullers Method\n",
+"//Page no. 202\n",
+"clc;clear;close;\n",
+"deff('x=f(x)','x=x^4-8*x^3+18*x^2+0.12*x-24.24')\n",
+"deff('x=f1(x)','x=4*x^3-24*x^2+36*x+0.12')\n",
+"\n",
+"//newton raphson\n",
+"x9=[1.5,2.5,2.7,3.1;4,5,14,10]\n",
+"for h=1:4\n",
+" x0=x9(1,h);e=0.00001\n",
+"for i=1:x9(2,h)\n",
+" x1=x0-f(x0)/f1(x0)\n",
+" e1=abs(x0-x1)\n",
+" x0=x1;\n",
+" if abs(x0)<e then\n",
+" break;\n",
+" end\n",
+"end\n",
+"printf('\nThe solution of this equation by newton raphshon after %i Iterations is %.5f\n',i,x1)\n",
+"end\n",
+"\n",
+"//mullers method\n",
+"zx=[1,2,2.7,3.1;2,3,3.7,4.1;3,4,4.7,5.1]\n",
+"zi=[1;2;3];\n",
+"s=['i','z0','z1','z2','f0','f1','f2','li','di','gi','li+1','hi','hi+1','zi+1','D+','D_']\n",
+"li(1)=(zi(3,1)-zi(2,1))/(zi(2,1)-zi(1,1))\n",
+"hi(1)=zi(3,1)-zi(2,1);\n",
+"for i=2:4\n",
+" for j=1:3\n",
+" fz(j,i-1)=f(zi(j,i-1))\n",
+" end\n",
+" di(i-1)=1+li(i-1)\n",
+" gi(i-1)=fz(1,i-1)*li(i-1)^2-fz(2,i-1)*di(i-1)^2+fz(3,i-1)*(li(i-1)+di(i-1))\n",
+" D1(i-1)=gi(i-1)+sqrt(gi(i-1)^2-4*fz(3,i-1)*di(i-1)*li(i-1)*(fz(1,i-1)*li(i-1)-fz(2,i-1)*di(i-1)+fz(3,i-1)))\n",
+" D2(i-1)=gi(i-1)-sqrt(gi(i-1)^2-4*fz(3,i-1)*di(i-1)*li(i-1)*(fz(1,i-1)*li(i-1)-fz(2,i-1)*di(i-1)+fz(3,i-1)))\n",
+" if abs(D1(i-1))>abs(D2(i-1)) then\n",
+" li(i)=-2*fz(3,i-1)*di(i-1)/D1(i-1)\n",
+" else\n",
+" li(i)=-2*fz(3,i-1)*di(i-1)/D2(i-1)\n",
+" end\n",
+" hi(i)=li(i)*hi(i-1);\n",
+" z(i-1)=zi(3,i-1)+hi(i)\n",
+" for j=1:2\n",
+" zi(j,i)=zi(j+1,i-1)\n",
+" end\n",
+" zi(3,i)=z(i-1)\n",
+"end\n",
+"printf('\n\nAt the end of the %ith iteration by mullers method, the root of the equation is %.10f',j+2,z(j))"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 5.34: QD_Method.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//Example 5.34\n",
+"//QD Method\n",
+"//Page no. 202\n",
+"clc;clear;close;\n",
+"a=[1,2,10,-20]\n",
+"for i=1:5\n",
+" e(i,1)=0;\n",
+" e(i,4)=0;\n",
+"end\n",
+"q(1,1)=-a(2)/a(1);\n",
+"q(1,2)=0;q(1,3)=0;\n",
+"e(1,2)=a(3)/a(2);\n",
+"e(1,3)=a(4)/a(3);\n",
+"for i=2:7\n",
+" for j=1:3\n",
+" q(i,j)=e(i-1,j+1)+q(i-1,j)-e(i-1,j)\n",
+" end\n",
+" for j=1:2\n",
+" e(i,j+1)=e(i-1,j+1)*q(i,j+1)/q(i,j)\n",
+" end\n",
+"end\n",
+"printf('e0\t\tq1\t\te1\t\tq2\t\te2\t\tq3\t\te3\n')\n",
+"printf('------------------------------------------------------------------------------------------------------------\n')\n",
+"for i=1:7\n",
+" for j=1:3\n",
+" printf('\t\t%.10f\t',q(i,j))\n",
+" end\n",
+" printf('\n')\n",
+" for j=1:4\n",
+" printf('%.10f\t\t\t',e(i,j))\n",
+" end\n",
+" printf('\n')\n",
+"end\n",
+"printf('\t\t%.10f\t\t\t%.10f\t\t\t%.10f\n',q(7,1),q(7,2),q(7,3))\n",
+"printf('\nThe exact roots are \t%.10f and %.10f',q(7,1),q(7,3))"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 5.35: Newton_Raphson_Method.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//Example 5.35\n",
+"//Newton Raphson Method\n",
+"//Page no. 203\n",
+"clc;clear;close;\n",
+"deff('x=f(x)','x=x^3-30*x^2+2552')\n",
+"deff('x=f1(x)','x=3*x^2-60*x')\n",
+"//newton raphson\n",
+"printf('n\txn\t\t\f(xn)\t\tf1(xn)\t\tXn+1\t\tError\n')\n",
+"printf('-----------------------------------------------------------------------------------------------------\n')\n",
+"x0=10;e=0.00001\n",
+"for i=1:4\n",
+" x1=x0-f(x0)/f1(x0)\n",
+" e1=abs(x0-x1)\n",
+" printf(' %i\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\n',i-1,x0,f(x0),f1(x0),x1,e1)\n",
+" x0=x1;\n",
+" if abs(x0)<e then\n",
+" break;\n",
+" end\n",
+"end\n",
+"printf('\n\nThus the ball is submerged upto height of %.10f cm\n\n\n',x1)"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 5.36: Secant_Method.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//Example 5.36\n",
+"//Secant Method\n",
+"//Page no. 204\n",
+"clc;clear;close;\n",
+"a=8670;c=10^-8;t2=1.4*10^-4;\n",
+"deff('x=f(x)','x=-t2+log((1-2*x/a)/(2-x/a))*(a*x*c)/(a+x)')\n",
+"\n",
+"printf('n\txn\t\tf(xn)\t\tXn+1\t\tf(Xn+1)\t\tXn+2\t\tError\n')\n",
+"printf('----------------------------------------------------------------------------------------------------------\n')\n",
+"x0=20000;x1=25000;e=0.00001\n",
+"for i=1:8\n",
+" x2=x1-f(x1)*(x1-x0)/(f(x1)-f(x0))\n",
+" e1=abs(x0-x2)\n",
+" printf(' %i\t%f\t%.10f\t%f\t%.10f\t%f\t%.10f\n',i-1,x0,f(x0),x1,f(x1),x2,e1)\n",
+" x0=x1;\n",
+" x1=x2\n",
+" if abs(x0)<e then\n",
+" break;\n",
+" end\n",
+"end\n",
+"printf('\n\nTherefore, Rb = %.10f ohm',x2)"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 5.37: Newton_Raphson_Method.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//Example 5.37\n",
+"//Newton Raphson Method\n",
+"//Page no. 204\n",
+"clc;clear;close;\n",
+"p=1.1;T=250;R=0.082;a=3.6;b=0.043;\n",
+"deff('y=f(v)','y=p*v^3-(b*p+R*T)*v^2+a*v-a*b')\n",
+"deff('y=f1(v)','y=3*p*v^2-2*(b*p+R*T)*v')\n",
+"printf('n\txn\t\t\f(xn)\t\tf1(xn)\t\tXn+1\t\tError\n')\n",
+"printf('-----------------------------------------------------------------------------------------------------\n')\n",
+"x0=0.1;e=0.00001\n",
+"for i=1:10\n",
+" x1=x0-f(x0)/f1(x0)\n",
+" e1=abs(x0-x1)\n",
+" printf(' %i\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\n',i-1,x0,f(x0),f1(x0),x1,e1)\n",
+" x0=x1;\n",
+" if abs(x0)<e then\n",
+" break;\n",
+" end\n",
+"end\n",
+"printf('\n\nTherefore, Volume v = %.10f ltr',x1)"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 5.38: Newton_Raphson_Method.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//Example 5.38\n",
+"//Newton Raphson Method\n",
+"//Page no. 205\n",
+"clc;clear;close;\n",
+"deff('y=f(p)','y=p^3-9*p^2+33*p-65')\n",
+"deff('y=f1(p)','y=3*p^2-18*p+33')\n",
+"printf('n\txn\t\t\f(xn)\t\tf1(xn)\t\tXn+1\t\tError\n')\n",
+"printf('-----------------------------------------------------------------------------------------------------\n')\n",
+"x0=6;e=0.00001\n",
+"for i=1:10\n",
+" x1=x0-f(x0)/f1(x0)\n",
+" e1=abs(x0-x1)\n",
+" printf(' %i\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\n',i-1,x0,f(x0),f1(x0),x1,e1)\n",
+" x0=x1;\n",
+" if abs(x0)<e then\n",
+" break;\n",
+" end\n",
+"end\n",
+"printf('\n\nTherefore, Market Price at equilibrium = Rs. %.f',x1)"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 5.39: Newton_Raphson_Method.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//Example 5.39\n",
+"//Newton Raphson Method\n",
+"//Page no. 205\n",
+"clc;clear;close;\n",
+"deff('y=f(v)','y=v^3-20*v+30')\n",
+"deff('y=f1(v)','y=3*v^2-20')\n",
+"printf('n\txn\t\t\f(xn)\t\tf1(xn)\t\tXn+1\t\tError\n')\n",
+"printf('-----------------------------------------------------------------------------------------------------\n')\n",
+"x0=10;e=0.00001\n",
+"for i=1:10\n",
+" x1=x0-f(x0)/f1(x0)\n",
+" e1=abs(x0-x1)\n",
+" printf(' %i\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\n',i-1,x0,f(x0),f1(x0),x1,e1)\n",
+" x0=x1;\n",
+" if abs(x0)<e then\n",
+" break;\n",
+" end\n",
+"end\n",
+"printf('\n\nTherefore, sides are = %.5f m x %.5f m x %.5f m',x1,x1,20/x1^2)"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 5.3: Regula_Falsi_Method.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//Example 5.3\n",
+"//Regula Falsi Method\n",
+"//Page no. 149\n",
+"clc;clear;close;\n",
+"deff('y=f(x)','y=x^3-3*x-5')\n",
+"x1=2;x2=3;e=0.00001\n",
+"printf('n\tx1\t\tf(x1)\t\tx2\t\tf(x2)\t\tx3\t\tf(x3)')\n",
+"printf('\n-------------------------------------------------------------------------------------------------\n')\n",
+"for i=0:19\n",
+" x3=x2*f(x1)/(f(x1)-f(x2))+x1*f(x2)/(f(x2)-f(x1))\n",
+" printf(' %i\t%f\t%f\t%f\t%f\t%f\t%f\n',i,x1,f(x1),x2,f(x2),x3,f(x3))\n",
+" if f(x1)*f(x3)>0 then\n",
+" x1=x3\n",
+" else\n",
+" x2=x3\n",
+" end\n",
+" if abs(f(x3))<e then\n",
+" break\n",
+" end\n",
+"end\n",
+"printf('\n\nTherefore the solution is %.10g',x3)"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 5.40: Newton_Raphson_Method.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//Example 5.40\n",
+"//Newton Raphson Method\n",
+"//Page no. 206\n",
+"clc;clear;close;\n",
+"deff('y=f(F)','y=-10*F^3-21*F+10')\n",
+"deff('y=f1(F)','y=-21-30*F^2')\n",
+"printf('n\txn\t\t\f(xn)\t\tf1(xn)\t\tXn+1\t\tError\n')\n",
+"printf('-----------------------------------------------------------------------------------------------------\n')\n",
+"x0=1;e=0.00001\n",
+"for i=1:10\n",
+" x1=x0-f(x0)/f1(x0)\n",
+" e1=abs(x0-x1)\n",
+" printf(' %i\t%.10f\t%.6f\t%.5f\t%.10f\t%.10f\n',i-1,x0,f(x0),f1(x0),x1,e1)\n",
+" x0=x1;\n",
+" if abs(x0)<e then\n",
+" break;\n",
+" end\n",
+"end\n",
+"printf('\n\t\t\t\t\t2\n Therefore, Magnetic Flux = %.5f Wb m',x1)"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 5.4: Ridders_Method.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//Example 5.4\n",
+"//Ridders Method\n",
+"//Page no. 153\n",
+"clc;clear;close;\n",
+"deff('y=f(x)','y=x^3-3*x-5')\n",
+"x1=2;x2=3;e=0.00001\n",
+"printf('n\tx1\t\tf(x1)\t\tx2\t\tf(x2)\t\tx3\t\tf(x3)\t sign\t x4')\n",
+"printf('\n----------------------------------------------------------------------------------------------------------\n')\n",
+"for i=0:8\n",
+" x3=(x1+x2)/2\n",
+" a=f(x1)-f(x2);\n",
+" s=a*abs(1/a)\n",
+" x4=x3+(x3-x2)*(s*f(x3))/sqrt(f(x3)-f(x1)*f(x2))\n",
+" printf(' %i\t%f\t%f\t%f\t%f\t%f\t%f %i\t%f\n',i,x1,f(x1),x2,f(x2),x3,f(x3),s,x4)\n",
+" if f(x1)*f(x4)>0 then\n",
+" x1=x4\n",
+" else\n",
+" x2=x4\n",
+" end\n",
+" if abs(f(x4))<e then\n",
+" break\n",
+" end\n",
+"end\n",
+"printf('\n\nThe solution of this equation is %g after %i Iterations',x4,i)\n",
+"printf('\n\n\nThere are computation error in the answers given by the book in this example\n\n(value of x1 is used instead of x2)')"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 5.5: General_Iterative_Method.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//Example 5.5\n",
+"//General Iterative Method\n",
+"//Page no. 154\n",
+"clc;clear;close;\n",
+"deff('x=f(x)','x=sqrt(3+5/x)')\n",
+"printf('n\tx\t\tf(x)\n')\n",
+"printf('------------------------------------\n')\n",
+"x=2;\n",
+"for i=1:8\n",
+" printf(' %i\t%.10f\t%.10f\n',i,x,f(x))\n",
+" x=f(x);\n",
+"end\n",
+"printf('\n\nThe solution of this equation after %i Iterations is %.10f',i,x)"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 5.6: Linear_Iterative_Method.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//Example 5.6\n",
+"//Linear Iterative Method\n",
+"//Page no. 159\n",
+"clc;clear;close;\n",
+"deff('x=f(x)','x=1+sin(x)/10')\n",
+"printf('n\tx\t\tf(x)\n')\n",
+"printf('-------------------------------------\n')\n",
+"x=0;\n",
+"for i=1:7\n",
+" printf(' %i\t%.10f\t%.10f\n',i,x,f(x))\n",
+" x=f(x);\n",
+"end\n",
+"printf('\n\nThe solution of this equation after %i Iterations is %.10f',i,x)"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 5.7: Aitkens_Method.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//Example 5.7\n",
+"//Aitkens Method\n",
+"//Page no. 161\n",
+"clc;clear;close;\n",
+"deff('x=f(x)','x=exp(-x)')\n",
+"printf('n\tx0\t\tx1\t\tx2\t\tx3\t\ty\t\tdx0\n')\n",
+"printf('-----------------------------------------------------------------------------------------------------\n')\n",
+"x0=0.5;e=0.0001\n",
+"for i=1:3\n",
+" x1=f(x0);x2=f(x1);x3=f(x2);\n",
+" y=x3-((x3-x2)^2)/(x3-2*x2+x1)\n",
+" dx0=y-x0;\n",
+" \n",
+" printf(' %i\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\n',i,x0,x1,x2,x3,y,dx0)\n",
+" x0=y;\n",
+" if abs(x0)<e then\n",
+" break;\n",
+" end\n",
+"end\n",
+"printf('\n\nThe solution of this equation after %i Iterations is %.10f',i,y)"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 5.8: Newton_Raphson_Method.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//Example 5.8\n",
+"//Newton Raphson Method\n",
+"//Page no. 163\n",
+"clc;clear;close;\n",
+"deff('x=f(x)','x=x-exp(-x)')\n",
+"deff('x=f1(x)','x=1+exp(-x)')\n",
+"printf('n\txn\t\t\f(xn)\t\tf1(xn)\t\tXn+1\t\tError\n')\n",
+"printf('-----------------------------------------------------------------------------------------------------\n')\n",
+"x0=0.5;e=0.00001\n",
+"for i=1:4\n",
+" x1=x0-f(x0)/f1(x0)\n",
+" e1=abs(x0-x1)\n",
+" printf(' %i\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\n',i-1,x0,f(x0),f1(x0),x1,e1)\n",
+" x0=x1;\n",
+" if abs(x0)<e then\n",
+" break;\n",
+" end\n",
+"end\n",
+"printf('\n\nThe solution of this equation after %i Iterations is %.10f',i,x1)"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 5.9: Modified_Newton_Raphson_Method.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//Example 5.9\n",
+"//Modified Newton Raphson Method\n",
+"//Page no. 165\n",
+"clc;clear;close;\n",
+"deff('x=f(x)','x=exp(x)-3*x-sin(x)')\n",
+"deff('x=f1(x)','x=exp(x)-3-cos(x)')\n",
+"printf('n\txn\t\t\f(xn)\t\tf1(xn)\t\tXn+1\t\tError\n')\n",
+"printf('-----------------------------------------------------------------------------------------------------\n')\n",
+"x0=0;e=0.00001\n",
+"for i=1:4\n",
+" x1=x0-f(x0)/f1(x0)\n",
+" e1=abs(x0-x1)\n",
+" printf(' %i\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\n',i-1,x0,f(x0),f1(x0),x1,e1)\n",
+" x0=x1;\n",
+" if abs(x0)<e then\n",
+" break;\n",
+" end\n",
+"end\n",
+"printf('\n\nTherefore, the root is %.10f',x1)"
+ ]
+ }
+],
+"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
+}