Unable to solve nonlinear equation using scipy.optimize.fsolve

321 Views Asked by At

I am using scipy.optimize.fsolve to solve a nonlinear equation in Fourier pseudospectral space but it does not work. It gives the same output as the input u0, which is a trivial solution. The equation I am trying to solve is:

$\frac{1}{2}\frac{\partial (u^{2})}{\partial x}+\frac{\partial^{2}u}{\partial x^{2}}+\nu\frac{\partial^{4}u}{\partial x^{4}}=0$

The code is given below. Can anyone please help me on how to get a non-trivial solution?

import numpy as np
import scipy.optimize

M = 16
nu = 0.4

def kssol(M):

    kkx = np.fft.fftfreq(2*M)*2.*M

    kx = kkx[0:M+1]

    def func(vec):

        linspec = -(kx**2)+(nu*(kx**4))
        lin = linspec*np.fft.rfft(vec)
        nlin = np.zeros_like(lin)
        nlinre = vec*vec
        nlin = 0.5*1j*kx*np.fft.rfft(nlinre)   
        sol = lin+nlin
        rhs = np.zeros_like(sol, dtype='complex')
        sol -= rhs

        return np.fft.irfft(sol)

    u0 = np.zeros((2.*M,))
    u = scipy.optimize.fsolve(func, u0) 

    return u