diff options
-rw-r--r-- | scilab2c/demos/TrigonometricIdentity.dem.sce | 14 | ||||
-rw-r--r-- | scilab2c/demos/alldemos.dem.sce | 17 | ||||
-rw-r--r-- | scilab2c/etc/scilab2c.start | 15 | ||||
-rw-r--r-- | scilab2c/tests/unit_tests/test001_LinearRegression/scilabcode/mainfunction.sci | 104 |
4 files changed, 98 insertions, 52 deletions
diff --git a/scilab2c/demos/TrigonometricIdentity.dem.sce b/scilab2c/demos/TrigonometricIdentity.dem.sce new file mode 100644 index 00000000..36d59ee5 --- /dev/null +++ b/scilab2c/demos/TrigonometricIdentity.dem.sce @@ -0,0 +1,14 @@ +// +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2010-2010 - DIGITEO - Bruno JOFRET +// +// This file must be used under the terms of the CeCILL. +// This source file is licensed as described in the file COPYING, which +// you should have received as part of this distribution. The terms +// are also available at +// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt +// +// + +global SCI2CHOME +xpad(SCI2CHOME+"/tests/unit_tests/test000_TrigonIdentity/scilabcode/mainfunction.sci");
\ No newline at end of file diff --git a/scilab2c/demos/alldemos.dem.sce b/scilab2c/demos/alldemos.dem.sce new file mode 100644 index 00000000..c0f0e812 --- /dev/null +++ b/scilab2c/demos/alldemos.dem.sce @@ -0,0 +1,17 @@ +// +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2010-2010 - DIGITEO - Bruno JOFRET +// +// This file must be used under the terms of the CeCILL. +// This source file is licensed as described in the file COPYING, which +// you should have received as part of this distribution. The terms +// are also available at +// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt +// +// + +demopath = get_absolute_file_path("alldemos.dem.sce"); + +subdemolist = ["Trigonometric Identity" , "TrigonometricIdentity.dem.sce"]; + +subdemolist(:,2) = demopath + subdemolist(:,2);
\ No newline at end of file diff --git a/scilab2c/etc/scilab2c.start b/scilab2c/etc/scilab2c.start index f2f1757a..5189f41d 100644 --- a/scilab2c/etc/scilab2c.start +++ b/scilab2c/etc/scilab2c.start @@ -34,6 +34,21 @@ if or(getscilabmode() == ["NW";"STD"]) then end end +// Add demos +// ============================================================================= + +if or(getscilabmode() == ["NW";"STD"]) then + mprintf("\tLoad demos\n"); + pathdemos = pathconvert(root_tlbx + "/demos/alldemos.dem.sce",%f,%t); + +disp("**") +disp(pathdemos); +disp("**") + add_demo(gettext("Scilab2C"),pathdemos); + clear pathdemos ; +end + + global SCI2CHOME SCI2CHOME = root_tlbx; diff --git a/scilab2c/tests/unit_tests/test001_LinearRegression/scilabcode/mainfunction.sci b/scilab2c/tests/unit_tests/test001_LinearRegression/scilabcode/mainfunction.sci index 298e3c31..92c96e4e 100644 --- a/scilab2c/tests/unit_tests/test001_LinearRegression/scilabcode/mainfunction.sci +++ b/scilab2c/tests/unit_tests/test001_LinearRegression/scilabcode/mainfunction.sci @@ -1,56 +1,56 @@ //SCI2C: DEFAULT_PRECISION= DOUBLE
- +
function mainfunction()
- -// Knowing that -// (1) P * (V^gamma) = C -// Where -// P = Pressure -// V = Volume -// gamma,C = constants depending on the particular gas used. -// (2) log10(P) = log10(C) - gamma*log10(V) -// (3) x = log10(V) -// (4) y = log10(P) -// than (2) becomes: -// y = a + b*x; -// Where -// a = log10(C) -// b = -gamma -// Then thanks to this transformation it is possible to perform -// a linear regression to estimate gamma and C! - -Volume = [54.3 61.8 72.4 88.7 118.6 194.0]; -Pressure = [61.2 49.5 37.6 28.4 19.2 10.1]; -x = log10(Volume); -y = log10(Pressure); - -a = (sum(y)*sum(x.^2)-sum(x)*sum(x.*y))./(length(x)*sum(x.^2)-sum(x).*sum(x)); -b = (length(x)*sum(x.*y)-sum(x)*sum(y))./(length(x)*sum(x.^2)-sum(x).*sum(x)); - -// Other way to compute a and b +
+// Knowing that
+// (1) P * (V^gamma) = C
+// Where
+// P = Pressure
+// V = Volume
+// gamma,C = constants depending on the particular gas used.
+// (2) log10(P) = log10(C) - gamma*log10(V)
+// (3) x = log10(V)
+// (4) y = log10(P)
+// than (2) becomes:
+// y = a + b*x;
+// Where
+// a = log10(C)
+// b = -gamma
+// Then thanks to this transformation it is possible to perform
+// a linear regression to estimate gamma and C!
+
+Volume = [54.3 61.8 72.4 88.7 118.6 194.0];
+Pressure = [61.2 49.5 37.6 28.4 19.2 10.1];
+x = log10(Volume);
+y = log10(Pressure);
+
+a = (sum(y)*sum(x.^2)-sum(x)*sum(x.*y))./(length(x)*sum(x.^2)-sum(x).*sum(x));
+b = (length(x)*sum(x.*y)-sum(x)*sum(y))./(length(x)*sum(x.^2)-sum(x).*sum(x));
+
+// Other way to compute a and b
beq = sum((x-mean(x)).*(y-mean(y)))./sum((x-mean(x)).^2);
aeq = mean(y)-mean(x)*beq;
- -C = 10 .^a; -gamma = -b; - -disp('C') -disp(C) - -disp('gamma'); -disp(gamma); - -disp('a'); -disp(a) -disp('aeq'); -disp(aeq) - -disp('b'); -disp(b) -disp('beq'); -disp(beq) - -// plot(Volume,Pressure); -// plot(Volume,(C ./(Volume.^gamma)),'r') -endfunction - +
+C = 10 .^a;
+gamma = -b;
+
+disp('C')
+disp(C)
+
+disp('gamma');
+disp(gamma);
+
+disp('a');
+disp(a)
+disp('aeq');
+disp(aeq)
+
+disp('b');
+disp(b)
+disp('beq');
+disp(beq)
+
+ plot(Volume,Pressure);
+ plot(Volume,(C ./(Volume.^gamma)),'r')
+endfunction
+
|