Home > Blockchain >  Is there a way to divide a large mathematical equation into individual terms?
Is there a way to divide a large mathematical equation into individual terms?

Time:10-02

Hi I want to integrate a relatively long equation with Python and am looking for a way to divide the equation into multiple terms and simplify it.

This is the function ...

p = lambda r_st, b_st: 1j * np.exp(-1j*k*((np.sqrt(r**2 - 2*r*r_st * np.sqrt(1 - r_st**2/4*gross_r**2) * np.sin(alpha) * np.cos(b_st)   r_st**2)) (r_st**2/2*n*gross_r))) / (np.sqrt(r**2 - 2*r*r_st * np.sqrt(1 - r_st**2/4*gross_r**2) * np.sin(alpha) * np.cos(b_st)   r_st**2)) * r_st

p_int =  integrate.dblquad(p, np.pi, 2*np.pi, lambda r: 0.4, lambda r: r_m)

... and so similar I would like to divide them, because the term "l" occurs twice and allows a better over view.

l = lambda r_st, b_st: np.sqrt(r**2 - 2*r*r_st * np.sqrt(1 - r_st**2/4*gross_r**2) * np.sin(alpha) * np.cos(b_st)   r_st**2)

p = lambda r_st, b_st: 1j * np.exp(-1j*k* l  (r_st**2/2*n*gross_r)) / l * r_st

p_int =  integrate.dblquad(p, np.pi, 2*np.pi, lambda r: 0.4, lambda r: r_m)

Unfortunately, it doesn't work that way. Can someone help me find a similar solution.

CodePudding user response:

Thanks for the comments, I forgot the parameters when calling the l function. Now it works.

l = lambda r_st, b_st: np.sqrt(r**2 - 2*r*r_st * np.sqrt(1 - r_st**2/4*gross_r**2) * np.sin(alpha) * np.cos(b_st)   r_st**2)

p = lambda r_st, b_st: 1j * np.exp(-1j*k* l(r_st, b_st)  (r_st**2/2*n*gross_r)) / l(r_st, bst) * r_st

p_int =  integrate.dblquad(p, np.pi, 2*np.pi, lambda r: 0.4, lambda r: r_m)
  • Related