summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChayan Bhawal2018-09-27 17:25:55 +0530
committerChayan Bhawal2018-09-27 17:25:55 +0530
commit7a29e5fb81d9f0bb5f3c548c76a3ebacb1ce94ec (patch)
treebf50691575cf8b22abfad2cccdf2d8e849da1baa
parent168f3114992f59d8782730ce47cb6911c62038ec (diff)
downloadscilab-tutorials-7a29e5fb81d9f0bb5f3c548c76a3ebacb1ce94ec.tar.gz
scilab-tutorials-7a29e5fb81d9f0bb5f3c548c76a3ebacb1ce94ec.tar.bz2
scilab-tutorials-7a29e5fb81d9f0bb5f3c548c76a3ebacb1ce94ec.zip
Tutorial5_nonlinear_update
-rw-r--r--Tutorial1_Basic/Data/README.md1
-rw-r--r--Tutorial1_Basic/Data/Tut1_data1.csv16
-rw-r--r--Tutorial1_Basic/Problems/README.md1
-rw-r--r--Tutorial1_Basic/README.md1
-rw-r--r--Tutorial1_Basic/Scilab_code/README.md1
-rw-r--r--Tutorial1_Basic/Scilab_code/Tutorial1_Matrix_manipulation.sce105
-rw-r--r--Tutorial1_Basic/Scilab_code/Tutorial1_function.sce27
-rw-r--r--Tutorial1_Basic/Scilab_code/Tutotial1_filehandling.sce24
-rw-r--r--Tutorial1_Basic/Scilab_code/mymean.sci9
-rw-r--r--Tutorial1_Basic/Scilab_code/mystdev.sci8
-rw-r--r--Tutorial2_Plot/Data/README.md1
-rw-r--r--Tutorial2_Plot/Data/Tut2_data1.csv15
-rw-r--r--Tutorial2_Plot/Problems/README.md1
-rw-r--r--Tutorial2_Plot/README.md1
-rw-r--r--Tutorial2_Plot/Scilab_code/README.md1
-rw-r--r--Tutorial2_Plot/Scilab_code/Tutorial2_semilog.sce22
-rw-r--r--Tutorial2_Plot/Scilab_code/Tutotial2_multi_plotting.sce35
-rw-r--r--Tutorial2_Plot/Scilab_code/Tutotial2_plot_save.sce20
-rw-r--r--Tutorial2_Plot/Scilab_code/Tutotial2_plotting.sce20
-rw-r--r--Tutorial3_Curve_fitting/Data/README.md1
-rw-r--r--Tutorial3_Curve_fitting/Problems/README.md1
-rw-r--r--Tutorial3_Curve_fitting/README.md1
-rw-r--r--Tutorial3_Curve_fitting/Scilab_code/README.md1
-rw-r--r--Tutorial4_ODE/Data/README.md1
-rw-r--r--Tutorial4_ODE/Problems/README.md1
-rw-r--r--Tutorial4_ODE/README.md1
-rw-r--r--Tutorial4_ODE/Scilab_code/README.md1
-rw-r--r--Tutorial5_Nonlinear_equation/Data/README.md1
-rw-r--r--Tutorial5_Nonlinear_equation/Problems/README.md1
-rw-r--r--Tutorial5_Nonlinear_equation/README.md1
-rw-r--r--Tutorial5_Nonlinear_equation/Scilab_code/README.md1
-rw-r--r--Tutorial5_Nonlinear_equation/Scilab_code/Tutotial5_nonlinear_equation.sce19
32 files changed, 340 insertions, 0 deletions
diff --git a/Tutorial1_Basic/Data/README.md b/Tutorial1_Basic/Data/README.md
new file mode 100644
index 0000000..7872997
--- /dev/null
+++ b/Tutorial1_Basic/Data/README.md
@@ -0,0 +1 @@
+# Data for matrix manipulation
diff --git a/Tutorial1_Basic/Data/Tut1_data1.csv b/Tutorial1_Basic/Data/Tut1_data1.csv
new file mode 100644
index 0000000..472523d
--- /dev/null
+++ b/Tutorial1_Basic/Data/Tut1_data1.csv
@@ -0,0 +1,16 @@
+0.05077,0.0038966667
+0.02751,0.00365
+0.02075,0.0036866667
+0.01881,0.0037333333
+0.01938,0.0037933333
+0.08237,0.00385
+0.03718,0.0038766667
+0.03714,0.0041033333
+0.03657,0.0039433333
+0.0362,0.00392
+0.048,0.0040733333
+0.04172,0.0040966667
+0.04115,0.0042166667
+0.0435,0.00409
+0.04202,0.0362
+0.0487,0.04172
diff --git a/Tutorial1_Basic/Problems/README.md b/Tutorial1_Basic/Problems/README.md
new file mode 100644
index 0000000..a7de39a
--- /dev/null
+++ b/Tutorial1_Basic/Problems/README.md
@@ -0,0 +1 @@
+# Problems for matrix manipulation
diff --git a/Tutorial1_Basic/README.md b/Tutorial1_Basic/README.md
new file mode 100644
index 0000000..75af7cd
--- /dev/null
+++ b/Tutorial1_Basic/README.md
@@ -0,0 +1 @@
+# Matrix manipulation
diff --git a/Tutorial1_Basic/Scilab_code/README.md b/Tutorial1_Basic/Scilab_code/README.md
new file mode 100644
index 0000000..275ce95
--- /dev/null
+++ b/Tutorial1_Basic/Scilab_code/README.md
@@ -0,0 +1 @@
+# Scilab code for matrix manipulation
diff --git a/Tutorial1_Basic/Scilab_code/Tutorial1_Matrix_manipulation.sce b/Tutorial1_Basic/Scilab_code/Tutorial1_Matrix_manipulation.sce
new file mode 100644
index 0000000..e4e06a6
--- /dev/null
+++ b/Tutorial1_Basic/Scilab_code/Tutorial1_Matrix_manipulation.sce
@@ -0,0 +1,105 @@
+//Script for Matrix manipulation tutorial
+//This script gives a demonstration of a few basic matrix operations used in Scilab
+
+//Manual entry of matrices (A,B,x)
+A = [1 2 3;3 2 1;2 4 5];
+B = [5 4 2;1 8 9;5 4 1];
+x = [1;2;3];
+
+//Elementwise Matrix operations
+//Summation of two matrices
+Mat_Sum = A + B;
+disp(Mat_Sum,'A+B');
+
+//Subtraction of a matrix from another
+Mat_Sub = A - B;
+disp(Mat_Sub,'A-B');
+
+//Elementwise multiplication of two matrices
+Mat_element_product = A.*B;
+disp(Mat_element_product,'A.*B');
+
+//Elementwise square of a matrix
+Mat_element_square = A.*A;
+disp(Mat_element_square,'A.*A');
+
+//Product of a scalar and matrix
+Mat_scalar_product = 5*A;
+disp(Mat_scalar_product,'5*A');
+
+//Elementwise square-root of a matrix
+Mat_sqrt = sqrt(A);
+disp(Mat_sqrt,'sqrt(A)');
+
+//Exponential of a matrix
+Mat_exp = exp(A);
+disp(Mat_exp,'exp(A)');
+
+
+
+//Matrix operations
+//Transpose of a matrix
+Mat_trans = A';
+disp(Mat_trans,'Atranspose');
+
+//Product of two matrices
+Mat_product = A*B;
+disp(Mat_product,'A*B');
+
+//Product of a matrix and vector
+Mat_vec_product = A*x;
+disp(Mat_vec_product,'A*x');
+
+//Square of a matrix
+Mat_square = A*A;
+disp(Mat_square,'A*A');
+
+//Higher powers of a matrix
+Mat_power_3 = A^3;
+disp(Mat_power_3, 'A^3');
+
+Mat_power_5 = A^5;
+disp(Mat_power_5,'A^5');
+
+
+//Range and size of matrices
+//Size of a matrix
+size_of_matrix = size(A);
+
+//Row and column size of a vector/matrix
+[row_size,column_size] = size(x);
+
+//Total number of elements in a matrix
+total_elements = length(A);
+
+//To extract an element of A
+Mat_element_31 = A(3,1);
+disp(Mat_element_31,'3rd row, 1st col element of A');
+
+//To extract a column of a matrix
+Mat_second_column = A(:,2);
+disp(Mat_second_column,'Second column of A');
+
+
+//To extract two columns of a matrix
+Mat_first_two_column = A(:,1:2);
+disp(Mat_first_two_column,'First two columns of A');
+
+//To extract a row of a matrix
+Mat_third_row = A(3,:);
+disp(Mat_third_row,'Third row of A');
+
+
+//Construction of special matrices
+//Identity matrix construction
+Identity_3 = eye(3,3);
+disp(Identity_3,'3 X 3 Identity matrix');
+
+//Zero matrix construction
+Zero_32 = zeros(3,2);
+disp(Zero_32,'3 X 2 Zero matrix');
+
+//All ones matrix
+Ones_45 = ones(4,5);
+disp(Ones_45,'4 X 5 all ones matrix');
+
diff --git a/Tutorial1_Basic/Scilab_code/Tutorial1_function.sce b/Tutorial1_Basic/Scilab_code/Tutorial1_function.sce
new file mode 100644
index 0000000..164430c
--- /dev/null
+++ b/Tutorial1_Basic/Scilab_code/Tutorial1_function.sce
@@ -0,0 +1,27 @@
+//This Matlab script is used to compute mean and standard deviation of data
+
+//Clears all previous variables stored
+clear
+
+//Clears screen
+clc
+
+
+//Executing the mymean function that computes the mean of a given data
+exec mymean.sci;
+//Executing the mystdev function that computes the standard deviation of a given data
+exec mystdev.sci;
+
+
+//Data for which the mean and standard-deviation is required
+x = [1 2 5];
+
+//Calling the mymean function. It takes data (a vector) as the input argument and returns mean of the data as output
+mean_of_x = mymean(x);
+disp(mean_of_x,'Mean of x');
+
+//Calling the mystdev function. It takes data (a vector) and its mean as the input argument
+//It returns standard deviation of the data as output
+stddev_of_x = mystdev(x,mean_of_x);
+disp(stddev_of_x,'Standard deviation of x');
+
diff --git a/Tutorial1_Basic/Scilab_code/Tutotial1_filehandling.sce b/Tutorial1_Basic/Scilab_code/Tutotial1_filehandling.sce
new file mode 100644
index 0000000..da9279a
--- /dev/null
+++ b/Tutorial1_Basic/Scilab_code/Tutotial1_filehandling.sce
@@ -0,0 +1,24 @@
+//This function is to import data from a csv file and store it in a variable
+//Using the data mean and standard deviation of the data is computed
+clear
+clc
+
+exec mymean.sci;
+exec mystdev.sci;
+
+//Import data from file
+Data = csvRead('/home/chayan/Documents/scilab-tutorials/Tutorial1/Data/Tut1_data1.csv');
+x = Data(:,1);
+y = Data(:,2);
+
+
+//Compute mean of the imported data
+mean_of_Data_x = mymean(x);
+
+//Compute standard deviation of the imported data
+standard_deviation_of_Data_x= mystdev(x,mean_of_Data_x);
+
+
+//Display mean and standard deviation in command window
+disp(mean_of_Data_x,'Mean of x',standard_deviation_of_Data_x,'Standard deviation of x')
+
diff --git a/Tutorial1_Basic/Scilab_code/mymean.sci b/Tutorial1_Basic/Scilab_code/mymean.sci
new file mode 100644
index 0000000..6a96da4
--- /dev/null
+++ b/Tutorial1_Basic/Scilab_code/mymean.sci
@@ -0,0 +1,9 @@
+//Function to compute mean of a given data (a vector)
+
+function mean_of_data = mymean(data)
+ sum_of_data = 0;
+ for iteration = 1:1:length(data)
+ sum_of_data = data(iteration) + sum_of_data;
+ end
+ mean_of_data = sum_of_data/length(data);
+endfunction
diff --git a/Tutorial1_Basic/Scilab_code/mystdev.sci b/Tutorial1_Basic/Scilab_code/mystdev.sci
new file mode 100644
index 0000000..53849a4
--- /dev/null
+++ b/Tutorial1_Basic/Scilab_code/mystdev.sci
@@ -0,0 +1,8 @@
+//A function to compute standard deviation of a given data
+//Input: Data (a vector) and mean of the data as input
+//Output: standard deviation of the data
+
+function standard_dev = mystdev(data,mean_of_data)
+ temp = (data - mean_of_data*ones(length(data)))^2;
+ standard_dev = sqrt(sum(temp)/(length(data)-1));
+endfunction
diff --git a/Tutorial2_Plot/Data/README.md b/Tutorial2_Plot/Data/README.md
new file mode 100644
index 0000000..a8e89e2
--- /dev/null
+++ b/Tutorial2_Plot/Data/README.md
@@ -0,0 +1 @@
+# Data for scientific plotting
diff --git a/Tutorial2_Plot/Data/Tut2_data1.csv b/Tutorial2_Plot/Data/Tut2_data1.csv
new file mode 100644
index 0000000..974af87
--- /dev/null
+++ b/Tutorial2_Plot/Data/Tut2_data1.csv
@@ -0,0 +1,15 @@
+1,3.33333333333333E-05,3.33333333333333E-06,3.33333333333333E-06,0.0036866667
+2,7.33333333333333E-05,0,3.33333333333333E-06,0.0038966667
+3,2.33333333333333E-05,0,3.33333333333333E-06,0.00365
+4,0.00003,0,6.66666666666667E-06,0.0036866667
+5,3.33333333333333E-05,0,3.33333333333333E-06,0.0037333333
+6,3.33333333333333E-05,0,3.33333333333333E-06,0.0037933333
+7,0.00004,0,3.33333333333333E-06,0.00385
+8,0.00004,3.33333333333333E-06,0.00001,0.0038766667
+9,0.00005,3.33333333333333E-06,3.33333333333333E-06,0.0041033333
+10,4.66666666666667E-05,0.00001,6.66666666666667E-06,0.0039433333
+11,0.00004,3.33333333333333E-06,6.66666666666667E-06,0.00392
+12,0.00005,0.00001,0.00001,0.0040733333
+13,5.66666666666667E-05,0.00001,0.00001,0.0040966667
+14,6.33333333333333E-05,6.66666666666667E-06,1.66666666666667E-05,0.0042166667
+15,5.66666666666667E-05,6.66666666666667E-06,0.00001,0.00409
diff --git a/Tutorial2_Plot/Problems/README.md b/Tutorial2_Plot/Problems/README.md
new file mode 100644
index 0000000..5a77a1e
--- /dev/null
+++ b/Tutorial2_Plot/Problems/README.md
@@ -0,0 +1 @@
+# Problems for scientific plotting
diff --git a/Tutorial2_Plot/README.md b/Tutorial2_Plot/README.md
new file mode 100644
index 0000000..f99bc98
--- /dev/null
+++ b/Tutorial2_Plot/README.md
@@ -0,0 +1 @@
+# Scientific plotting
diff --git a/Tutorial2_Plot/Scilab_code/README.md b/Tutorial2_Plot/Scilab_code/README.md
new file mode 100644
index 0000000..150fc44
--- /dev/null
+++ b/Tutorial2_Plot/Scilab_code/README.md
@@ -0,0 +1 @@
+# Scilab code for scientific plotting
diff --git a/Tutorial2_Plot/Scilab_code/Tutorial2_semilog.sce b/Tutorial2_Plot/Scilab_code/Tutorial2_semilog.sce
new file mode 100644
index 0000000..070290c
--- /dev/null
+++ b/Tutorial2_Plot/Scilab_code/Tutorial2_semilog.sce
@@ -0,0 +1,22 @@
+//This script demonstrate multi-plotting in Scilab
+clear
+clc
+
+//Import data from file
+Data = csvRead('/home/chayan/Documents/scilab-tutorials/Tutorial2/Data/Tut2_data1.csv');
+
+//Segregate the data into variables
+y = Data(:,1);
+x = [Data(:,4) Data(:,5)]
+
+
+//Figure 1 is a semilog plot
+fig1 = figure();
+plot2d(y,x,[1,2],logflag="nl")
+legends(['Length of x1','Length of x3'],[1,2],opt="ur",font_size=1,font);
+
+
+//Figure 2 is a loglog plot
+fig2 = figure();
+plot2d(y,x,[3,-1],logflag="ll")
+legends(['Length of x1','Length of x3'],[3,-1],opt="ur",font_size=1);
diff --git a/Tutorial2_Plot/Scilab_code/Tutotial2_multi_plotting.sce b/Tutorial2_Plot/Scilab_code/Tutotial2_multi_plotting.sce
new file mode 100644
index 0000000..91e4f20
--- /dev/null
+++ b/Tutorial2_Plot/Scilab_code/Tutotial2_multi_plotting.sce
@@ -0,0 +1,35 @@
+//This script demonstrate multi-plotting in Scilab
+clear
+clc
+
+//Import data from file
+Data = csvRead('/home/chayan/Documents/scilab-tutorials/Tutorial2/Data/Tut2_data1.csv');
+
+//Segregate the data into variables
+y = Data(:,1);
+x = [Data(:,2) Data(:,4)]
+
+//Fixing the range of plot
+//Range is defined by [xmin,xmax,ymin,ymax]
+range_of_plot = [-10,1e-05,20,10e-05]
+
+//Style of plot
+//Stricly positive value represent the color
+//Negative or zero value means given curve points are drawn using marks
+//For color of marks use polyline property
+style_plot = [-1,2]
+
+//Plotting y versus two data sets
+plot2d(y,x,style_plot,rect=range_of_plot);
+
+
+//For labelling axes and adding a title to the plot
+xtitle('Plot of Time versus Length_x1 and Length_x3','Time','Length');
+
+
+//For legends "ur" for upper right
+//legends(['Length of x1','Length of x3'],[-1,2]); //Default case
+//legends(['Length of x1','Length of x3'],[-1,2],opt="ur"); //Position of the legend box
+legends(['Length of x1','Length of x3'],[-1,2],opt="ur",font_size=2); //Font size of the legends
+
+
diff --git a/Tutorial2_Plot/Scilab_code/Tutotial2_plot_save.sce b/Tutorial2_Plot/Scilab_code/Tutotial2_plot_save.sce
new file mode 100644
index 0000000..1cf2566
--- /dev/null
+++ b/Tutorial2_Plot/Scilab_code/Tutotial2_plot_save.sce
@@ -0,0 +1,20 @@
+//This script demonstrate exporting plots to svg/pdf files
+clear
+clc
+
+//Import data from file
+Data = csvRead('/home/chayan/Documents/scilab-tutorials/Tutorial2/Data/Tut2_data1.csv');
+
+//Segregate the data into variables
+y = Data(:,1);
+x1 = Data(:,2)
+
+//Figure 1 is y versus x1
+fig1 = figure();
+plot(y,x1);
+
+//Export Figure 1 as svg file
+xs2svg(fig1,'plot_y_versus_x1')
+
+//Export Figure 2 as pdf file
+xs2pdf(fig1,'plot_y_versus_x1')
diff --git a/Tutorial2_Plot/Scilab_code/Tutotial2_plotting.sce b/Tutorial2_Plot/Scilab_code/Tutotial2_plotting.sce
new file mode 100644
index 0000000..b191b80
--- /dev/null
+++ b/Tutorial2_Plot/Scilab_code/Tutotial2_plotting.sce
@@ -0,0 +1,20 @@
+//This script demonstrate plotting in Scilab
+clear
+clc
+
+//Import data from file
+Data = csvRead('/home/chayan/Documents/scilab-tutorials/Tutorial2/Data/Tut2_data1.csv');
+
+//Segregate the data into variables
+y = Data(:,1);
+x1 = Data(:,2);
+x2 = Data(:,3);
+x3 = Data(:,4);
+x4 = Data(:,5);
+
+//Plotting y versus x1
+plot(y,x1);
+
+
+
+
diff --git a/Tutorial3_Curve_fitting/Data/README.md b/Tutorial3_Curve_fitting/Data/README.md
new file mode 100644
index 0000000..7b5f1bd
--- /dev/null
+++ b/Tutorial3_Curve_fitting/Data/README.md
@@ -0,0 +1 @@
+# Data for curve fitting
diff --git a/Tutorial3_Curve_fitting/Problems/README.md b/Tutorial3_Curve_fitting/Problems/README.md
new file mode 100644
index 0000000..565101b
--- /dev/null
+++ b/Tutorial3_Curve_fitting/Problems/README.md
@@ -0,0 +1 @@
+# Problems for curve fitting
diff --git a/Tutorial3_Curve_fitting/README.md b/Tutorial3_Curve_fitting/README.md
new file mode 100644
index 0000000..0b8b421
--- /dev/null
+++ b/Tutorial3_Curve_fitting/README.md
@@ -0,0 +1 @@
+# Curve fitting
diff --git a/Tutorial3_Curve_fitting/Scilab_code/README.md b/Tutorial3_Curve_fitting/Scilab_code/README.md
new file mode 100644
index 0000000..37230ff
--- /dev/null
+++ b/Tutorial3_Curve_fitting/Scilab_code/README.md
@@ -0,0 +1 @@
+# Scilab code for curve fitting
diff --git a/Tutorial4_ODE/Data/README.md b/Tutorial4_ODE/Data/README.md
new file mode 100644
index 0000000..b212332
--- /dev/null
+++ b/Tutorial4_ODE/Data/README.md
@@ -0,0 +1 @@
+# Data for ODE
diff --git a/Tutorial4_ODE/Problems/README.md b/Tutorial4_ODE/Problems/README.md
new file mode 100644
index 0000000..5ccbfe0
--- /dev/null
+++ b/Tutorial4_ODE/Problems/README.md
@@ -0,0 +1 @@
+# Problems for ODE
diff --git a/Tutorial4_ODE/README.md b/Tutorial4_ODE/README.md
new file mode 100644
index 0000000..841c27b
--- /dev/null
+++ b/Tutorial4_ODE/README.md
@@ -0,0 +1 @@
+# Ordinary differential equation
diff --git a/Tutorial4_ODE/Scilab_code/README.md b/Tutorial4_ODE/Scilab_code/README.md
new file mode 100644
index 0000000..78de9d2
--- /dev/null
+++ b/Tutorial4_ODE/Scilab_code/README.md
@@ -0,0 +1 @@
+# Scilab code for ODE
diff --git a/Tutorial5_Nonlinear_equation/Data/README.md b/Tutorial5_Nonlinear_equation/Data/README.md
new file mode 100644
index 0000000..febbdf8
--- /dev/null
+++ b/Tutorial5_Nonlinear_equation/Data/README.md
@@ -0,0 +1 @@
+# Data for non-linear equations
diff --git a/Tutorial5_Nonlinear_equation/Problems/README.md b/Tutorial5_Nonlinear_equation/Problems/README.md
new file mode 100644
index 0000000..f7a9032
--- /dev/null
+++ b/Tutorial5_Nonlinear_equation/Problems/README.md
@@ -0,0 +1 @@
+# Problems for non-linear equations
diff --git a/Tutorial5_Nonlinear_equation/README.md b/Tutorial5_Nonlinear_equation/README.md
new file mode 100644
index 0000000..56a4129
--- /dev/null
+++ b/Tutorial5_Nonlinear_equation/README.md
@@ -0,0 +1 @@
+# Non-linear equations
diff --git a/Tutorial5_Nonlinear_equation/Scilab_code/README.md b/Tutorial5_Nonlinear_equation/Scilab_code/README.md
new file mode 100644
index 0000000..297d7b8
--- /dev/null
+++ b/Tutorial5_Nonlinear_equation/Scilab_code/README.md
@@ -0,0 +1 @@
+# Scilab code for non-linear equations
diff --git a/Tutorial5_Nonlinear_equation/Scilab_code/Tutotial5_nonlinear_equation.sce b/Tutorial5_Nonlinear_equation/Scilab_code/Tutotial5_nonlinear_equation.sce
new file mode 100644
index 0000000..6ab3a23
--- /dev/null
+++ b/Tutorial5_Nonlinear_equation/Scilab_code/Tutotial5_nonlinear_equation.sce
@@ -0,0 +1,19 @@
+//This scilab script is to compute the solution of a nonlinear function with initial
+//guess x_0
+clear
+clc
+
+
+//The nonlinear equation for which solutions are sought
+function y = nonlinear_func(x)
+ y = cos(x)*sin(x) - tan(x) + 1
+endfunction
+
+
+//Initial guess for the solution
+x0 = 0;
+
+//Computation of solution using fsolve
+y_result = fsolve(x0,nonlinear_func);
+
+disp(y_result,'Solution of the equation')