# Python code of explicit method of a nonlinear a BVP

I am trying to have a Python code for the following nonlinear BVP: $$\frac{\partial N}{\partial t}=\frac{\partial^2 N}{\partial x^2}+N(1-N)-\sigma N$$ $$N(0,x)=\sin(2\pi x)$$ $$N(t,0)=0 \hspace{3mm}N(t,L)=0 \hspace{1.5mm};\hspace{2mm}t>0,0

Without the non-linear part I discretize with explicit FTCS method. $$\frac{N_{i,j+1}-N_{i,j}}{k} = c^2\frac{N_{i+1,j}-2N_{i,j}+N_{i-1,j}}{h^2}$$ $$N_{i,j+1} = \lambda[N_{i+1,j}-2N_{i,j}+_{i-1,j}]+N_{i,j}$$ $$\text{where}\hspace{3mm} \lambda = \frac{c^2k}{h^2}$$

But the problem is that maybe I can't discretize the nonlinear part. That's why my Python code does not respond well and I am new to Python. So, can anybody help me with a Python algorithm?

• Please describe in sufficient detail how you would discretize if the non-linear part were absent. Commented May 21, 2023 at 20:05
• I am sorry .I just edited the post. @LutzLehmann Commented May 22, 2023 at 2:10
• What specifically is it that prevents you from "discretiz[ing] the nonlinear part? Commented May 22, 2023 at 3:08
• because I dont understand that do I have to discretize the system of linear ODE from this PDE or I should just discretize the whole PDE. @WolfgangBangerth Commented May 22, 2023 at 14:57
• Finite Difference Methods for Ordinary and Partial Differential Equations: Steady-State and Time-dependent Problems by Randall LeVeque is a great reference. If you are familiar with using numerical ODE solvers in Python (scipy.integrate for instance) then you can forego the need to really understand the time-stepping for a nonlinear problem via the Method of Lines, where you just discretize in space then solve the resulting system of ODEs using an arbitrary method of your choice. Commented May 22, 2023 at 18:11