Python 板


LINE

参考网路来源 https://ipython-books.github.io/124-simulating-a-partial-differential-equation-reaction-diffusion-systems-and-turing-patterns/ 我想要把里面的方程式,换成以下论文里面的方程式 http://journals.plos.org/plosone/article?id=10.1371/journal.pone.0174946 所以我目前的进度是这样: import numpy as np import matplotlib.pyplot as plt %matplotlib inline mu = 0.16 nu= 0.04 D_H = 0.3 D_A=0.02 D_S=0.06 RHO_A = 0.03 RHO_H = 0.0001 epsilon=1.0 gamma=0.02 C=0.002 D=0.008 E=0.1 F=10 C_O=0.02 size = 50 # size of the 2D grid dx = 2. / size # space step T = 9.0 # total time dt = .001 # time step n = int(T / dt) # number of iterations A = np.random.rand(size, size) H = np.random.rand(size, size) S = np.random.rand(size, size) Y = np.random.rand(size, size) def laplacian( Z, R, i , j , A ): Z= 0.0 , dx=DELtA_X , dy=DELTA_X * 0.8 ; if ( i > L ): Z+= ( A[i-1][j] - A[i][j] )/dx/dx; if ( i < R ): Z+= ( A[i+1][j] - A[i][j] )/dx/dx; if ( j > 0 ): Z+= ( A[i][j-1] - A[i][j] )/dy/dy; if ( j < Z ): Z+= ( A[i][j+1] - A[i][j] )/dy/dy; return Z; #def laplacian(Z): # Ztop = Z[0:-2, 1:-1] # Zleft = Z[1:-1, 0:-2] # Zbottom = Z[2:, 1:-1] # Zright = Z[1:-1, 2:] # Zcenter = Z[1:-1, 1:-1] # return (Ztop + Zleft + Zbottom + Zright - # 4 * Zcenter) / dx**2 def show_patterns(S, ax=None): ax.imshow(S, cmap=plt.cm.copper, interpolation='bilinear', extent=[-1, 1, -1, 1]) ax.set_axis_off() fig, axes = plt.subplots(3, 3, figsize=(8, 8)) step_plot = n // 9 # We simulate the PDE with the finite difference # method. for i in range(n): # We compute the Laplacian of S and Y. deltaA = laplacian(A) deltaH = laplacian(H) deltaS = laplacian(S) # We take the values of S and Y inside the grid. Ac = A[1:-1, 1:-1] Hc = H[1:-1, 1:-1] Sc = S[1:-1, 1:-1] Yc = Y[1:-1, 1:-1] # We update the variables. A[1:-1, 1:-1],H[1:-1, 1:-1],S[1:-1, 1:-1], Y[1:-1, 1:-1]=\ Ac+dt * (C*A*A* S /H - mu * A + RHO_A * Y+D_A*deltaA),\ Hc+dt * (C * A*S - nu*H+ +RHO_H * Y+D_H*deltaH),\ Sc+dt * ( C_O - gamma * S - epsilon * Y * S+D_S*deltaS),\ Yc+dt * (D * A - E * Y + Y * Y / ( 1 + F * Y * Y)) # Neumann conditions: derivatives at the edges # are null. for Z in (Y, S): if ( i > L ): Z+= ( A[i-1][j] - A[i][j] )/dx/dx; if ( i < R ): Z+= ( A[i+1][j] - A[i][j] )/dx/dx; if ( j > 0 ): Z+= ( A[i][j-1] - A[i][j] )/dy/dy; if ( j < Z ): Z+= ( A[i][j+1] - A[i][j] )/dy/dy; return Z; # We plot the state of the system at # 9 different times. if i % step_plot == 0 and i < 9 * step_plot: ax = axes.flat[i // step_plot] show_patterns(S, ax=ax) ax.set_title(f'$t={i * dt:.2f}$') fig, ax = plt.subplots(1, 1, figsize=(8, 8)) show_patterns(S, ax=ax) 可是laplacian出现问题,矩阵怪怪的。 论文里面是用cuda的软体写的(我实在不知道怎麽改) : __device__ float laplace_2( mat_t A, int i, int j , int L, int R, int Z){ float t = 0.0f, dx = DELTA_X, dy = (DELTA_X*0.8); if ( i > L ) t+= ( A[i-1][j] - A[i][j] )/dx/dx; if ( i < R ) t+= ( A[i+1][j] - A[i][j] )/dx/dx; if ( j > 0 ) t+= ( A[i][j-1] - A[i][j] )/dy/dy; if ( j < Z ) t+= ( A[i][j+1] - A[i][j] )/dy/dy; return t; } 最後我需要看S-Y curve,所以我又加了 #plot that shit plt.figure() plt.plot(V,U, label ='one' ) plt.xlabel('U') plt.ylabel('V') plt.legend() plt.show() 可是又跟论文里面 Fig1的那个图案差很多。 我分离不出来单独一条 V,U,所以是一大坨线,我希望画单独一条。 --



※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 111.250.133.168
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Python/M.1530378743.A.6FA.html







like.gif 您可能会有兴趣的文章
icon.png[问题/行为] 猫晚上进房间会不会有憋尿问题
icon.pngRe: [闲聊] 选了错误的女孩成为魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一张
icon.png[心得] EMS高领长版毛衣.墨小楼MC1002
icon.png[分享] 丹龙隔热纸GE55+33+22
icon.png[问题] 清洗洗衣机
icon.png[寻物] 窗台下的空间
icon.png[闲聊] 双极の女神1 木魔爵
icon.png[售车] 新竹 1997 march 1297cc 白色 四门
icon.png[讨论] 能从照片感受到摄影者心情吗
icon.png[狂贺] 贺贺贺贺 贺!岛村卯月!总选举NO.1
icon.png[难过] 羡慕白皮肤的女生
icon.png阅读文章
icon.png[黑特]
icon.png[问题] SBK S1安装於安全帽位置
icon.png[分享] 旧woo100绝版开箱!!
icon.pngRe: [无言] 关於小包卫生纸
icon.png[开箱] E5-2683V3 RX480Strix 快睿C1 简单测试
icon.png[心得] 苍の海贼龙 地狱 执行者16PT
icon.png[售车] 1999年Virage iO 1.8EXi
icon.png[心得] 挑战33 LV10 狮子座pt solo
icon.png[闲聊] 手把手教你不被桶之新手主购教学
icon.png[分享] Civic Type R 量产版官方照无预警流出
icon.png[售车] Golf 4 2.0 银色 自排
icon.png[出售] Graco提篮汽座(有底座)2000元诚可议
icon.png[问题] 请问补牙材质掉了还能再补吗?(台中半年内
icon.png[问题] 44th 单曲 生写竟然都给重复的啊啊!
icon.png[心得] 华南红卡/icash 核卡
icon.png[问题] 拔牙矫正这样正常吗
icon.png[赠送] 老莫高业 初业 102年版
icon.png[情报] 三大行动支付 本季掀战火
icon.png[宝宝] 博客来Amos水蜡笔5/1特价五折
icon.pngRe: [心得] 新鲜人一些面试分享
icon.png[心得] 苍の海贼龙 地狱 麒麟25PT
icon.pngRe: [闲聊] (君の名は。雷慎入) 君名二创漫画翻译
icon.pngRe: [闲聊] OGN中场影片:失踪人口局 (英文字幕)
icon.png[问题] 台湾大哥大4G讯号差
icon.png[出售] [全国]全新千寻侘草LED灯, 水草

请输入看板名称,例如:Gossiping站内搜寻

TOP