我试图绘制r作为二维和三维氢原子基态中发现电子的概率的函数。我现在的代码是:
import math
import matplotlib.pyplot as plt
import numpy as np
def three_dimensional(radius):
bohr = (5.2917721067)*10**(-11)
use_radius = []
for i in radius:
new_rad = bohr*i
use_radius.append(new_rad)
answers = []
for i in use_radius:
R_r = (2//(bohr)**(3//2))*math.exp(-i/bohr)
answers.append(R_r)
probability = []
for i in answers:
probs = i^2
probability.append(probs)
print(answers)
return plt.contour(answers, probability)
我收到错误:
TypeError:^:'float'和'int'
的不支持的操作数类型
解决此问题的最佳方法是什么?
答案 0 :(得分:2)
您需要**
运算符,它是Python中的指数运算符,而不是^
。所以这一行应该是:
for i in answers:
probs = i**2
probability.append(probs)