diff options
author | Nguyễn Gia Phong <vn.mcsinyx@gmail.com> | 2019-12-16 21:31:18 +0700 |
---|---|---|
committer | Nguyễn Gia Phong <vn.mcsinyx@gmail.com> | 2019-12-16 21:31:18 +0700 |
commit | e461df7573c2b7b7e26c965d8cf2d8e175d67378 (patch) | |
tree | 193b8439edac52c1749764395fe5f7787889eda9 /usth/MATH2.2/final/EX3.m | |
parent | c1008fe39217be7f91f0ea23483e747bfbc5743e (diff) | |
download | cp-e461df7573c2b7b7e26c965d8cf2d8e175d67378.tar.gz |
[usth/MATH2.2] Numerical Methods
The future starts now.
Diffstat (limited to 'usth/MATH2.2/final/EX3.m')
-rw-r--r-- | usth/MATH2.2/final/EX3.m | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/usth/MATH2.2/final/EX3.m b/usth/MATH2.2/final/EX3.m new file mode 100644 index 0000000..99240f8 --- /dev/null +++ b/usth/MATH2.2/final/EX3.m @@ -0,0 +1,16 @@ +disp ("Question 3:"); +disp ("(a)"); +function y = f (x) + y = 2 + x.^2 + exp(x.*2 + 1); +endfunction +h = 0.005; +printf ("By forward difference with h = 0.05, f'(1.35) = %g\n", + (f (1.35 + h) - f (1.35)) / h); + +disp ("(b)"); +disp ("I am unsure if diff is different on Matlab, but on octave,"); +disp ("it's simply taking differences between consecutive elements."); +x = [1.35, 1.35+h]; +printf ("Using diff with h = 0.05, we get same result, f'(1.35) = %g\n", + (diff (f (x)) / h)); +disp ("Using symbolical methods, f'(1.35) = 83.5946 which is quite close."); |