Burger'中的语法错误;Python的等式代码

Burger'中的语法错误;Python的等式代码,python,Python,我正在使用Python 2.7.13。Ubuntu 16.10中的Anaconda 4.3.1(64位)和Python 2.7.12 Shell,用于编码计算流体力学中Navier Stokes 12个步骤的Burger方程部分 我使用的代码写在下面,在第56行中我不断得到语法错误,如果我把这一行作为注释,下一行就会出现语法错误 import numpy #bunch of useful matrix operations import matplotlib.pyplot as plt # 2d

我正在使用Python 2.7.13。Ubuntu 16.10中的Anaconda 4.3.1(64位)和Python 2.7.12 Shell,用于编码计算流体力学中Navier Stokes 12个步骤的Burger方程部分


我使用的代码写在下面,在第56行中我不断得到语法错误,如果我把这一行作为注释,下一行就会出现语法错误

import numpy #bunch of useful matrix operations
import matplotlib.pyplot as plt # 2d plottin library
import sympy#symbolic math library for python
from sympy import init_printing
init_printing(use_latex=True)
#setting up symbolic variables for the three variables in our inicial condition
x, nu, t = sympy.symbols('x nu t')
fi=(sympy.exp(-(x-4*t)**2/(4*nu*(t+1)))+sympy.exp(-(x-4*t-2*numpy.pi)**2/(4*nu*(t+1))))
fi
#phi
#partial derivative is a trivial task
fiprima=fi.diff(x)
fiprima
#phiprime
#to see the unrendered version
#print(fiprima)
#lambdify function, which takes a sympy symbolic equation and turns it into a callable function
from sympy.utilities.lambdify import lambdify
u=-2*nu*(fiprima/fi)+4
u
#we tell lambdify which variables to request and the function we want to plug them in to
ufunc=lambdify((t,x,nu),u)
ufunc(1,4,3)
#back to burger equation
nx=101#int(input('inserte el numero de puntos de la grilla:'))
nlast=2*numpy.pi#float(input('inserte el tamaño del dominio:'))
dx=nlast/(nx-1.)
nt=100#int(input('inserte el numero de pasos de tiempo:'))
nu=0.07#float(input('inserte el valor de la viscosidad cinematica:'))
dt=dx*nu
#defimos las condiciones iniciales
#u=numpy.ones(nx)
x=numpy.linspace(0,2*numpy.pi,nx)
x
un=numpy.empty(nx)
un
#iterative process
for i in range(nt+1):
    if i==0:
        plt.clf()
        t=0
        u=numpy.asarray([ufunc(t,x0,nu) for x0 in x])
        plt.figure(figsize=(11,7),dpi=100)
        ax=plt.axes(xlim=(0,nlast),ylim=(0,8))
        plt.title('Burger Equation='+str(i))
        plt.grid(True)
        plt.plot(x,u,marker='o',lw=2)
        plt.pause(0.01) 
    else:
        un=u.copy()
        plt.clf()
        for j in range(1,nx-1):
            u[j]=un[j]-un[j]*dt/dx*(un[j]-un[j-1])+nu*(dt/(dx**2))*(un[j+1]-2*un[j]+un[j-1])
#periodic boundary condition
        u[0]=un[0]-un[0]*dt/dx*(un[0]-un[-2]+nu*(dt/(dx**2))*(un[1]-2*un[0]+un[-2])
        u[-1] = u[0]
        u_analytical=numpy.asarray([ufunc(i*dt,xi,nu) for xi in x])
        plt.figure(figsize=(11,7),dpi=100)
        ax=plt.axes(xlim=(0,nlast),ylim=(0,8))
        plt.title('Burger Equation='+str(i))
        plt.grid(True)
        plt.plot(x,u,marker='o',lw=2, label='Computational');
        plt.plot(x,u_analytical, label='Analytical');
        plt.legend();
        plt.pause(0.01)

如何解决此问题?

您在
u[0]=
行中有一个未关闭的parens。“如果我将此行作为注释,则下一行将出现语法错误。”:这通常意味着查看感兴趣行之前的行。注:StackOverflow不提供行号:请引用相关行,而不是说明“第56行”.感谢大家,问题解决了,所以语法错误在上面一行。