Python Non-linear elliptic differential equation - python

AI Thread Summary
The discussion revolves around a student struggling with a computational physics assignment, specifically on solving a differential equation using numerical methods. The student previously failed the course and is seeking guidance to achieve a passing grade of 30%. They have successfully implemented a solution for a different problem using a tridiagonal solver and finite-difference methods. The current challenge involves solving the equation u'' + 500*exp(-100*x2) - u^3 = 0, which requires rearranging to u'' = u^3 - 500*exp(-100*x2). The student is unsure how to set up the necessary arrays and finite-difference approximations for the new equation, particularly how to initialize the values for 'u' and construct the right-hand side (RHS) array. The urgency is emphasized as the assignment deadline approaches.
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...
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
Thread 'Project Documentation'
Trying to package up a small bank account manager project that I have been tempering on for a while. One that is certainly worth something to me. Although I have created methods to whip up quick documents with all fields and properties. I would like something better to reference in order to express the mechanical functions. It is unclear to me about any standardized format for code documentation that exists. I have tried object orientated diagrams with shapes to try and express the...
Back
Top