diff options
Diffstat (limited to '845/CH2/EX2.8')
-rwxr-xr-x | 845/CH2/EX2.8/Ex2_8.sce | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/845/CH2/EX2.8/Ex2_8.sce b/845/CH2/EX2.8/Ex2_8.sce new file mode 100755 index 000000000..5ef7cea63 --- /dev/null +++ b/845/CH2/EX2.8/Ex2_8.sce @@ -0,0 +1,24 @@ +//Example 2.8
+clc
+clear
+
+function [f,df] = fun8(x)
+ f = x.^3 - x - 1;
+ df = 3*x.^2 - 1;
+endfunction
+
+xold = 1;
+maxit = 5;
+iter = 1;
+
+while (1)
+ [fx,dfx] = fun8(xold);
+ xnew = xold - fx/dfx;
+ if iter == maxit then
+ break
+ end
+ xold = xnew;
+ iter = iter + 1;
+end
+root = round(xnew*10^4) / 10^4;
+disp(root,"root = ")
|