summaryrefslogtreecommitdiff
path: root/413/CH7/EX7.2/Example_7_2.sce
diff options
context:
space:
mode:
authorprashantsinalkar2017-10-10 12:27:19 +0530
committerprashantsinalkar2017-10-10 12:27:19 +0530
commit7f60ea012dd2524dae921a2a35adbf7ef21f2bb6 (patch)
treedbb9e3ddb5fc829e7c5c7e6be99b2c4ba356132c /413/CH7/EX7.2/Example_7_2.sce
parentb1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b (diff)
downloadScilab-TBC-Uploads-7f60ea012dd2524dae921a2a35adbf7ef21f2bb6.tar.gz
Scilab-TBC-Uploads-7f60ea012dd2524dae921a2a35adbf7ef21f2bb6.tar.bz2
Scilab-TBC-Uploads-7f60ea012dd2524dae921a2a35adbf7ef21f2bb6.zip
initial commit / add all books
Diffstat (limited to '413/CH7/EX7.2/Example_7_2.sce')
-rw-r--r--413/CH7/EX7.2/Example_7_2.sce30
1 files changed, 30 insertions, 0 deletions
diff --git a/413/CH7/EX7.2/Example_7_2.sce b/413/CH7/EX7.2/Example_7_2.sce
new file mode 100644
index 000000000..2fd122a96
--- /dev/null
+++ b/413/CH7/EX7.2/Example_7_2.sce
@@ -0,0 +1,30 @@
+clc
+clear
+a=-3
+b=1
+r=0.618034
+function a=f(x)
+ a=exp(x)+2-cos(x);
+endfunction
+xl=a+(1-r)*(b-a)
+xr=a+r*(b-a)
+FL=f(xl)
+FR=f(xr)
+while (abs(xr-xl)>0.001)
+ T=[xl,xr,FL,FR,a,b,a-b]
+ disp(T)
+ if(FR >FL)
+ b=xr
+ xr=xl
+ FR=FL
+ xl=a+(1-r)*(b-a)
+ FL=f(xl)
+ else
+ a=xl
+ xl=xr
+ FL=FR
+ xr=a+r*(b-a)
+ FR=f(xr)
+ end
+
+end \ No newline at end of file