0

I am very new to python and I have to animate wave function depending on time and position. The formula is a sum of sin and cos function, depending of n and m integers. In the formula there is also x, which I would like to leave as a variable and do the summation, and then have a wave function depending only on x. Is it somehow possible? Here is a part with summation:

import sympy as sp
import numpy as np

n = sp.Symbol('n', integer = True, positive = True)
m = sp.Symbol('m', integer = True, positive = True)
x = sp.Symbol('x', real = True)
t = sp.Symbol('t', real = True, positive = True)
a = sp.Symbol('a', real = True, positive = True)
h = sp.Symbol('hbar', real = True, positive = True)
mass = sp.Symbol('m', real = True, positive = True)
V0 = sp.Symbol('V')

C = 4 * mass * a**2 * V0 / sp.pi**3 / h**2 
summ = sp.sin(m * sp.pi * x / a)/(n**2 - m**2)**2 * (n * sp.sin(sp.pi * m / 2) * sp.cos(sp.pi * n / 2) + m * sp.sin(sp.pi * n / 2) * sp.cos(sp.pi * m / 2))
Psi0 = lambdify((x, n, m), (summ).subs({h: 6.6 * 10**(-16), a: 1, mass: 9.1 * 10**(-31), V0: 10}))
Psi1 = 0
for i in range (0, 1000):
    for j in range (0, 1000):
        if i != j:
            Psi1 += C * Psi0 (x, i, j)

julswion
  • 11
  • 1
  • Check out this: https://stackoverflow.com/questions/9450656/positional-argument-v-s-keyword-argument – surya May 31 '21 at 07:19

2 Answers2

0

Not sure if this is what you need or just an optional keyword arg, for which other answers exist (though I'd be careful with optionals, as they can lead to bug which are a bit harder to detect).

If it's about "gradual function application" there's a way to do it in Python using partial application. Assume you have function fun() which takes a, b and c, and you'd like to first bind only a and b, and then later on just call it with different values of c. You could do this:

import functools


def three_args(a, b, c):
   print(f"Got {a}, {b} and {c}")


def main():
   # "fix" first two values by applying function partially with those
   fun = functools.partial(three_args, 1, 2)

   fun(3)   # prints "Got 1, 2 and 3" 

   fun(42)  # prints "Got 1, 2 and 42"

Naturally the first function is still callable with all three arguments if you need to.

EdvardM
  • 2,934
  • 1
  • 21
  • 20
-1

It is possible by making the third argument as "Optional Argument". Checkout this:

  1. Positional argument v.s. keyword argument
  2. https://docs.python.org/3/reference/expressions.html#calls
  3. https://docs.python.org/3/reference/compound_stmts.html#function-definitions
surya
  • 719
  • 5
  • 13