Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- """
- Created on Thu Oct 17 14:22:59 2019
- @author: gullholm
- """
- # Q1
- import random
- import numpy as np
- import matplotlib.pyplot as plt
- # First makes vector with the resolution and size of the grid
- N = 10
- size = [0]*N
- res = [0]*N
- ress = [0]*N
- for n in range(N):
- size[n] = 2**(n+1)
- res[n] = 2**-(n+1)
- # makes brownian motion for finest grid 2^-10
- Z = np.zeros(size[9])
- sigma = res[9]
- Z = sigma*np.random.randn(1024)
- Z[0] = 0
- B_10 = np.cumsum(Z)
- for i in range(N):
- ress[i] = np.arange(0,1, res[i])
- def BM(B): # function that's makes the bigger grids
- lgd = int(len(B)/2)
- B_new = [0]*lgd
- for i in range(1,lgd):
- B_new[i] = (1/2)*(B[i]+B[i+1]-B[i-1]) # each coarser grid is the mean of two finer
- return(B_new)
- B_9 = BM(B_10)
- B_8 = BM(B_9)
- B_7 = BM(B_8)
- B_6 = BM(B_7)
- B_5 = BM(B_6)
- B_4 = BM(B_5)
- B_3 = BM(B_4)
- B_2 = BM(B_3)
- B_1 = BM(B_2)
- plt.plot(ress[9], B_10)
- plt.plot(ress[8], B_9)
- plt.plot(ress[7], B_8)
- plt.plot(ress[6], B_7)
- plt.plot(ress[5], B_6)
- plt.plot(ress[4], B_5)
- plt.plot(ress[3], B_4)
- plt.plot(ress[2], B_3)
- plt.plot(ress[1], B_2)
- plt.plot(ress[0], B_1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement