summaryrefslogtreecommitdiff
path: root/413/CH7/EX7.2
diff options
context:
space:
mode:
Diffstat (limited to '413/CH7/EX7.2')
-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