diff options
author | P Sunthar | 2018-10-02 00:09:14 +0530 |
---|---|---|
committer | P Sunthar | 2018-10-02 00:09:14 +0530 |
commit | 6d39446c434cfcca02ae7a4551e2d66edf9def7f (patch) | |
tree | f0e84e8fadd28600bfdeadf1471d59be5eaee54a /Tutorial01-Basics | |
parent | 4d0d95e5748137abe4636dc734b03b4e7ccfd6f5 (diff) | |
download | scilab-tutorials-6d39446c434cfcca02ae7a4551e2d66edf9def7f.tar.gz scilab-tutorials-6d39446c434cfcca02ae7a4551e2d66edf9def7f.tar.bz2 scilab-tutorials-6d39446c434cfcca02ae7a4551e2d66edf9def7f.zip |
Renamed dirs
Diffstat (limited to 'Tutorial01-Basics')
-rw-r--r-- | Tutorial01-Basics/Data/README.md | 1 | ||||
-rw-r--r-- | Tutorial01-Basics/Data/Tut1_data1.csv | 16 | ||||
-rw-r--r-- | Tutorial01-Basics/Problems/README.md | 1 | ||||
-rw-r--r-- | Tutorial01-Basics/Problems/Tut1.pdf | bin | 0 -> 67566 bytes | |||
-rw-r--r-- | Tutorial01-Basics/README.md | 1 | ||||
-rw-r--r-- | Tutorial01-Basics/Scilab_code/README.md | 1 | ||||
-rw-r--r-- | Tutorial01-Basics/Scilab_code/Tutorial1_Matrix_manipulation.sce | 105 | ||||
-rw-r--r-- | Tutorial01-Basics/Scilab_code/Tutorial1_function.sce | 27 | ||||
-rw-r--r-- | Tutorial01-Basics/Scilab_code/Tutotial1_filehandling.sce | 23 | ||||
-rw-r--r-- | Tutorial01-Basics/Scilab_code/mymean.sci | 9 | ||||
-rw-r--r-- | Tutorial01-Basics/Scilab_code/mystdev.sci | 8 |
11 files changed, 192 insertions, 0 deletions
diff --git a/Tutorial01-Basics/Data/README.md b/Tutorial01-Basics/Data/README.md new file mode 100644 index 0000000..7872997 --- /dev/null +++ b/Tutorial01-Basics/Data/README.md @@ -0,0 +1 @@ +# Data for matrix manipulation diff --git a/Tutorial01-Basics/Data/Tut1_data1.csv b/Tutorial01-Basics/Data/Tut1_data1.csv new file mode 100644 index 0000000..472523d --- /dev/null +++ b/Tutorial01-Basics/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/Tutorial01-Basics/Problems/README.md b/Tutorial01-Basics/Problems/README.md new file mode 100644 index 0000000..a7de39a --- /dev/null +++ b/Tutorial01-Basics/Problems/README.md @@ -0,0 +1 @@ +# Problems for matrix manipulation diff --git a/Tutorial01-Basics/Problems/Tut1.pdf b/Tutorial01-Basics/Problems/Tut1.pdf Binary files differnew file mode 100644 index 0000000..24abc4f --- /dev/null +++ b/Tutorial01-Basics/Problems/Tut1.pdf diff --git a/Tutorial01-Basics/README.md b/Tutorial01-Basics/README.md new file mode 100644 index 0000000..75af7cd --- /dev/null +++ b/Tutorial01-Basics/README.md @@ -0,0 +1 @@ +# Matrix manipulation diff --git a/Tutorial01-Basics/Scilab_code/README.md b/Tutorial01-Basics/Scilab_code/README.md new file mode 100644 index 0000000..275ce95 --- /dev/null +++ b/Tutorial01-Basics/Scilab_code/README.md @@ -0,0 +1 @@ +# Scilab code for matrix manipulation diff --git a/Tutorial01-Basics/Scilab_code/Tutorial1_Matrix_manipulation.sce b/Tutorial01-Basics/Scilab_code/Tutorial1_Matrix_manipulation.sce new file mode 100644 index 0000000..e4e06a6 --- /dev/null +++ b/Tutorial01-Basics/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/Tutorial01-Basics/Scilab_code/Tutorial1_function.sce b/Tutorial01-Basics/Scilab_code/Tutorial1_function.sce new file mode 100644 index 0000000..164430c --- /dev/null +++ b/Tutorial01-Basics/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/Tutorial01-Basics/Scilab_code/Tutotial1_filehandling.sce b/Tutorial01-Basics/Scilab_code/Tutotial1_filehandling.sce new file mode 100644 index 0000000..2924f03 --- /dev/null +++ b/Tutorial01-Basics/Scilab_code/Tutotial1_filehandling.sce @@ -0,0 +1,23 @@ +//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 csv file +Data = csvRead('../Data/Tut1_data1.csv'); +x = Data(:,1); +y = Data(:,2); + + +//Compute mean of the imported data +mean_of_x = mymean(x); +//Compute standard deviation of the imported data +stdev_of_x= mystdev(x,mean_of_x); + +//Data to be exported (It can be a scalar, vector or matrix) +data_to_write = [mean_of_x stdev_of_x]; +//Export data to a csv file +csvWrite(data_to_write,'../Data/Tut1_data3.csv') diff --git a/Tutorial01-Basics/Scilab_code/mymean.sci b/Tutorial01-Basics/Scilab_code/mymean.sci new file mode 100644 index 0000000..6a96da4 --- /dev/null +++ b/Tutorial01-Basics/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/Tutorial01-Basics/Scilab_code/mystdev.sci b/Tutorial01-Basics/Scilab_code/mystdev.sci new file mode 100644 index 0000000..53849a4 --- /dev/null +++ b/Tutorial01-Basics/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 |