In [1]:
import numpy as np
import sympy as sp
import pandas as pd
import math
import interpolate_exp_cos as p1
import plot_sin_eps as p2
import integrate_exp as p3
import diff_functions as p4
import matplotlib.pyplot as plt
# Needed only in Jupyter to render properly in-notebook
%matplotlib inline
In [3]:
p1.f(-.45)
Out[3]:
In [2]:
p1.S_k(-1, 1, -.45, 10)
Out[2]:
Part 2:
Value of function f(x) = $e^(-x^2) * cos(2\pi x)$ at x = -0.45 :
In [2]:
p1.f(-.45)
Out[2]:
In [3]:
p1.S_k(-1, 1, -.45, 2)
Out[3]:
Error in approximation at q = 2:
In [4]:
p1.error(-1, 1, -.45, 2)
Out[4]:
In [5]:
p1.S_k(-1, 1, -.45, 4)
Out[5]:
Error in approximation at q = 4:
In [6]:
p1.error(-1, 1, -.45, 4)
Out[6]:
In [9]:
p1.S_k(-1, 1, -.45, 8)
Out[9]:
Error in approximation at q = 8:
In [8]:
p1.error(-1, 1, -.45, 8)
Out[8]:
In [10]:
p1.S_k(-1, 1, -.45, 16)
Out[10]:
Error in approximation at q = 16:
In [13]:
p1.error(-1, 1, -.45, 16)
Out[13]:
In [2]:
p2.sin_graph(0.2, 10)
In [2]:
p2.multigraph(0.2, 10)
How large n needs to be in order for the difference between the max of the function $f(x) = sin\dfrac{1}{x+eps}$ in [0,1] using n nodes and n+10 nodes to be less than 0.1:
In [2]:
p2.choose_n(0.2)
Out[2]:
In [3]:
p2.choose_n(0.1)
Out[3]:
In [4]:
p2.choose_n(0.05)
Out[4]:
n = 200 * eps (for an epsilon of 0.2). Increasing n further does not change the plot so that it is visible on the screen.
In [8]:
p2.multigraph(0.2, 40)
In [2]:
p3.graph()
The plot is symmetric over the y-axis. Therefore the integral of the function from -$\infty$ to $\infty$ will be the same as twice the integral of the function from 0 to $\infty$
In [3]:
p3.T(100, 10)
Out[3]:
In [5]:
p3.trap(100, 10) * 2
Out[5]:
In [4]:
p3.table()
Out[4]:
In [5]:
p3.error()
Out[5]:
The error decreases as n increases and as L increases
In [2]:
p4.graph(p4.diff(p4.f, 1/1000, 1, 100))
In [2]:
p4.multigraph(p4.diff(p4.f, 1/1000, 1, 100), p4.fprime)
In [3]:
p4.graph(p4.diff(p4.g, 1/1000, 1, 100))
In [5]:
p4.multigraph(p4.diff(p4.g, 1/1000, 1, 100), p4.gprime)
In [4]:
p4.graph(p4.diff(p4.h, 1/1000, 1, 100))
In [6]:
p4.multigraph(p4.diff(p4.h, 1/1000, 1, 100), p4.hprime)
For the functions f(x) and h(x), an n of 100 seems to be sufficient as to make the graphs of the analytical and discrete derivatives visibly indistinguishable. For g(x), however, it is unlikely that any value of n will make the graphs indistinguishable upon superimposition, as the slope of g(x) as x -> 1 approaches very high values.
In [ ]: