def finite_difference(L, Nx, N, dt, C, P_L, P_R):
    x = linspace(0, L, Nx+1)
    dx = x[1] - x[0]
    C = 0.4*C*dt/(dx**2)
    print C	
    Q   = zeros(Nx+1)
    Q_1 = P_R**2*ones(Nx+1)

    for n in range(0, N):
        # Compute u at inner mesh points
        for i in range(1, Nx):
            Q[i] = Q_1[i] + C*(Q_1[i-1]**2.5 - 2*Q_1[i]**2.5 + Q_1[i+1]**2.5)
	# Insert boundary conditions 
	Q[0]=P_L**2; Q[Nx]=P_R**2
    	# Update u_1 before next step
    	Q_1[:]= Q
    
    return sqrt(Q), x
def finite_difference(L, Nx, N, dt, C, P_L, P_R):
    x = linspace(0, L, Nx+1)
    dx = x[1] - x[0]
    C = C*dt/(dx**2)
    print C	
    P   = zeros(Nx+1)
    P_1 = P_R*ones(Nx+1)

    for n in range(0, N):
        # Compute u at inner mesh points
        for i in range(1, Nx):
	    #print P_1
            P[i] = P_1[i] + C*(P_1[i-1]**2 - 2*P_1[i]**2 + P_1[i+1]**2)
	# Insert boundary conditions 
	P[0]=P_L; P[Nx]=P_R
    	# Update u_1 before next step
    	P_1[:]= P
    
    return P, x