Non-linear elliptic differential equation - python

Click For Summary
SUMMARY

This discussion focuses on solving a non-linear elliptic differential equation using Python, specifically employing the SciPy library for numerical methods. The user initially solved a similar problem using a tridiagonal matrix algorithm and is now attempting to solve the equation u'' + 500*exp(-100*x2) - u3 = 0. Key techniques mentioned include finite-difference approximations and the Newton-Raphson method for iterative solutions. The user seeks guidance on setting up the necessary arrays and implementing the finite-difference method effectively.

PREREQUISITES
  • Understanding of non-linear elliptic differential equations
  • Familiarity with Python programming and the SciPy library
  • Knowledge of finite-difference methods for numerical solutions
  • Experience with iterative methods such as Newton-Raphson
NEXT STEPS
  • Research finite-difference methods for non-linear equations
  • Explore the implementation of the Newton-Raphson method in Python
  • Learn about constructing and solving tridiagonal systems in numerical analysis
  • Investigate the use of interpolation techniques in SciPy for numerical solutions
USEFUL FOR

Students in computational physics, researchers working on numerical methods for differential equations, and Python developers interested in scientific computing.

leonmate
Messages
81
Reaction score
1
Hey guys,

I'm going to be honest and say I'm so stuck on this assignment - I really need help!
I've took on a third year computational physics course last year - turn your weaknesses into strengths someone told me.

Well, I failed and I'm back doing it again this year!

So, I just have to pass which means I need 30% in this assignment. But, I'm not getting there on my own - I've struggled to get to grips with the module - I got 20% in my last assignment :'(

Can someone help guide me through it?

So, I've already solved a similar problem, the one I did was:

u''(x) = f(x) = - exp(x) * (-2 + 2x + 5x2 + x3)

Code:
from pylab import *
from scipy import interpolate
       
def EllipticSolver(Nx):
    dx = 1.0/Nx
    pts = linspace(-dx/2.0,1.+dx/2.0,Nx+2)
    soln = zeros(Nx+2)
    rhs = zeros(Nx+2)
    rhs = -exp(pts)*(-2.0 + 2.*pts + 5.*pts**2 + pts**3)
    soln = tridiagonal2(soln,rhs,dx)
    return pts[1:-1], soln[1:-1]
   
def tridiagonal2(dat,d,dx):
    N = len(dat)
    print(N)
    dx2 = 1.0/(dx*dx)
    a = zeros(N)
    b = zeros(N)
    c = zeros(N)
    a[:] = dx2
    c[:] = dx2
    b[:] = -2.0*dx2
   
    b[1] = -1.0*dx2
    b[N-2] = -3.0*dx2
  
    c[1] = c[1]/b[1]
    d[1] = d[1]/b[1]
    for j in range(2,N-1):
        c[j] = c[j]/(b[j] - c[j-1]*a[j])
        d[j] = (d[j] - d[j-1]*a[j])/(b[j] - c[j-1]*a[j])
       
    print(a)
    print(b)
    print(c)
    print(d)
  
    dat[N-2] = d[N-2]
    for j in range(N-3,0,-1):
        dat[j] = d[j] - c[j]*dat[j+1]
   
    return dat

x1, soln1 = EllipticSolver(100)
x2, soln2 = EllipticSolver(200)
x3, soln3 = EllipticSolver(400)

figure(1)
clf()
plot(x1,soln1,'r-')
plot(x2,soln2,'g-')

s2 = interpolate.interp1d(x2,soln2,'cubic')
soln2a = s2(x1)

s3 = interpolate.interp1d(x3,soln3,'cubic')
soln3a = s3(x2)

diff1 = soln1 - soln2a
diff2 = soln2 - soln3a

figure(2)
clf()
plot(x1,diff1,'r-')
plot(x2,4.*diff2,'g-')

Now I have to solve it for:

u'' + 500*exp(-100*x2) - u3 = 0

I guess I rearrange so:

u'' = u3 - 500*exp(-100*x2)

and then solve that

How do I solve it with an x and a u in the equation :O :(

If you've made it this far I love you and please help me, I have until next Wednesday to get this done and I can't do it on my own..... pleeeeeease help I just need 30 damn percent

I attached a copy of the assignmentLeon
 

Attachments

Technology news on Phys.org
OK, so I've made a little progressFirst thing we have to do is find the finite-difference approximation for the u'' matrix for a staggered grid

So, Newton-Raphson method, discretise using finite-difference approximations of the derivatives

u'' = (ui+1 + ui-1 - 2ui) / dx2

So, the first thing I'm going to have to do is set up some kind of array for u in order to whack it in a for loop and populate it using the above equation

I don't know what 'u' should be here, I could use an array of zeros, but I need some values in order to get something for u''

In the example above, i create the rhs array using the staggered grid I produced called pts

Do I need to make another staggered grid for u, and then use that to make a RHS array:

rhs = zeros(N)
rhs = ui+1 + ui-1 - 2ui / dx2

That wouldn't quite work but something along those lines...
 

Similar threads

  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
Replies
1
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 3 ·
Replies
3
Views
1K
  • · Replies 4 ·
Replies
4
Views
6K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 12 ·
Replies
12
Views
4K
  • · Replies 16 ·
Replies
16
Views
3K