1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Non-linear elliptic differential equation - python

  1. Dec 3, 2015 #1
    Hey guys,

    I'm gonna 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 (Text):
    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 assignment


    Leon
     

    Attached Files:

  2. jcsd
  3. Dec 4, 2015 #2
    OK, so I've made a little progress


    First 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 gonna 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...
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted



Similar Discussions: Non-linear elliptic differential equation - python
Loading...