diff --git a/hw2/assignment2.m b/hw2/assignment2.m new file mode 100644 index 0000000..c6a59a4 --- /dev/null +++ b/hw2/assignment2.m @@ -0,0 +1,36 @@ +%% Assignment 2 +% Name: Claudio Maggioni +% +% Date: 19/3/2019 +% +% This is a template file for the first assignment to get started with running +% and publishing code in Matlab. Each problem has its own section (delineated +% by |%%|) and can be run in isolation by clicking into the particular section +% and pressing |Ctrl| + |Enter| (evaluate current section). +% +% To generate a pdf for submission in your current directory, use the following +% three lines of code at the command window: +% +% >> options.format = 'pdf'; options.outputDir = pwd; publish('assignment2.m', options) +% + +%% Problem 3 + +syms x; + +f = exp(x); +df = diff(f); +x_0 = 1; +err = zeros(10, 1); +h = zeros(10, 1); + +for i = 1:10 + h(i) = 10^(-i); + err(i) = abs(subs(df,x,x_0) - my_diff(f, x, x_0, h(i))); +end + +loglog(h, err) + +function approx = my_diff(f, x, x_0, h) + approx = (subs(f,x,x_0 + h) - subs(f, x, x_0)) / h; +end \ No newline at end of file diff --git a/hw2/assignment2.pdf b/hw2/assignment2.pdf new file mode 100644 index 0000000..671c3a7 Binary files /dev/null and b/hw2/assignment2.pdf differ diff --git a/hw2/hw2.pdf b/hw2/hw2.pdf index 0721a1f..9fce7c8 100644 Binary files a/hw2/hw2.pdf and b/hw2/hw2.pdf differ diff --git a/hw2/hw2.tex b/hw2/hw2.tex index ff3faf0..5bfdef9 100644 --- a/hw2/hw2.tex +++ b/hw2/hw2.tex @@ -56,4 +56,11 @@ $$ \subsection*{Point e} Division and multiplication may suffer from cancellation. + +\section*{Exercise 3} +\subsection*{Point d} +The error at first keeps getting exponentially smaller due to a better approximation of $h$ when computing the derivative +(i.e. $h$ is exponentially nearer to 0), but at $10^{-9}$ this trend almost becomes the opposite due to loss of significant +digits when subtracting from $e^{x+h}$ $e^x$ and amplifiying this error by effectively multiplying that with exponentially +increasing powers of 10. \end{document}