A new world
This is my first entry in a new blog. I'm trying to create this blog using Pelican, a tool for automatically creating a website for the blog. Articles on the internet aren't all that helpful in describing exactly how to do this. The cost is $\$5.30$.
I'm sure, however, that I will eventually figure it all out.
Here is an in-line equation $\sqrt{3x - 1} + (1 + x^2)^3$ in the body of the text. Here is a displayed equation.
$$x = \frac{-b \pm\sqrt{b^2 - 4ac}}{2a}$$
where $a, b$ and $c$ are constants. The formula solves the equation $ax^2 + bx + c = 0$. One thing we use this formula for is solving quadratic equations. Here are some aligned equations:
$$\begin{align} 3x^2 + 4x - 1 &= 0\\ 2x + 3xy - y &= 0\\ y^2 - 2x^2 + 9 &= 0 \end{align}$$
To solve the formula $ax^2 + bx + c = 0$, use the quadratic formula. We use the quadratic equation to solve it!
An Ipython Notebook
import scipy as sp
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
%matplotlib inline
from __future__ import division
from scipy.integrate import quad
def f(x):
return sp.sin(x)
def g(f,a):
pi = sp.pi
return 1/pi * quad(lambda x: f(x)*sp.cos(x),-a,a)[0]
g(f,sp.pi)
def a(f, k):
return (1/sp.pi) * quad(lambda x: f(x)*sp.cos(k*x),-sp.pi,sp.pi)[0]
def b(f, k):
return (1/sp.pi) * quad(lambda x: f(x)*sp.sin(k*x),-sp.pi,sp.pi)[0]
def f(x):
return sp.exp(x)
def F(x,n):
g = lambda x: a(f,0)/2 + sum([a(f,k)*sp.cos(k*x) for k in range(1,n)] + [b(f,k)*sp.sin(k*x) for k in range(1,n+1)])
return g
xrng = sp.linspace(-sp.pi, sp.pi,200)
plt.plot(xrng, F(f,40)(xrng),lw=2)
plt.plot(xrng,sp.exp(xrng),lw=8,alpha=0.5)
def fourier(f,N,x):
coeffs = np.array([quad(f(x)*np.exp(1j*n*x),-np.pi,np.pi) for n in N])
return coeffs
def g(x):
return np.exp(x)
def myint(f):
return quad(lambda x: f(x),0,2)[0]
def g(x):
return 5*x
print(myint(g))
xrng = sp.linspace(-sp.pi,sp.pi,200)
plt.plot(xrng,fourier(lambda x: x**3,20)(xrng),lw=3)
def func(x):
return np.where(np.abs(x) >= 1, 0., np.abs(x) - 1.0)
def cn(x, y, n, period):
c = y * np.exp(-1j * 2. * np.pi * n * x / period)
return c.sum()/c.size
def f(x, y, Nh, period):
rng = np.arange(0.5, Nh+0.5)
coeffs = np.array([cn(x,y,i,period) for i in rng])
f = np.array([2. * coeffs[i] * np.exp(1j*2*i*np.pi*x/period) for i in rng])
return f.sum(axis=0)
a, b = 1, 4
N = 100
Nh = 10
def func(x):
return x*sp.log(x)
time = np.linspace( a, b, N )
y = func(time)
period = np.abs(a-b)
y2 = f(time,y,Nh,period).real
fig = plt.figure()
ax = fig.add_subplot(1,1,1)
ax.plot(time, y, lw=3)
ax.plot(time, y2, lw=3)
plt.show()
a = np.array([(x+1j)*(1-x*1j) for x in range(0,10)],dtype='complex')
print(a)
print(a.real)
print(a.imag)
print(a.sum()/a.max())
print(a.min())
print(a.max())
print(a.sum(), a.sum()/a.size)
rng = np.arange(.5, 8+.5)
print(rng)
print(a.size)
Nh = 10
rng = np.arange(0.5, Nh+0.5)
print(rng)
coeffs = np.array([i for i in rng])
print(coeffs)
f = np.array([(i,coeffs[i]) for i in rng])
print(coeffs[0],coeffs[0.5],coeffs[2],coeffs[2.1],coeffs[2.2],coeffs[2.3],coeffs[2.8],coeffs[2.99],coeffs[3.001])