diff options
author | jofret | 2010-06-21 06:24:38 +0000 |
---|---|---|
committer | jofret | 2010-06-21 06:24:38 +0000 |
commit | 8b44229ef44f0558ce045e46ff833fb44df913c9 (patch) | |
tree | 4fdd89b2258c18c905d2f17ef4bea8ea9cf32893 /tests/unit_tests/test001_LinearRegression | |
parent | af0366230e14cc75d9e9a183375ee9cb69fb46b6 (diff) | |
download | scilab2c-8b44229ef44f0558ce045e46ff833fb44df913c9.tar.gz scilab2c-8b44229ef44f0558ce045e46ff833fb44df913c9.tar.bz2 scilab2c-8b44229ef44f0558ce045e46ff833fb44df913c9.zip |
Tagging the 2.0 release of scilab2crelease-2.0
Diffstat (limited to 'tests/unit_tests/test001_LinearRegression')
-rw-r--r-- | tests/unit_tests/test001_LinearRegression/launchConversion.sci | 5 | ||||
-rw-r--r-- | tests/unit_tests/test001_LinearRegression/scilabcode/mainfunction.sci | 56 |
2 files changed, 61 insertions, 0 deletions
diff --git a/tests/unit_tests/test001_LinearRegression/launchConversion.sci b/tests/unit_tests/test001_LinearRegression/launchConversion.sci new file mode 100644 index 00000000..41be0f04 --- /dev/null +++ b/tests/unit_tests/test001_LinearRegression/launchConversion.sci @@ -0,0 +1,5 @@ +lines(0)
+clear all
+tmpPWD = pwd;
+
+scilab2c(pwd()+"/scilabcode/mainfunction.sci", pwd(), pwd()+"/scilabcode/");
diff --git a/tests/unit_tests/test001_LinearRegression/scilabcode/mainfunction.sci b/tests/unit_tests/test001_LinearRegression/scilabcode/mainfunction.sci new file mode 100644 index 00000000..13624cfb --- /dev/null +++ b/tests/unit_tests/test001_LinearRegression/scilabcode/mainfunction.sci @@ -0,0 +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
+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
+
|