diff options
author | priyanka | 2015-06-24 15:03:17 +0530 |
---|---|---|
committer | priyanka | 2015-06-24 15:03:17 +0530 |
commit | b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b (patch) | |
tree | ab291cffc65280e58ac82470ba63fbcca7805165 /60/DEPENDENCIES | |
download | Scilab-TBC-Uploads-b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b.tar.gz Scilab-TBC-Uploads-b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b.tar.bz2 Scilab-TBC-Uploads-b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b.zip |
initial commit / add all books
Diffstat (limited to '60/DEPENDENCIES')
-rwxr-xr-x | 60/DEPENDENCIES/adamsbash.sce | 27 | ||||
-rwxr-xr-x | 60/DEPENDENCIES/bisect.sce | 28 | ||||
-rwxr-xr-x | 60/DEPENDENCIES/fixedp.sce | 23 | ||||
-rwxr-xr-x | 60/DEPENDENCIES/gausselim2.sce | 43 | ||||
-rwxr-xr-x | 60/DEPENDENCIES/modifiedEuler.sce | 28 | ||||
-rwxr-xr-x | 60/DEPENDENCIES/newt.sce | 16 | ||||
-rwxr-xr-x | 60/DEPENDENCIES/regulfalsi.sce | 13 | ||||
-rwxr-xr-x | 60/DEPENDENCIES/rkm2.sce | 26 | ||||
-rwxr-xr-x | 60/DEPENDENCIES/rkm4.sce | 28 | ||||
-rwxr-xr-x | 60/DEPENDENCIES/scant.sce | 12 | ||||
-rwxr-xr-x | 60/DEPENDENCIES/secantm.sce | 13 |
11 files changed, 257 insertions, 0 deletions
diff --git a/60/DEPENDENCIES/adamsbash.sce b/60/DEPENDENCIES/adamsbash.sce new file mode 100755 index 000000000..41210017d --- /dev/null +++ b/60/DEPENDENCIES/adamsbash.sce @@ -0,0 +1,27 @@ + +function [u,t] = adamsbashforth3(u0,t0,tn,h,f) + +//adamsbashforth3 3rd order method solving ODE +// du/dt = f(u,t), with initial +//conditions u=u0 at t=t0. The +//solution is obtained for t = [t0:h:tn] +//and returned in u + +umaxAllowed = 1e+100; + +t = [t0:h:tn]; u = zeros(t); n = length(u); u(1) = u0; +for j = 1:n-1 +if j<3 then + k1=h*f(t(j),u(j)); + k2=h*f(t(j)+h,u(j)+k1); + u(j+1) = u(j) + (k2+k1)/2; +end; + +if j>=2 then + u(j+2) = u(j+1) + (h/12)*(23*f(t(j+1),u(j+1))-16*f(t(j),u(j))+5*f(t(j-1),u(j-1))); +end; +end; +endfunction + + + diff --git a/60/DEPENDENCIES/bisect.sce b/60/DEPENDENCIES/bisect.sce new file mode 100755 index 000000000..23216d2bf --- /dev/null +++ b/60/DEPENDENCIES/bisect.sce @@ -0,0 +1,28 @@ +function x=bisection(a,b,f) + N=100; //define max. number of iterations + PE=10^-4 //define tolerance + if (f(a)*f(b) > 0) then + error('no root possible f(a)*f(b) > 0') // checking if the decided range is containing a root + abort; + end; + if(abs(f(a)) <PE) then + error('solution at a') // seeing if there is an approximate root at a, + abort; + end; + if(abs(f(b)) < PE) then //seeing if there is an approximate root at b, + error('solution at b') + abort; + end; + x=(a+b)/2 + for n=1:1:N //initialising 'for' loop, + p=f(a)*f(x) + if p<0 then b=x ,x=(a+x)/2; //checking for the required conditions( f(x)*f(a)<0), + else + a=x + x=(x+b)/2; + end + if abs(f(x))<=PE then break // instruction to come out of the loop after the required condition is achived, + end + end + disp(n," no. of iterations =") // display the no. of iterations took to achive required condition, +endfunction
\ No newline at end of file diff --git a/60/DEPENDENCIES/fixedp.sce b/60/DEPENDENCIES/fixedp.sce new file mode 100755 index 000000000..f4031a234 --- /dev/null +++ b/60/DEPENDENCIES/fixedp.sce @@ -0,0 +1,23 @@ +function [x]=fixedp(x0,f)
+//fixed-point iteration
+N = 100; eps = 1.e-5; // define max. no. iterations and error
+maxval = 10000.0; // define value for divergence
+a = x0;
+while (N>0)
+ xn = f(a);
+ if(abs(xn-a)<eps)then
+ x=xn
+ disp(100-N);
+ return(x);
+ end;
+ if (abs(f(x))>maxval)then
+ disp(100-N);
+ error('Solution diverges');
+ abort;
+ end;
+ N = N - 1;
+ xx = xn;
+end;
+error('No convergence');
+abort;
+//end function
diff --git a/60/DEPENDENCIES/gausselim2.sce b/60/DEPENDENCIES/gausselim2.sce new file mode 100755 index 000000000..9e1ef25f3 --- /dev/null +++ b/60/DEPENDENCIES/gausselim2.sce @@ -0,0 +1,43 @@ +function [x] = gausselim(A,b) + + //This function obtains the solution to the system of + //linear equations A*x = b, given the matrix of coefficients A + //and the right-hand side vector, b + +[nA,mA] = size(A) +[nb,mb] = size(b) + +if nA<>mA then + error('gausselim - Matrix A must be square'); + abort; +elseif mA<>nb then + error('gausselim - incompatible dimensions between A and b'); + abort; +end; + +a = [A b]; + + //Forward elimination + +n = nA; +for k=1:n-1 + for i=k+1:n + for j=k+1:n+1 + a(i,j)=a(i,j)-a(k,j)*a(i,k)/a(k,k); + end; + end; +end; + + //Backward substitution + +x(n) = a(n,n+1)/a(n,n); + +for i = n-1:-1:1 + sumk=0 + for k=i+1:n + sumk=sumk+a(i,k)*x(k); + end; + x(i)=(a(i,n+1)-sumk)/a(i,i); +end; + + //End function
\ No newline at end of file diff --git a/60/DEPENDENCIES/modifiedEuler.sce b/60/DEPENDENCIES/modifiedEuler.sce new file mode 100755 index 000000000..164e09842 --- /dev/null +++ b/60/DEPENDENCIES/modifiedEuler.sce @@ -0,0 +1,28 @@ +function [u,t] = modifiedeuler(u0,t0,tn,h,f) + +//modifiedeuler 1st order method solving ODE +// du/dt = f(u,t), with initial +//conditions u=u0 at t=t0. The +//solution is obtained for t = [t0:h:tn] +//and returned in u + +umaxAllowed = 1e+100; + +t = [t0:h:tn]; u = zeros(t); n = length(u); u(1) = u0; + +for j = 1:n-1 + k1=h*f(t(j),u(j)); + k2=h*f(t(j)+h/2,u(j)+k1/2); + u(j+1) = u(j) + k2; + if u(j+1) > umaxAllowed then + disp('Euler 1 - WARNING: underflow or overflow'); + disp('Solution sought in the following range:'); + disp([t0 h tn]); + disp('Solution evaluated in the following range:'); + disp([t0 h t(j)]); + n = j; t = t(1,1:n); u = u(1,1:n); + break; + end; +end; + +endfunction
\ No newline at end of file diff --git a/60/DEPENDENCIES/newt.sce b/60/DEPENDENCIES/newt.sce new file mode 100755 index 000000000..6f7557e38 --- /dev/null +++ b/60/DEPENDENCIES/newt.sce @@ -0,0 +1,16 @@ +function x=newton(x,f,fp) + R=100; + PE=10^-8; + maxval=10^4; + + for n=1:1:R + x=x-f(x)/fp(x); + if abs(f(x))<=PE then break + end + if (abs(f(x))>maxval) then error('Solution diverges'); + abort + break + end + end + disp(n," no. of iterations =") +endfunction
\ No newline at end of file diff --git a/60/DEPENDENCIES/regulfalsi.sce b/60/DEPENDENCIES/regulfalsi.sce new file mode 100755 index 000000000..a743b4a4f --- /dev/null +++ b/60/DEPENDENCIES/regulfalsi.sce @@ -0,0 +1,13 @@ +function [x]=regularfalsi(a,b,f)
+ N=100;
+ PE=10^-5;
+ for n=2:1:N
+ x=a-(a-b)*f(a)/(f(a)-f(b));
+ disp(x)
+ if abs(f(x))<=PE then break;
+ elseif (f(a)*f(x)<0) then b=x;
+ else a=x;
+ end
+ end
+ disp(n," no. of ittirations =")
+endfunction
\ No newline at end of file diff --git a/60/DEPENDENCIES/rkm2.sce b/60/DEPENDENCIES/rkm2.sce new file mode 100755 index 000000000..633ecf265 --- /dev/null +++ b/60/DEPENDENCIES/rkm2.sce @@ -0,0 +1,26 @@ +function [u,t] = RK2(u0,t0,tn,h,f) + +// RK2 method solving ODE +// du/dt = f(u,t), with initial +//conditions u=u0 at t=t0. The +//solution is obtained for t = [t0:h:tn] +//and returned in u + +umaxAllowed = 1e+100; + +t = [t0:h:tn]; u = zeros(t); n = length(u); u(1) = u0; + +for j = 1:n-1 + k1=h*f(t(j),u(j)); + k2=h*f(t(j)+h,u(j)+k1); + u(j+1) = u(j) + (1/2)*(k1+k2); + if u(j+1) > umaxAllowed then + disp('Euler 1 - WARNING: underflow or overflow'); + disp('Solution sought in the following range:'); + disp([t0 h tn]); + disp('Solution evaluated in the following range:'); + disp([t0 h t(j)]); + n = j; t = t(1,1:n); u = u(1,1:n); + break; + end; +end;
\ No newline at end of file diff --git a/60/DEPENDENCIES/rkm4.sce b/60/DEPENDENCIES/rkm4.sce new file mode 100755 index 000000000..d034c374b --- /dev/null +++ b/60/DEPENDENCIES/rkm4.sce @@ -0,0 +1,28 @@ +function [u,t] = RK4(u0,t0,tn,h,f) +// RK4 method solving ODE +// du/dt = f(u,t), with initial +//conditions u=u0 at t=t0. The +//solution is obtained for t = [t0:h:tn] +//and returned in u + +umaxAllowed = 1e+100; + +t = [t0:h:tn]; u = zeros(t); n = length(u); u(1) = u0; + +for j = 1:n-1 + k1=h*f(t(j),u(j)); + k2=h*f(t(j)+h/2,u(j)+k1/2); + k3=h*f(t(j)+h/2,u(j)+k2/2); + k4=h*f(t(j)+h,u(j)+k3); + u(j+1) = u(j) + (1/6)*(k1+2*k2+2*k3+k4); + if u(j+1) > umaxAllowed then + disp('Euler 1 - WARNING: underflow or overflow'); + disp('Solution sought in the following range:'); + disp([t0 h tn]); + disp('Solution evaluated in the following range:'); + disp([t0 h t(j)]); + n = j; t = t(1,1:n); u = u(1,1:n); + break; + end; +end; + diff --git a/60/DEPENDENCIES/scant.sce b/60/DEPENDENCIES/scant.sce new file mode 100755 index 000000000..e7d914803 --- /dev/null +++ b/60/DEPENDENCIES/scant.sce @@ -0,0 +1,12 @@ +function [x]=secant(a,b,f) + N=100; // define max. no. iterations to be performed + PE=10^-4 // define tolerance for convergence + for n=1:1:N // initiating for loop + x=a-(a-b)*f(a)/(f(a)-f(b)); + if abs(f(x))<=PE then break; //checking for the required condition + else a=b; + b=x; + end + end + disp(n," no. of iterations =") // +endfunction
\ No newline at end of file diff --git a/60/DEPENDENCIES/secantm.sce b/60/DEPENDENCIES/secantm.sce new file mode 100755 index 000000000..fa0f84e78 --- /dev/null +++ b/60/DEPENDENCIES/secantm.sce @@ -0,0 +1,13 @@ +function [x]=secant(a,b,f) + N=100; // define max. no. iterations to be performed + PE=10^-4 // define tolerance for convergence + for n=1:1:N // initiating for loop + x=a-(a-b)*f(a)/(f(a)-f(b)); + disp(x) + if abs(f(x))<=PE then break; //checking for the required condition + else a=b; + b=x; + end + end + disp(n," no. of iterations =") // +endfunction
\ No newline at end of file |