Math Maniac's Musings

My first blog

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!

[2in][2in][

An Ipython Notebook

In [1]:
import scipy as sp
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
%matplotlib inline

from __future__ import division
In [2]:
from scipy.integrate import quad
In [47]:
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)
Out[47]:
0.0
In [63]:
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]
In [126]:
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
In [123]:
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)
Out[123]:
[<matplotlib.lines.Line2D at 0x10ba49590>]
In [372]:
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)
3.14159265359

In [344]:
def myint(f):
    return quad(lambda x: f(x),0,2)[0]

def g(x):
    return 5*x

print(myint(g))
10.0

In [352]:
None

In [198]:
xrng = sp.linspace(-sp.pi,sp.pi,200)
plt.plot(xrng,fourier(lambda x: x**3,20)(xrng),lw=3)
Out[198]:
[<matplotlib.lines.Line2D at 0x10c824610>]
In [338]:
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()
In [270]:
a = np.array([(x+1j)*(1-x*1j) for x in range(0,10)],dtype='complex')
In [273]:
print(a)
print(a.real)
print(a.imag)
[  0. +1.j   2. +0.j   4. -3.j   6. -8.j   8.-15.j  10.-24.j  12.-35.j
  14.-48.j  16.-63.j  18.-80.j]
[  0.   2.   4.   6.   8.  10.  12.  14.  16.  18.]
[  1.   0.  -3.  -8. -15. -24. -35. -48. -63. -80.]

In [285]:
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)
(3.51279000595+0.334622248662j)
1j
(18-80j)
((90-275j), (9-27.5j))
[ 0.5  1.5  2.5  3.5  4.5  5.5  6.5  7.5]
10

In [317]:
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])
[ 0.5  1.5  2.5  3.5  4.5  5.5  6.5  7.5  8.5  9.5]
[ 0.5  1.5  2.5  3.5  4.5  5.5  6.5  7.5  8.5  9.5]
(0.5, 0.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 3.5)

In []: