形の科学会誌第35巻 連載講座データ形の科学会 Society for Science on Form, Japan
形の科学会誌第35巻に掲載の連載講座のデータを収録しております。
*著作権は放棄されておりません。二次使用等につきましては作成・発表者にお問い合わせください。
平田隆幸(福井大学)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
!pip install ColabTurtle import ColabTurtle.Turtle as turtle turtle.initializeTurtle() turtle.penup() turtle.goto(100,400) turtle.pendown() turtle.speed(10) def koch(length1, n): if n == 0: turtle.forward(int(length1)) else: koch(length1/3, n - 1) turtle.left(60) koch(length1/3, n - 1) turtle.right(120) koch(length1/3, n - 1) turtle.left(60) koch(length1/3, n - 1) turtle.right(90) koch(600,4) |
1 2 3 4 5 6 7 8 9 10 |
import matplotlib.pyplot as plt import numpy as np data = np.array([[],[]]) for i in range(11): for j in range(11): newdisk = np.array([[i],[j]]) data = np.append(data,newdisk,axis=1) fig, ax = plt.subplots(figsize=(5,5)) ax.scatter(data[0], data[1]) plt.show() |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
import matplotlib.pyplot as plt import numpy as np np.random.seed(20201230) data = np.array([[],[]]) histdistance = np.array([]) ndisk = 0 def calnearestdistance(x, y,ndisk): mindistance = 999999 for i in range(ndisk): distance = np.sqrt((data[0,i]-x)**2 + (data[1,i]-y)**2) if (distance != 0) & (distance < mindistance): mindistance = distance return mindistance for i in range(100): newdisk = np.random.rand(2,1) data = np.append(data,newdisk,axis=1) ndisk += 1 for i in range(ndisk): r = calnearestdistance(data[0,i],data[1,i],ndisk) histdistance = np.append(histdistance,np.array([r])) fig, axs = plt.subplots(1,2, figsize=(11, 5)) axs[0].scatter(data[0], data[1]) axs[1].hist(histdistance) plt.xlabel("Distance"), plt.ylabel("Number of Persons") plt.show() |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
import math import matplotlib.pyplot as plt import numpy as np NTRIAL = 1000000 np.random.seed(20201230) data = np.random.rand(2,1) histdistance = np.array([]) socialdistance = 0.1 ndisk = 1 def calnearestdistance(x, y,ndisk): mindistance = 999999 for i in range(ndisk): distance = math.sqrt((data[0,i]-x)**2 + (data[1,i]-y)**2) if (distance != 0) & (distance < mindistance): mindistance = distance return mindistance for i in range(NTRIAL): newdisk = np.random.rand(2,1) r = calnearestdistance(newdisk[0],newdisk[1],ndisk) if r >= socialdistance: data = np.append(data,newdisk,axis=1) ndisk += 1 for i in range(ndisk): r = calnearestdistance(data[0,i],data[1,i],ndisk) histdistance = np.append(histdistance,np.array([r])) print('Number of disks is ',ndisk) fig, axs = plt.subplots(1,2, figsize=(11, 5)) axs[0].scatter(data[0], data[1]) axs[1].hist(histdistance) plt.xlabel("Distance"), plt.ylabel("Number of Persons") plt.show() |
*参考リンク Colaboratory(Google)
*個人の責任においてご利用ください。
*著作権は放棄されておりません。二次使用等につきましては作成・発表者にお問い合わせください。
2020年12月01日火曜日/2020-12-01T08:00:50+00:00 category :