summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChayan Bhawal2018-10-01 03:21:11 +0530
committerChayan Bhawal2018-10-01 03:21:11 +0530
commitd70da5e732149071f715e080407aa5c74e3da44a (patch)
treeab5273a19f600fde8406eb7ad8431196dd8b39ff
parent20c792454b7757064cb5ced103357bfed42d9b1a (diff)
downloadscilab-tutorials-d70da5e732149071f715e080407aa5c74e3da44a.tar.gz
scilab-tutorials-d70da5e732149071f715e080407aa5c74e3da44a.tar.bz2
scilab-tutorials-d70da5e732149071f715e080407aa5c74e3da44a.zip
Problems_updated
-rw-r--r--Tutorial1_Basic/Data/Tut1_data2.dat15
-rw-r--r--Tutorial1_Basic/Data/Tut1_data3.csv1
-rw-r--r--Tutorial1_Basic/Problems/Tut1.pdfbin0 -> 67566 bytes
-rw-r--r--Tutorial1_Basic/Scilab_code/Tutotial1_filehandling.sce20
-rw-r--r--Tutorial2_Plot/Problems/Tut2.pdfbin0 -> 29099 bytes
-rw-r--r--Tutorial2_Plot/Problems/Tut2Problem.csv15
-rw-r--r--Tutorial2_Plot/Scilab_code/Tutorial2_semilog.sce16
-rw-r--r--Tutorial2_Plot/Scilab_code/Tutotial2_multi_plotting.sce41
-rw-r--r--Tutorial2_Plot/Scilab_code/Tutotial2_plot_save.sce21
-rw-r--r--Tutorial2_Plot/Scilab_code/Tutotial2_plot_save_func.sce27
-rw-r--r--Tutorial2_Plot/Scilab_code/Tutotial2_plotting.sce16
-rw-r--r--Tutorial2_Plot/Scilab_code/change_plot_attribs.sci10
-rw-r--r--Tutorial3_Curve_fitting/Problems/Tut3.pdfbin0 -> 43895 bytes
-rw-r--r--Tutorial3_Curve_fitting/Problems/Tut3Problem.csv91
-rw-r--r--Tutorial3_Curve_fitting/Scilab_code/Tutorial3_curve_fitting.sce17
-rw-r--r--Tutorial3_Curve_fitting/Scilab_code/Tutorial3_curve_fitting_weighted.sce37
-rw-r--r--Tutorial3_Curve_fitting/Scilab_code/errorfun.sci4
-rw-r--r--Tutorial3_Curve_fitting/Scilab_code/errorfunweight.sci4
-rw-r--r--Tutorial4_ODE/Data/README.md1
-rw-r--r--Tutorial4_ODE/Problems/Tut4.pdfbin0 -> 50507 bytes
-rw-r--r--Tutorial4_ODE/Scilab_code/Tutorial4_ode_matrix.sce2
-rw-r--r--Tutorial4_ODE/Scilab_code/Tutorial4_ode_simple.sce4
-rw-r--r--Tutorial4_ODE/Scilab_code/Tutorial4_ode_simple_plot.sce13
-rw-r--r--Tutorial5_Solution_of_equations/Problems/README.md1
-rw-r--r--Tutorial5_Solution_of_equations/Problems/Tut5.pdfbin0 -> 64565 bytes
-rw-r--r--Tutorial5_Solution_of_equations/README.md1
-rw-r--r--Tutorial5_Solution_of_equations/Scilab_code/README.md1
-rw-r--r--Tutorial5_Solution_of_equations/Scilab_code/Tutotial5_linear_equation.sce22
-rw-r--r--Tutorial5_Solution_of_equations/Scilab_code/Tutotial5_nonlinear_equation.sce21
-rw-r--r--Tutorial5_Solution_of_equations/Scilab_code/Tutotial5_nonlinear_equation_twovar.sce17
-rw-r--r--Tutorial5_Solution_of_equations/Scilab_code/func.sci4
-rw-r--r--Tutorial5_Solution_of_equations/Scilab_code/functwovar.sci6
32 files changed, 341 insertions, 87 deletions
diff --git a/Tutorial1_Basic/Data/Tut1_data2.dat b/Tutorial1_Basic/Data/Tut1_data2.dat
deleted file mode 100644
index 8d79fe3..0000000
--- a/Tutorial1_Basic/Data/Tut1_data2.dat
+++ /dev/null
@@ -1,15 +0,0 @@
-#Obtained from a dummy data for illustration in https://docs.google.com/spreadsheets/d/1mIbdSO35zmm4SJcIXE89_-sk_ZBsB1qKnhiLdgY_-FE/edit#gid=0
-#Grinv Nuexpt err
-0.001 17.52228506 0.5
-0.002511886432 15.39548247 0.5
-0.006309573445 10.72315424 0.5
-0.01 7.490637629 0.5
-0.02511886432 7.573613426 0.5
-0.06309573445 6.521758867 0.5
-0.1 4.85299648 0.5
-0.2511886432 5.179305259 0.5
-0.6309573445 4.544433719 0.5
-1 5.009578782 0.5
-2.511886432 5.126719895 0.5
-6.309573445 4.478903266 0.5
-10 5.431082153 0.5
diff --git a/Tutorial1_Basic/Data/Tut1_data3.csv b/Tutorial1_Basic/Data/Tut1_data3.csv
new file mode 100644
index 0000000..b8a1e42
--- /dev/null
+++ b/Tutorial1_Basic/Data/Tut1_data3.csv
@@ -0,0 +1 @@
+0.039485624999999996,0.015297881756962301
diff --git a/Tutorial1_Basic/Problems/Tut1.pdf b/Tutorial1_Basic/Problems/Tut1.pdf
new file mode 100644
index 0000000..24abc4f
--- /dev/null
+++ b/Tutorial1_Basic/Problems/Tut1.pdf
Binary files differ
diff --git a/Tutorial1_Basic/Scilab_code/Tutotial1_filehandling.sce b/Tutorial1_Basic/Scilab_code/Tutotial1_filehandling.sce
index a429533..a2e4696 100644
--- a/Tutorial1_Basic/Scilab_code/Tutotial1_filehandling.sce
+++ b/Tutorial1_Basic/Scilab_code/Tutotial1_filehandling.sce
@@ -7,23 +7,17 @@ exec mymean.sci;
exec mystdev.sci;
//Import data from csv file
-Data = csvRead('/home/chayan/Documents/scilab-tutorials/Tutorial1/Data/Tut1_data1.csv');
+Data = csvRead('/home/chayan/Documents/scilab-tutorials/Tutorial1_Basic/Data/Tut1_data1.csv');
x = Data(:,1);
y = Data(:,2);
//Compute mean of the imported data
-mean_of_Data_x = mymean(x);
-
+mean_of_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')
-
-
-//Importing data from dat file
-Mat = fscanfMat('Data/Tut1_data2.dat');
-disp(Mat,'Data in the file');
+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,'/home/chayan/Documents/scilab-tutorials/Tutorial1_Basic/Data/Tut1_data3.csv')
diff --git a/Tutorial2_Plot/Problems/Tut2.pdf b/Tutorial2_Plot/Problems/Tut2.pdf
new file mode 100644
index 0000000..ddc5da8
--- /dev/null
+++ b/Tutorial2_Plot/Problems/Tut2.pdf
Binary files differ
diff --git a/Tutorial2_Plot/Problems/Tut2Problem.csv b/Tutorial2_Plot/Problems/Tut2Problem.csv
new file mode 100644
index 0000000..53ce715
--- /dev/null
+++ b/Tutorial2_Plot/Problems/Tut2Problem.csv
@@ -0,0 +1,15 @@
+1,1.05E-14,1E-23,8.68735727748734E-16,3.06988472271084E-16
+2,1.05E-14,1E-23,8.68735727748734E-16,3.06988472271084E-16
+3,1.00E-14,3.70119513918373E-17,2.79736087695949E-15,2.80391266864912E-16
+4,3.70E-14,5.65E-14,1.04559200525073E-14,7.3865291428153E-16
+5,3.70E-14,1.4571218255213E-18,7.01651859869889E-15,8.11719142528036E-16
+6,1.00E-15,1.17015966442439E-18,7.7095815167149E-15,2.05292485680238E-13
+7,3.70E-15,3.80212541554568E-19,2.15320675526335E-14,1.19013817278563E-14
+8,3.70E-15,5.85059486105432E-20,1.54664178302948E-14,8.79191968097034E-13
+9,1.11E-14,3.76606511037024E-17,3.26447099775275E-14,7.32859431036281E-13
+10,3.70074341541719E-17,2.42958520611185E-19,3.81298644807883E-14,4.28588268926054E-12
+11,1E-23,1.78899096261478E-18,1.35509320162881E-13,1.01359319772089E-12
+12,1E-23,2.42863790449231E-19,1.71955664104378E-13,3.2126484715214E-13
+13,1.11022302462516E-16,1.68809380852638E-16,6.08815500389293E-13,7.94331887098062E-14
+14,1.11022302462516E-16,3.40508595605121E-16,3.84924467610673E-13,4.54796283179633E-15
+15,1.57009245868378E-16,3.78577179124018E-16,5.2850172570156E-13,1.20783040520019E-11
diff --git a/Tutorial2_Plot/Scilab_code/Tutorial2_semilog.sce b/Tutorial2_Plot/Scilab_code/Tutorial2_semilog.sce
index 833855b..9acc3a6 100644
--- a/Tutorial2_Plot/Scilab_code/Tutorial2_semilog.sce
+++ b/Tutorial2_Plot/Scilab_code/Tutorial2_semilog.sce
@@ -1,6 +1,7 @@
//This script demonstrate multi-plotting in Scilab
clear
clc
+exec change_plot_attribs.sci;
//Import data from file
Data = csvRead('/home/chayan/Documents/scilab-tutorials/Tutorial2_Plot/Data/Tut2_data1.csv');
@@ -9,14 +10,19 @@ Data = csvRead('/home/chayan/Documents/scilab-tutorials/Tutorial2_Plot/Data/Tut2
y = Data(:,1);
x = [Data(:,4) Data(:,5)]
+//Style of plot
+style_plot = [1,2]
//Figure 1 is a semilog plot
-fig1 = figure();
+fig1 = scf();
plot2d(y,x,[1,2],logflag="nl")
-legends(['Length of x1','Length of x3'],[1,2],opt="ur",font_size=1);
+legends(['Length of x1','Length of x3'],style_plot,opt="ur",font_size=1);
+change_plot_attribs('Time','Data','Sample semi-log plot',5,5,3)
//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);
+fig2 = scf();
+plot2d(y,x,style_plot,logflag="ll")
+legends(['Length of x1','Length of x3'],style_plot,opt="ur",font_size=1);
+change_plot_attribs('Time','Data','Figure2 (loglog)',5,5,3)
+
diff --git a/Tutorial2_Plot/Scilab_code/Tutotial2_multi_plotting.sce b/Tutorial2_Plot/Scilab_code/Tutotial2_multi_plotting.sce
index e149334..ec5b193 100644
--- a/Tutorial2_Plot/Scilab_code/Tutotial2_multi_plotting.sce
+++ b/Tutorial2_Plot/Scilab_code/Tutotial2_multi_plotting.sce
@@ -1,37 +1,36 @@
-//This script demonstrate multi-plotting in Scilab
+//This script demonstrates multi-plotting in Scilab
clear
clc
+exec change_plot_attribs.sci;
//Import data from file
Data = csvRead('/home/chayan/Documents/scilab-tutorials/Tutorial2_Plot/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]
+t = Data(:,1);
+x = [Data(:,2:4)]
//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');
+style_plot = [1,2,4]
+//Fixing the range of plot
+//Range is defined by [xmin,ymin,xmax,ymax]
+range_of_plot = [1,-1e-5,15,8e-05];
+//Plotting y versus two data sets
+//plot2d(t,x,style_plot);
+plot2d(t,x,style_plot,rect=range_of_plot);
+
+//Font size and labels for legends
//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
+legends(['x1','x2', 'x3'],style_plot,opt="ur",font_size=2);
+
+//Call function to change plot attributes
+change_plot_attribs('Time','Data','Data versus Time',5,5,3)
+//For thickness of the plots
+attrib = gcf();
+attrib.children(2).children(1).children.thickness = 3;
diff --git a/Tutorial2_Plot/Scilab_code/Tutotial2_plot_save.sce b/Tutorial2_Plot/Scilab_code/Tutotial2_plot_save.sce
index 20a8427..a3da8f3 100644
--- a/Tutorial2_Plot/Scilab_code/Tutotial2_plot_save.sce
+++ b/Tutorial2_Plot/Scilab_code/Tutotial2_plot_save.sce
@@ -6,13 +6,24 @@ clc
Data = csvRead('/home/chayan/Documents/scilab-tutorials/Tutorial2_Plot/Data/Tut2_data1.csv');
//Segregate the data into variables
-y = Data(:,1);
-x1 = Data(:,2)
+t = Data(:,1);
+x = Data(:,2)
-//Figure 1 is y versus x1 with linewidth = 3
-//fig1 = figure();
+//Ploting the figure. Name of the figure is fig1;
+//Use the field Linewidth to specify thickness of the plot
fig1 = scf(1);
-plot(y,x1,'Linewidth',3);
+plot(t,x,'Linewidth',3);
+
+//Adding title, xlabels and ylabels
+//Changing thickness and textsize in plot
+attrib_axes = gca(); //Attributes of axes of active handle
+attrib_axes.x_label.text = 'Time'; //X-label
+attrib_axes.y_label.text = 'Data'; //Y-label
+attrib_axes.title.text = 'x versus t'; //Title of the plot
+attrib_axes.x_label.font_size = 5; //X_label font size
+attrib_axes.y_label.font_size = 5; //Y_label font size
+attrib_axes.title.font_size = 5; //Title font size
+attrib_axes.font_size = 4; //Font size of x-axis and y-axis
//Export Figure 1 as svg file
xs2svg(fig1,'plot_y_versus_x1');
diff --git a/Tutorial2_Plot/Scilab_code/Tutotial2_plot_save_func.sce b/Tutorial2_Plot/Scilab_code/Tutotial2_plot_save_func.sce
new file mode 100644
index 0000000..d8f9963
--- /dev/null
+++ b/Tutorial2_Plot/Scilab_code/Tutotial2_plot_save_func.sce
@@ -0,0 +1,27 @@
+//This script demonstrate exporting plots to svg/pdf files
+clear
+clc
+
+exec change_plot_attribs.sci;
+
+//Import data from file
+Data = csvRead('/home/chayan/Documents/scilab-tutorials/Tutorial2_Plot/Data/Tut2_data1.csv');
+
+//Segregate the data into variables
+t = Data(:,1);
+x = Data(:,2)
+
+//Ploting the figure. Name of the figure is fig1;
+//Use the field Linewidth to specify thickness of the plot
+fig1 = scf(1);
+plot(t,x,'Linewidth',3);
+
+//Call function to change plot attributes
+//Arguments (x_label,y_label,title,label_size,title_size,fontsize)
+change_plot_attribs('Time','Data','x versus t',7,6,3)
+
+//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
index f16018c..5494863 100644
--- a/Tutorial2_Plot/Scilab_code/Tutotial2_plotting.sce
+++ b/Tutorial2_Plot/Scilab_code/Tutotial2_plotting.sce
@@ -1,4 +1,4 @@
-//This script demonstrate plotting in Scilab
+//This script demonstrate basic plot command in Scilab
clear
clc
@@ -6,15 +6,11 @@ clc
Data = csvRead('/home/chayan/Documents/scilab-tutorials/Tutorial2_Plot/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);
-
+t = Data(:,1);
+x = Data(:,2);
+//Plotting x versus t
+plot(t,x);
+xtitle('A x versus t plot','Time','Data')
diff --git a/Tutorial2_Plot/Scilab_code/change_plot_attribs.sci b/Tutorial2_Plot/Scilab_code/change_plot_attribs.sci
new file mode 100644
index 0000000..68a04bd
--- /dev/null
+++ b/Tutorial2_Plot/Scilab_code/change_plot_attribs.sci
@@ -0,0 +1,10 @@
+function change_plot_attribs(xlab,ylab,caption,labelsize,capsize,fontsize)
+ attrib_axes = gca(); //Attributes of axes of active handle
+ attrib_axes.x_label.text = xlab; //X-label
+ attrib_axes.y_label.text = ylab; //Y-label
+ attrib_axes.title.text = caption; //Title of the plot
+ attrib_axes.x_label.font_size = labelsize; //X_label font size
+ attrib_axes.y_label.font_size = labelsize; //Y_label font size
+ attrib_axes.title.font_size = capsize; //Title font size
+ attrib_axes.font_size = fontsize; //Font size of x-axis and y-axis
+endfunction
diff --git a/Tutorial3_Curve_fitting/Problems/Tut3.pdf b/Tutorial3_Curve_fitting/Problems/Tut3.pdf
new file mode 100644
index 0000000..c65c9e2
--- /dev/null
+++ b/Tutorial3_Curve_fitting/Problems/Tut3.pdf
Binary files differ
diff --git a/Tutorial3_Curve_fitting/Problems/Tut3Problem.csv b/Tutorial3_Curve_fitting/Problems/Tut3Problem.csv
new file mode 100644
index 0000000..6840862
--- /dev/null
+++ b/Tutorial3_Curve_fitting/Problems/Tut3Problem.csv
@@ -0,0 +1,91 @@
+1,1.6217170325525478
+1.1000000000000001,1.7361607926542162
+1.2,1.4886611048766012
+1.3,1.6095812042057687
+1.3999999999999999,1.3163168146419344
+1.5,1.330920700128845
+1.6000000000000001,1.110366283597638
+1.7000000000000002,0.81241353160410024
+1.8,0.753186814760053
+1.8999999999999999,0.69330057676696411
+2,0.49673930861054816
+2.1000000000000001,0.31269839670758381
+2.2000000000000002,0.20735326026520753
+2.2999999999999998,0.34251898976490369
+2.4000000000000004,0.017995492701055816
+2.5,0.15030667407027673
+2.6000000000000001,-0.10873060024156005
+2.7000000000000002,0.039912435622286677
+2.7999999999999998,-0.054524639195131827
+2.9000000000000004,-0.033821820189606222
+3,0.10912354497639255
+3.1000000000000001,0.050813981610711309
+3.2000000000000002,0.20889346610039716
+3.3000000000000003,0.35298948844971123
+3.4000000000000004,0.32474940318236023
+3.5,0.38239253826306385
+3.6000000000000001,0.32630838797473993
+3.7000000000000002,0.29718736751740976
+3.8000000000000003,0.19916162996035178
+3.9000000000000004,0.31696369945065445
+4,0.041190365415972992
+4.0999999999999996,0.11391228020475636
+4.2000000000000002,0.019485103395021075
+4.3000000000000007,-0.26342952196101571
+4.4000000000000004,-0.5092611472365397
+4.5,-0.41799215318123728
+4.5999999999999996,-0.73561485139026217
+4.7000000000000002,-0.92329619928696904
+4.8000000000000007,-0.90927651741448279
+4.9000000000000004,-1.1339614346763489
+5,-1.1517504631511968
+5.1000000000000005,-1.1402908029724872
+5.2000000000000002,-1.3521737597704713
+5.2999999999999998,-1.3520561465250629
+5.4000000000000004,-1.2713463645241503
+5.5,-1.1964088310952452
+5.6000000000000005,-1.2452944910422561
+5.7000000000000002,-1.169494079454507
+5.8000000000000007,-1.0070891198113012
+5.9000000000000004,-0.57833731612131689
+6,-0.37159339352530946
+6.1000000000000005,-0.13634550028140968
+6.2000000000000002,-0.18976896716746369
+6.3000000000000007,0.18023780009704649
+6.4000000000000004,0.48543592211567244
+6.5,0.6589373906769419
+6.6000000000000005,0.83333281190824393
+6.7000000000000002,0.96398998261249746
+6.8000000000000007,1.11701757929679
+6.9000000000000004,1.5186297452264101
+7,1.5889705955825626
+7.1000000000000005,1.6524294768055354
+7.2000000000000002,1.6839209146108967
+7.3000000000000007,1.6676039305248551
+7.4000000000000004,1.4677753919938958
+7.5,1.5943284226073355
+7.6000000000000005,1.3487063819931264
+7.7000000000000002,1.4916746989442995
+7.8000000000000007,1.3579050651588507
+7.9000000000000004,1.2201516339395857
+8,1.0354727508078239
+8.1000000000000014,0.87649138728423037
+8.1999999999999993,0.77387261855386325
+8.3000000000000007,0.4536800046194267
+8.4000000000000004,0.23974455070849177
+8.5,0.28174991982090863
+8.6000000000000014,0.17716212958380056
+8.6999999999999993,0.2300092768999859
+8.8000000000000007,-0.04592404352469065
+8.9000000000000004,0.021685712091274192
+9,0.11126106098973793
+9.0999999999999996,0.13994288990456027
+9.2000000000000011,-0.02788752686137759
+9.3000000000000007,0.0024405644345866159
+9.4000000000000004,0.03467349958429617
+9.5,0.062619838733266583
+9.5999999999999996,0.25690494810827541
+9.7000000000000011,0.17227340213228237
+9.8000000000000007,0.1249762313228136
+9.9000000000000004,0.22426593455377142
+10,0.22483299693724429
diff --git a/Tutorial3_Curve_fitting/Scilab_code/Tutorial3_curve_fitting.sce b/Tutorial3_Curve_fitting/Scilab_code/Tutorial3_curve_fitting.sce
index 57ba922..43e34db 100644
--- a/Tutorial3_Curve_fitting/Scilab_code/Tutorial3_curve_fitting.sce
+++ b/Tutorial3_Curve_fitting/Scilab_code/Tutorial3_curve_fitting.sce
@@ -15,24 +15,19 @@ time = Data(:,1);
//Measured output
measured_data = Data(:,2);
-// weights for data fitting
-weight_matrix = ones(length(time),1);
-//weight_matrix = [2 2 2 2 1 1 1 1 -3 -3 -3 1 1]';
-
-
-// minimize f(x) = sum_i weight_matrix(i)^2 (weight_matrix(tm(i),a,b) - measured_data(i))^2
// initial parameters guess
initial_condition = [1 ; 1];
-//f is the function value at optimal x (xopt)
-[func_value_xopt,x_optimal] = leastsq(list(errorfun,time,measured_data,weight_matrix),initial_condition)
+//Call least square function,
+//Output is function value (func_value_xopt) at optimal coefficients (x_optimal))
+[func_value_xopt,coeff_optimal] = leastsq(list(errorfun,time,measured_data),initial_condition)
-error = errorfun(x_optimal,time,measured_data,weight_matrix)
+error = errorfun(coeff_optimal,time,measured_data)
disp(error,'The error after least square approximation')
-// a small graphic
-fitted_data = fit_function(time, x_optimal);
+// Plot of measured data and fitted data versus time
+fitted_data = fit_function(time, coeff_optimal);
plot2d(time, [measured_data,fitted_data], [-1,2])
legend(["measure points", "fitted curve"],[-1,2],"ur");
xtitle("a simple fit with leastsq","time","data")
diff --git a/Tutorial3_Curve_fitting/Scilab_code/Tutorial3_curve_fitting_weighted.sce b/Tutorial3_Curve_fitting/Scilab_code/Tutorial3_curve_fitting_weighted.sce
new file mode 100644
index 0000000..866a070
--- /dev/null
+++ b/Tutorial3_Curve_fitting/Scilab_code/Tutorial3_curve_fitting_weighted.sce
@@ -0,0 +1,37 @@
+//This function is for curve fitting using least-square
+
+clear
+clc
+
+//The function to be fitted
+exec fit_function.sci;
+//The error function
+exec errorfunweight.sci;
+
+//Read measured data
+Data = csvRead('/home/chayan/Documents/scilab-tutorials/Tutorial3_Curve_fitting/Data/Tut3_Data.csv')
+//Time stamp
+time = Data(:,1);
+//Measured output
+measured_data = Data(:,2);
+
+// weights for data fitting
+weight_matrix = [1 1 1 1 1 1 5 5 5 5 5 5 5]';
+
+
+// minimize f(x) = sum_i weight_matrix(i)^2 (weight_matrix(tm(i),a,b) - measured_data(i))^2
+// initial parameters guess
+initial_condition = [1 ; 1];
+
+//f is the function value at optimal x (xopt)
+[func_value_xopt,x_optimal] = leastsq(list(errorfunweight,time,measured_data,weight_matrix),initial_condition)
+
+error = errorfunweight(x_optimal,time,measured_data,weight_matrix)
+disp(error,'The error after least square approximation')
+
+
+// a small graphic
+fitted_data = fit_function(time, x_optimal);
+plot2d(time, [measured_data,fitted_data], [-1,2])
+legend(["measure points", "fitted curve"],[-1,2],"ur");
+xtitle("a simple fit with leastsq","time","data")
diff --git a/Tutorial3_Curve_fitting/Scilab_code/errorfun.sci b/Tutorial3_Curve_fitting/Scilab_code/errorfun.sci
index 0b93304..741ad63 100644
--- a/Tutorial3_Curve_fitting/Scilab_code/errorfun.sci
+++ b/Tutorial3_Curve_fitting/Scilab_code/errorfun.sci
@@ -1,4 +1,4 @@
//A function to compute error between computed data and measured data
-function err = errorfun(x, time, measured_data, weight_matrix)
- err = weight_matrix.*(fit_function(time, x) - measured_data )
+function err = errorfun(x, time, measured_data)
+ err = (fit_function(time, x) - measured_data )
endfunction
diff --git a/Tutorial3_Curve_fitting/Scilab_code/errorfunweight.sci b/Tutorial3_Curve_fitting/Scilab_code/errorfunweight.sci
new file mode 100644
index 0000000..9326d91
--- /dev/null
+++ b/Tutorial3_Curve_fitting/Scilab_code/errorfunweight.sci
@@ -0,0 +1,4 @@
+//A function to compute error between computed data and measured data
+function err = errorfunweight(x, time, measured_data, weight_matrix)
+ err = weight_matrix.*(fit_function(time, x) - measured_data )
+endfunction
diff --git a/Tutorial4_ODE/Data/README.md b/Tutorial4_ODE/Data/README.md
deleted file mode 100644
index b212332..0000000
--- a/Tutorial4_ODE/Data/README.md
+++ /dev/null
@@ -1 +0,0 @@
-# Data for ODE
diff --git a/Tutorial4_ODE/Problems/Tut4.pdf b/Tutorial4_ODE/Problems/Tut4.pdf
new file mode 100644
index 0000000..2ad3662
--- /dev/null
+++ b/Tutorial4_ODE/Problems/Tut4.pdf
Binary files differ
diff --git a/Tutorial4_ODE/Scilab_code/Tutorial4_ode_matrix.sce b/Tutorial4_ODE/Scilab_code/Tutorial4_ode_matrix.sce
index fff34eb..33e5e33 100644
--- a/Tutorial4_ODE/Scilab_code/Tutorial4_ode_matrix.sce
+++ b/Tutorial4_ODE/Scilab_code/Tutorial4_ode_matrix.sce
@@ -1,4 +1,6 @@
//This script demonstrates the use of ODE solver when matrix is involved
+clear
+clc
//Definition of the function
function ydot = func(t,y)
diff --git a/Tutorial4_ODE/Scilab_code/Tutorial4_ode_simple.sce b/Tutorial4_ODE/Scilab_code/Tutorial4_ode_simple.sce
index ad42d4d..66431a4 100644
--- a/Tutorial4_ODE/Scilab_code/Tutorial4_ode_simple.sce
+++ b/Tutorial4_ODE/Scilab_code/Tutorial4_ode_simple.sce
@@ -1,9 +1,11 @@
//This script demonstrates the use of ODE solver
+clear
+clc
//Definition the function.
//The function is dy/dt = cos(t)*sin(t) - tan(t) + 1
function ydot = func(t,y)
- ydot = cos(t)*sin(t) - tan(t) + 1
+ ydot = t^2*exp(-2*t) + y
endfunction
//Initial condition of the problem, a scalar or vector
diff --git a/Tutorial4_ODE/Scilab_code/Tutorial4_ode_simple_plot.sce b/Tutorial4_ODE/Scilab_code/Tutorial4_ode_simple_plot.sce
index 4ecf87e..f2df913 100644
--- a/Tutorial4_ODE/Scilab_code/Tutorial4_ode_simple_plot.sce
+++ b/Tutorial4_ODE/Scilab_code/Tutorial4_ode_simple_plot.sce
@@ -1,6 +1,8 @@
//This script demonstrates the use of ODE solver and computing the
//solution at different times. The output is in the form of a plot
//of time versus computed solution
+clear
+clc
//Definition the function.
function ydot = func(t,y)
@@ -11,9 +13,14 @@ endfunction
y0 = -1;
//Start time
t0= 0;
+
//The array of time where the solution is computed
-t = 4:0.01:10;
+tf = 4:0.01:10;
+
//Calling the ODE solver
-sol=ode(y0,t0,t,func);
+sol=ode(y0,t0,tf,func);
+
+
//Plotting the result
-plot(t,sol)
+plot(tf,sol,'Linewidth',3)
+xtitle('Dynamics of y','Time','y(t)')
diff --git a/Tutorial5_Solution_of_equations/Problems/README.md b/Tutorial5_Solution_of_equations/Problems/README.md
new file mode 100644
index 0000000..f7a9032
--- /dev/null
+++ b/Tutorial5_Solution_of_equations/Problems/README.md
@@ -0,0 +1 @@
+# Problems for non-linear equations
diff --git a/Tutorial5_Solution_of_equations/Problems/Tut5.pdf b/Tutorial5_Solution_of_equations/Problems/Tut5.pdf
new file mode 100644
index 0000000..a8c2c51
--- /dev/null
+++ b/Tutorial5_Solution_of_equations/Problems/Tut5.pdf
Binary files differ
diff --git a/Tutorial5_Solution_of_equations/README.md b/Tutorial5_Solution_of_equations/README.md
new file mode 100644
index 0000000..56a4129
--- /dev/null
+++ b/Tutorial5_Solution_of_equations/README.md
@@ -0,0 +1 @@
+# Non-linear equations
diff --git a/Tutorial5_Solution_of_equations/Scilab_code/README.md b/Tutorial5_Solution_of_equations/Scilab_code/README.md
new file mode 100644
index 0000000..297d7b8
--- /dev/null
+++ b/Tutorial5_Solution_of_equations/Scilab_code/README.md
@@ -0,0 +1 @@
+# Scilab code for non-linear equations
diff --git a/Tutorial5_Solution_of_equations/Scilab_code/Tutotial5_linear_equation.sce b/Tutorial5_Solution_of_equations/Scilab_code/Tutotial5_linear_equation.sce
new file mode 100644
index 0000000..dcd5510
--- /dev/null
+++ b/Tutorial5_Solution_of_equations/Scilab_code/Tutotial5_linear_equation.sce
@@ -0,0 +1,22 @@
+//This scilab script is to compute the solution of a linear equation
+clear
+clc
+
+//Example of Ax + b = 0 where unique solution exists
+A = [1 2 3;3 2 1;2 4 5];
+b = [7;7;12];
+[x,kerA] = linsolve(A,b);
+disp(x,'Solution of Ax + b',kerA,'kernel of A');
+
+//Example of Py+q = 0 where solution does not exist
+P = [1 2 3;3 2 1;4 4 4]
+q = [1;2;1]
+[y,kerP] = linsolve(P,q);
+disp(y,'Solution of Py + q',kerP,'kernel of P');
+
+//Example of Lz+m = 0 where infinite solutions exist
+L = [1 2 3;3 2 1;4 4 4]
+m = [1;1;2]
+[z,kerL] = linsolve(L,m);
+disp(z,'Solution of Lz + m',kerL,'kernel of L');
+
diff --git a/Tutorial5_Solution_of_equations/Scilab_code/Tutotial5_nonlinear_equation.sce b/Tutorial5_Solution_of_equations/Scilab_code/Tutotial5_nonlinear_equation.sce
new file mode 100644
index 0000000..7f2a9ce
--- /dev/null
+++ b/Tutorial5_Solution_of_equations/Scilab_code/Tutotial5_nonlinear_equation.sce
@@ -0,0 +1,21 @@
+//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
+exec func.sci;
+
+
+//Initial guess for the solution
+t0 = 0;
+
+//Computation of solution using fsolve
+y_result = fsolve(t0,func);
+//Display the solution in command window
+disp(y_result,'Solution of the equation')
+
+
+
+
diff --git a/Tutorial5_Solution_of_equations/Scilab_code/Tutotial5_nonlinear_equation_twovar.sce b/Tutorial5_Solution_of_equations/Scilab_code/Tutotial5_nonlinear_equation_twovar.sce
new file mode 100644
index 0000000..2b5dce1
--- /dev/null
+++ b/Tutorial5_Solution_of_equations/Scilab_code/Tutotial5_nonlinear_equation_twovar.sce
@@ -0,0 +1,17 @@
+//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
+exec functwovar.sci;
+
+
+//Initial guess for the solution
+t0 = [0;0];
+
+//Computation of solution using fsolve
+y_result = fsolve(t0,functwovar);
+//Display the solution in command window
+disp(y_result,'Solution of the equation')
diff --git a/Tutorial5_Solution_of_equations/Scilab_code/func.sci b/Tutorial5_Solution_of_equations/Scilab_code/func.sci
new file mode 100644
index 0000000..013277d
--- /dev/null
+++ b/Tutorial5_Solution_of_equations/Scilab_code/func.sci
@@ -0,0 +1,4 @@
+//This is script to define a fuction
+function y = func(t)
+ y = cos(t)*sin(t) - tan(t) + 1
+endfunction
diff --git a/Tutorial5_Solution_of_equations/Scilab_code/functwovar.sci b/Tutorial5_Solution_of_equations/Scilab_code/functwovar.sci
new file mode 100644
index 0000000..6506ce4
--- /dev/null
+++ b/Tutorial5_Solution_of_equations/Scilab_code/functwovar.sci
@@ -0,0 +1,6 @@
+//This is script to define a fuction
+function y = functwovar(t)
+ x = t(1);
+ z = t(2);
+ y = [x^2+z^2-1;x^2*exp(-2*x) + z]
+endfunction