用Python编了一个物理折射率的图,可是有一点问题,求大神指教
用Python编了一个物理折射率的图,可是有一点问题,求大神指教fromipywidgetsimportinteractfrompylabimport*frommathi...
用Python编了一个物理折射率的图,可是有一点问题,求大神指教from ipywidgets import interact
from pylab import *
from math import *
import matplotlib.pyplot as plt
import numpy as py
n1=0
n2=0
def Snell_law(n1,n2,i1):
%matplotlib.inline
axis[(-10,10,-10,10)]
grid()
axhline(color='c',linewidth=3)
t=np.arange(0,10,0.1)
if 90>=i1>asin(n2/n1)/pi*180:
x=sin(i1/180*pi)*t
y=cos(i1/180*pi)*t
x1=sin(i1/180*pi)*-t
y1=cos(i1/180*pi)*t
elif 0<i1<=asin(n2/n1)/pi*180:
x=sin(i1/180*pi)*t
y=cos(i1/180*pi)*t
x1=sin(i1/180*pi)*-t
y1=sin(i1/180*pi)*t
i2=asin(n1/n2*sin(x1))/pi*180
x2=sin(abs(n2)/180*pi)*-t
y2=cos(abs(n2)/180*pi)*-t
plt.plot(x,y,'-',label="rayon incident")
plt.plot(x1,y1,'--',label="rayon refracte")
plt.plot(x2,y2,'-.',label="rayon reflechi")
plt.legend()
plt.title("Animation Snell_law")
plt.show()
interact(Snell_law, i1=(0,90,1) ,n1=(1,3,0.1) ,n2=(1,3,0.1))
cannot find widget or abbreviation for argument:'i1'. 展开
from pylab import *
from math import *
import matplotlib.pyplot as plt
import numpy as py
n1=0
n2=0
def Snell_law(n1,n2,i1):
%matplotlib.inline
axis[(-10,10,-10,10)]
grid()
axhline(color='c',linewidth=3)
t=np.arange(0,10,0.1)
if 90>=i1>asin(n2/n1)/pi*180:
x=sin(i1/180*pi)*t
y=cos(i1/180*pi)*t
x1=sin(i1/180*pi)*-t
y1=cos(i1/180*pi)*t
elif 0<i1<=asin(n2/n1)/pi*180:
x=sin(i1/180*pi)*t
y=cos(i1/180*pi)*t
x1=sin(i1/180*pi)*-t
y1=sin(i1/180*pi)*t
i2=asin(n1/n2*sin(x1))/pi*180
x2=sin(abs(n2)/180*pi)*-t
y2=cos(abs(n2)/180*pi)*-t
plt.plot(x,y,'-',label="rayon incident")
plt.plot(x1,y1,'--',label="rayon refracte")
plt.plot(x2,y2,'-.',label="rayon reflechi")
plt.legend()
plt.title("Animation Snell_law")
plt.show()
interact(Snell_law, i1=(0,90,1) ,n1=(1,3,0.1) ,n2=(1,3,0.1))
cannot find widget or abbreviation for argument:'i1'. 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询