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