summaryrefslogtreecommitdiff
path: root/50/CH4/EX4.36
diff options
context:
space:
mode:
authorpriyanka2015-06-24 15:03:17 +0530
committerpriyanka2015-06-24 15:03:17 +0530
commitb1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b (patch)
treeab291cffc65280e58ac82470ba63fbcca7805165 /50/CH4/EX4.36
downloadScilab-TBC-Uploads-b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b.tar.gz
Scilab-TBC-Uploads-b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b.tar.bz2
Scilab-TBC-Uploads-b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b.zip
initial commit / add all books
Diffstat (limited to '50/CH4/EX4.36')
-rwxr-xr-x50/CH4/EX4.36/ex_4_36.sce31
1 files changed, 31 insertions, 0 deletions
diff --git a/50/CH4/EX4.36/ex_4_36.sce b/50/CH4/EX4.36/ex_4_36.sce
new file mode 100755
index 000000000..afc372683
--- /dev/null
+++ b/50/CH4/EX4.36/ex_4_36.sce
@@ -0,0 +1,31 @@
+// example 4.36
+// method of least squares to fit the data to the curve P(x)=c0*X+c1/squrt(X)
+
+x=[.2 .3 .5 1 2];
+f=[16 14 11 6 3];
+
+// I(c0,c1)= summation of (f(x)-(c0*X+c1/sqrt(X)))^2
+
+// hence on parcially derivating the summation,
+
+n=length(x);m=length(f);
+if m<>n then
+ error('linreg - Vectors x and f are not of the same length.');
+ abort;
+end;
+
+s1=0; // s1= summation of x(i)*f(i)
+s2=0; // s2= summation of f(i)/sqrt(x(i))
+s3=0;
+for i=1:n
+ s1=s1+x(i)*f(i);
+ s2=s2+f(i)/sqrt(x(i));
+ s3=s3+1/x(i);
+end
+
+c0=det([s1 sum(sqrt(x));s2 s3])/det([sum(x^2) sum(sqrt(x));sum(sqrt(x)) s3])
+
+c1=det([sum(x^2) s1;sum(sqrt(x)) s2])/det([sum(x^2) sum(sqrt(x));sum(sqrt(x)) s3])
+X=poly(0,"X");
+P=c0*X+c1/X^1/2
+// hence considering the polinomial P(x)=7.5961*X^1/2-1.1836*X \ No newline at end of file