summaryrefslogtreecommitdiff
path: root/662/CH8/EX8.4
diff options
context:
space:
mode:
authorpriyanka2015-06-24 15:03:17 +0530
committerpriyanka2015-06-24 15:03:17 +0530
commitb1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b (patch)
treeab291cffc65280e58ac82470ba63fbcca7805165 /662/CH8/EX8.4
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 '662/CH8/EX8.4')
-rwxr-xr-x662/CH8/EX8.4/Example8_4.jpgbin0 -> 13436 bytes
-rwxr-xr-x662/CH8/EX8.4/Example8_4.sci61
2 files changed, 61 insertions, 0 deletions
diff --git a/662/CH8/EX8.4/Example8_4.jpg b/662/CH8/EX8.4/Example8_4.jpg
new file mode 100755
index 000000000..cc1b40256
--- /dev/null
+++ b/662/CH8/EX8.4/Example8_4.jpg
Binary files differ
diff --git a/662/CH8/EX8.4/Example8_4.sci b/662/CH8/EX8.4/Example8_4.sci
new file mode 100755
index 000000000..d0fe91735
--- /dev/null
+++ b/662/CH8/EX8.4/Example8_4.sci
@@ -0,0 +1,61 @@
+//Programming Example 8.4
+//find the maximum of a function within a specified interval
+
+funcprot(0)
+CNST=0.0001;
+
+function[]= mainmax()
+ global a;
+ global b;
+ //read input data(interval end points)
+ printf("a=");
+ a=scanf("%f");
+ printf("b=");
+ b=scanf("%f");
+
+ global x1;
+ global y1;
+ global xr;
+ global yr;
+ //interval reduction loop
+ first="t";
+ while ((( y1<> yr) & (( b- a)>3*CNST) ) | (first=="t"))
+ reduce();
+ first="f";
+ end
+ //calculate xmax and ymax and display the result
+ xmax=0.5*( x1+ xr);
+ ymax=curve(xmax);
+ //disp(xmax,ymax,"xmax ymax")
+ printf("xmax=%f , yamx=%f", xmax,ymax);
+endfunction
+
+//interval reduction routine
+function[]=reduce()
+ global a;
+ global b;
+ global x1;
+ global y1;
+ global xr;
+ global yr;
+ x1= a+0.5*( b- a-CNST);
+ xr= x1+CNST;
+ y1=curve(x1);
+ yr=curve(xr);
+ if y1>yr then
+ b=xr;
+ end
+ if y1<yr then
+ a=xr
+
+ end
+endfunction
+
+//evaluate the function y=x*cos(x)
+function[sol]= curve(x)
+ sol=x*cos(x);
+endfunction
+
+// routine call
+mainmax()
+