summaryrefslogtreecommitdiff
path: root/260/DEPENDENCIES
diff options
context:
space:
mode:
authorprashantsinalkar2017-10-10 12:27:19 +0530
committerprashantsinalkar2017-10-10 12:27:19 +0530
commit7f60ea012dd2524dae921a2a35adbf7ef21f2bb6 (patch)
treedbb9e3ddb5fc829e7c5c7e6be99b2c4ba356132c /260/DEPENDENCIES
parentb1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b (diff)
downloadScilab-TBC-Uploads-7f60ea012dd2524dae921a2a35adbf7ef21f2bb6.tar.gz
Scilab-TBC-Uploads-7f60ea012dd2524dae921a2a35adbf7ef21f2bb6.tar.bz2
Scilab-TBC-Uploads-7f60ea012dd2524dae921a2a35adbf7ef21f2bb6.zip
initial commit / add all books
Diffstat (limited to '260/DEPENDENCIES')
-rw-r--r--260/DEPENDENCIES/cubicspline.sci50
-rw-r--r--260/DEPENDENCIES/graeffe.sci51
-rw-r--r--260/DEPENDENCIES/graf.sci66
-rw-r--r--260/DEPENDENCIES/insertion_sort.sci14
-rw-r--r--260/DEPENDENCIES/lagrange.sci20
-rw-r--r--260/DEPENDENCIES/quicksort.sci35
-rw-r--r--260/DEPENDENCIES/swap.sci7
7 files changed, 243 insertions, 0 deletions
diff --git a/260/DEPENDENCIES/cubicspline.sci b/260/DEPENDENCIES/cubicspline.sci
new file mode 100644
index 000000000..178a716eb
--- /dev/null
+++ b/260/DEPENDENCIES/cubicspline.sci
@@ -0,0 +1,50 @@
+function cubicspline(X,Y)
+ n = length(X);
+ //c(1) = 0;
+ //a = zeros(n-1,n-1);
+ for(i = 2:n-1)
+ c(i-1) = (6/(X(i+1)-X(i-1)))*((Y(i+1)-Y(i))/(X(i+1)-X(i)) - (Y(i)-Y(i-1))/ (X(i)-X(i-1)));
+ end
+ for(i = 2:n-1)
+ a(i-1,i-1) = (X(i)-X(i-1))/(X(i+1)-X(i-1));
+ a(i-1,i) = 2;
+ a(i-1,i+1) = (X(i+1)-X(i))/(X(i+1)-X(i-1));
+
+ end
+[m,n] = size(a);
+
+b = a(:,2:n-1); //For the case of natural splines, double derivative is zero at the first and last of data points. So removing the first and last columns since these are the only non-zero terms in the respective columns.
+
+//[r2 c2] = size(b);
+
+//disp(c)
+//disp(b)
+x = inv(b)*c;
+
+//disp(x)
+x1(1,1) = 0;
+x1(n,1) = 0;
+x1(2:n-1,1) = x(:,1);
+
+printf('The values of second derivatives at the data points are :\n')
+disp(x1)
+
+x = poly(0,'x');
+
+for(i = 2:n)
+ f(i-1) = [Y(i-1)*(X(i)-x)/(X(i)-X(i-1)) + Y(i)*(x-X(i-1))/(X(i)-X(i-1))] + x1(i-1)/6*[(X(i)-x)^3/(X(i)-X(i-1))-(X(i)-X(i-1))*(X(i)-x)] + x1(i)/6*[(x-X(i-1))^3/(X(i)-X(i-1))-(X(i)-X(i-1))*(x-X(i-1))];
+end
+
+printf('\nThe expressions for the cubic splines are \n')
+disp(f)
+
+for(i = 1:n-1)
+ p = X(i):0.01:X(i+1);
+ q = horner(f(i),p);
+ plot(p,q)
+end
+plot(X,Y,'ks')
+xlabel('x')
+ylabel('y')
+
+endfunction \ No newline at end of file
diff --git a/260/DEPENDENCIES/graeffe.sci b/260/DEPENDENCIES/graeffe.sci
new file mode 100644
index 000000000..f04838ae6
--- /dev/null
+++ b/260/DEPENDENCIES/graeffe.sci
@@ -0,0 +1,51 @@
+function q = graeffe(A,eps)
+ n = length(A)-1;
+ x = poly(0,'x');
+ for(i = 1:n)
+ X(i) = x^(n+1-i);
+ end
+ X(n+1) = 1;
+ //disp(X)
+ //converting this polynomial into standard one where the coefficient of highest order term is 1
+
+A = A/A(1);
+p = A*X;
+printf('The given polynomial is\n')
+disp(p)
+n = length(X)-1;
+
+j = 1;
+a(j,1) = A(j,2);
+a(j,2) = abs(A(j,3)/A(j,2));
+//eps = 0.000001;
+err = 1;
+printf('\nIteration no. error eps\n')
+while(err>eps)
+ A(j,1) = 1;
+ for(i = 2:n+1)
+ S = 0;
+ for(k = 1:i-1)
+ if(i-1+k>n)
+ A(j,i+k) = 0;
+ end
+ S = S+ (-1)^k*A(j,i+k)*A(j,i-k);
+ end
+
+ A(j+1,i) = (-1)^(i-1)*(A(j,i)^2 + 2*S);
+
+ end
+ a(j+1,1) = abs(A(j+1,2))^(1/2^j);
+ for(i = 3:n+1)
+ a(j+1,i-1) = (abs(A(j+1,i)/A(j+1,i-1)))^(1/2^j);
+ end
+ b = abs(a);
+ err = abs((sum(b(j+1,:)) - sum(b(j,:)))/sum(b(j,:)));
+ printf(' %d %f %f\n',j,err,eps)
+ j = j+1;
+end
+printf('\nThe roots are \n')
+for(i = 1:n)
+ printf(' %f\n',a(j,i))
+end
+q = a(j,:);
+endfunction \ No newline at end of file
diff --git a/260/DEPENDENCIES/graf.sci b/260/DEPENDENCIES/graf.sci
new file mode 100644
index 000000000..a0211fb2e
--- /dev/null
+++ b/260/DEPENDENCIES/graf.sci
@@ -0,0 +1,66 @@
+function q = graf(A,eps)
+ n = length(A)-1;
+ x = poly(0,'x');
+ for(i = 1:n)
+ X(i) = x^(n+1-i);
+ end
+ X(n+1) = 1;
+ //disp(X)
+ //converting this polynomial into standard one where the coefficient of highest order term is 1
+
+A = A/A(1);
+p = A*X;
+
+printf('The given polynomial is')
+disp(p)
+n = length(X)-1;
+
+if(n == 1)
+ for(i = 3:4)
+ A(1,3) = 0;
+ A(1,4) = 0;
+ end
+end
+
+j = 1;
+a(j,1) = A(j,2);
+a(j,2) = abs(A(j,3)/A(j,2));
+//eps = 0.000001;
+err = 1;
+printf('\nIteration no. error eps\n')
+while(err>eps)
+ A(j,1) = 1;
+ for(i = 2:n+1)
+ S = 0;
+ for(k = 1:i-1)
+ if(i-1+k>n)
+ A(j,i+k) = 0;
+ end
+ S = S+ (-1)^k*A(j,i+k)*A(j,i-k);
+ end
+
+ A(j+1,i) = (-1)^(i-1)*(A(j,i)^2 + 2*S);
+
+ end
+ a(j+1,1) = abs(A(j+1,2))^(1/2^j);
+ for(i = 3:n+1)
+ a(j+1,i-1) = (abs(A(j+1,i)/A(j+1,i-1)))^(1/2^j);
+ end
+ b = abs(a);
+ err = abs((sum(b(j+1,:)) - sum(b(j,:)))/sum(b(j,:)));
+ printf(' %d %f %f\n',j,err,eps)
+ j = j+1;
+end
+printf('\nThe roots are \n')
+
+for(i = 1:n)
+ if( abs(horner(p,a(j,i))) > eps )
+ a(j,i) = -a(j,i);
+ end
+end
+
+for(i = 1:n)
+ printf(' %f\n',a(j,i))
+end
+q = a(j,:);
+endfunction \ No newline at end of file
diff --git a/260/DEPENDENCIES/insertion_sort.sci b/260/DEPENDENCIES/insertion_sort.sci
new file mode 100644
index 000000000..d6b5f5d32
--- /dev/null
+++ b/260/DEPENDENCIES/insertion_sort.sci
@@ -0,0 +1,14 @@
+function A = insertion_sort(A)
+ n = length(A);
+
+for(i = 2:n)
+ t = A(i);
+ j = i;
+ while((j > 1) & (A(j-1) > t))
+ A(j) = A(j-1);
+ j = j-1;
+ end
+ A(j) = t;
+end
+
+endfunction \ No newline at end of file
diff --git a/260/DEPENDENCIES/lagrange.sci b/260/DEPENDENCIES/lagrange.sci
new file mode 100644
index 000000000..59d81f779
--- /dev/null
+++ b/260/DEPENDENCIES/lagrange.sci
@@ -0,0 +1,20 @@
+function p = lagrange(X,y,n)
+
+ x = poly(0,'x')
+ // n is the order of the polynomial
+ //x is the matrix of independent variable values
+ //y is the matrix of values of f(x)
+ p = 0;
+ for i = 1:n+1
+ L(i) = 1
+ for j = 1:n+1
+ if j == i then
+ continue ;
+ else
+ L(i) = L(i)*( x - X(j) )/( X(i) - X(j) ) ;
+ end
+ end
+ p = p + y(i)*L(i)
+ end
+
+endfunction \ No newline at end of file
diff --git a/260/DEPENDENCIES/quicksort.sci b/260/DEPENDENCIES/quicksort.sci
new file mode 100644
index 000000000..eb3119d86
--- /dev/null
+++ b/260/DEPENDENCIES/quicksort.sci
@@ -0,0 +1,35 @@
+function xsort = quicksort(x)
+ n= length(x)
+ pivot = x(1)
+if n == 0 then
+ xsort = []
+elseif n == 1 then
+ xsort = x(1)
+ else
+ j = n
+ for i = 2:n
+ if pivot < x(i) then
+ for j = j:-1:i
+ if pivot > x(j) then
+ t = x(i)
+ x(i) = x(j)
+ x(j) = t
+ break
+ end
+
+ end
+
+ end
+
+ if j == i then
+ if i == n & pivot > x(i) then
+ xsort = [ quicksort( x(2:i) ) pivot]
+ else
+ xsort = [ quicksort( x(2:i-1) ) pivot quicksort( x(i:n) )]
+ break ;
+ end
+ end
+ end
+end
+
+endfunction \ No newline at end of file
diff --git a/260/DEPENDENCIES/swap.sci b/260/DEPENDENCIES/swap.sci
new file mode 100644
index 000000000..8efdfec5b
--- /dev/null
+++ b/260/DEPENDENCIES/swap.sci
@@ -0,0 +1,7 @@
+function [p,q] = swap(x,y)
+ t = x;
+ x = y;
+ y = t;
+ p = x;
+ q = y;
+endfunction \ No newline at end of file