hw2 done up to ex3
This commit is contained in:
parent
505f42ac3a
commit
67897f3485
4 changed files with 43 additions and 0 deletions
36
hw2/assignment2.m
Normal file
36
hw2/assignment2.m
Normal file
|
@ -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
|
BIN
hw2/assignment2.pdf
Normal file
BIN
hw2/assignment2.pdf
Normal file
Binary file not shown.
BIN
hw2/hw2.pdf
BIN
hw2/hw2.pdf
Binary file not shown.
|
@ -56,4 +56,11 @@ $$
|
||||||
|
|
||||||
\subsection*{Point e}
|
\subsection*{Point e}
|
||||||
Division and multiplication may suffer from cancellation.
|
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}
|
\end{document}
|
||||||
|
|
Reference in a new issue