pythonpython-3.xdoublesympysymbolic-integration

How can i solve a first order deferential using python that has another function in it?


My problem is sort of like this and this one combined but not quite. Anyway what im trying to do is take a double integral of a function using sympy to get the symbolic answer. The problem is that inside the derivative element and the integrals thereare 2 other functions and im not sure how to show that they are functions and not just constants. Here is what i have so far.

from sympy import *
import sympy as sp
sp.init_printing()

x=sp.Symbol('x') #a and k are constants
z=sp.Symbol('z')
k=sp.Symbol('k')
f=sp.Function('f')(x)
l=sp.Function('l')(x)

def dN(x,z):
    return -N*f*z**(a-2)

def b(x,z):
    return l*x*dN

def c(x,z):
    return z*l*x*dN

res=integrate(b,(z,k,float('inf')),(x,0,float('inf')))
sp.pprint (res)              
#print(b)

This is what im using for dN:

enter image description here

This is the integral im trying to preform to get eqn 12:

enter image description here

Any help would be much appreciated.


Solution

  • It looks like there might be some confusion between sympy functions and python functions. When you define b(x, z) that is a python function. When you refer to b in your integrate line you should supply the variables that are needed for the function, hence integrate(b(x, z)...). The same applies for dN that is called in functions b and c without args. (It should be ...*dN(x, z). In the dN function you define, you refer to N but don't define it. I would recommend that at the top you define N = sp.Function('N')(x, z). Finally, you can use sp.oo to refer to infinity rather than creating a floating point representation of the same.

    Sorry I can't test it here. Hopefully these suggestions will help you get on track! :-)