一
python
import pandas as pd
import numpy as np
#初始化参数
D_0=70
theta=120
alpha=1.5
d=200
d=d*np.sin(np.radians(90-theta/2))/np.sin(np.radians(90-alpha+theta/2))
distances=np.array([-800,-600,-400,-200,0,200,400,600,800])
D=D_0-distances*np.tan(np.radians(alpha))
print(D)
W=D*np.sin(np.radians(theta/2))*(1/np.sin(np.radians((180-theta)/2+alpha))+1/np.sin(np.radians((180-theta)/2-alpha)))
print(W)
n=1-d/W
print(n)
#创建DataFrame用于保存结果
df=pd.DataFrame({'测线距中心点处的距离/m':distances})
df['海水深度/m']=D
df['覆盖宽度/m']=W
df['与前一条测线的覆盖率/%']=n
#将DataFrame保存为Excel文件
path=r'C:\Users\Administrator\Desktop\大学\数学建模\2023国B\result1.xlsx'
df.to_excel(path,index=False)
二
python
import pandas as pd
import numpy as np
def get_width(B):
#初始化参数
D_0 = 120 #海底深度(单位:m)
alpha=1.5 #坡度(单位:度)
D=D_0-distances*np.tan(np.radians(alpha))*np.cos(np.radians(180-B))
theta=120 #换能器的开角(单位:度)
alpha=np.arctan(abs(np.sin(np.radians(B)))*np.tan(np.radians(alpha)))*180/np.pi
print(D)
W=D*np.sin(np.radians(theta/2))*(1/np.sin(np.radians((180-theta)/2+alpha))+1/np.sin(np.radians((180-theta)/2-alpha)))
print(W)
return W
distances=np.array([0,0.3,0.6,0.9,1.2,1.5,1.8,2.1])
distances=distances*1852
print(distances)
angel=[0,45,90,135,180,225,270,315]
W=[]
for i in angel:
W.append(get_width(i))
#将DataFrame保存为Excel文件
path=r'C:\Users\Administrator\Desktop\大学\数学建模\2023国B\result2.xlsx'
pd.DataFrame(W).to_excel(path,index=False)
三
1、
python
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif']=['SimHei'] #显示中文
def get_width(B,D_0):
#初始化参数
alpha=1.5 #坡度
D=D_0
theta=120
alpha=np.arctan(abs(np.sin(np.radians(B)))*np.tan(np.radians(alpha)))*180/np.pi
print(D)
W = D * np.sin(np.radians(theta / 2)) * (
1 / np.sin(np.radians((180 - theta) / 2 + alpha)) + 1 / np.sin(np.radians((180 - theta) / 2 - alpha)))
print(W)
return W
angle=np.linspace(0,360,360)
W=[]
for i in angle:
W.append(get_width(i,150))
print(W)
plt.plot(angle,W)
plt.scatter(90,W[89],color='r')
plt.scatter(270,W[269],color='r')
plt.text(90,W[89],'({},{})'.format(90,W[89]))
plt.text(270,W[269],'({},{})'.format(270,W[269]))
angle=np.linspace(0,360,360)
W=[]
for i in angle:
W.append(get_width(i,149.5))
print(W)
plt.plot(angle,W)
plt.scatter(90,W[89],color='r')
plt.scatter(270,W[269],color='r')
plt.text(90,W[89],'({},{})'.format(90,W[89]))
plt.text(270,W[269],'({},{})'.format(270,W[269]))
plt.xlabel("不同角度")
plt.ylabel("覆盖宽度")
plt.show()
2、
python
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif']=['SimHei'] #显示中文
def sin(a):
return np.sin(np.radians(a))
def cos(a):
return np.cos(np.radians(a))
def tan(a):
return np.tan(np.radians(a))
angle=np.linspace(0,360,360)
low=110-2*2852*np.tan(np.radians(1.5))
high=110+2*2852*np.tan(np.radians(1.5))
alpha=1.5#坡度
theta=120 #换能器的开角
n=np.linspace(0.1,0.2,100)
cnt=[]
for i in n:
x=sin(theta/2)*cos(alpha)*high/(sin(90-theta/2-alpha)+sin(alpha)*sin(theta/2))
x=high-x*tan(alpha)
print(x)
ans=[]
ans.append(x)
A = sin(90 - theta / 2 + alpha)
B = sin(90 - theta / 2 - alpha)
C=sin(theta/2)/A-1/tan(alpha)
D=i*sin(theta/2)*(1/A+1/B)-sin(theta/2)/B-1/tan(alpha)
while True:
x=x*C/D
if x<low:
break
ans.append(x)
#print(len(ans))
cnt.append(len(ans))
#print(ans[-1])
n=np.array(n)
print(n)
print(cnt)
plt.plot(n,cnt,color='r')
plt.xlabel("不同重复率")
plt.ylabel("测线总数")
plt.show()
3、
python
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif']=['SimHei'] #显示中文
def sin(a):
return np.sin(np.radians(a))
def cos(a):
return np.cos(np.radians(a))
def tan(a):
return np.tan(np.radians(a))
angle=np.linspace(0,360,360)
low=110-2*2852*np.tan(np.radians(1.5))
high=110+2*2852*np.tan(np.radians(1.5))
alpha=1.5#坡度
theta=120 #换能器的开角
n=0.1
cnt=[]
x = sin(theta / 2) * cos(alpha) * high / (sin(90 - theta / 2 - alpha) + sin(alpha) * sin(theta / 2))
x = high - x * tan(alpha)
print(x)
ans = []
ans.append(x)
A = sin(90 - theta / 2 + alpha)
B = sin(90 - theta / 2 - alpha)
C = sin(theta / 2) / A - 1 / tan(alpha)
D = n * sin(theta / 2) * (1 / A + 1 / B) - sin(theta / 2) / B - 1 / tan(alpha)
while True:
x = x * C / D
if x < low:
break
ans.append(x)
#print(len(ans))
#print(ans[-1])
index=np.arange(len(ans))
ans=np.array(ans)
dis=[]
for i in range(len(ans)-1):
dis.append((ans[i]-ans[i+1])/tan(alpha))
for i in range(len(dis)-1):
dis[i+1]+=dis[i]
#plt.scatter(index,ans,color='g')
#plt.xlabel("测线编号")
#plt.ylabel("水深")
#plt.show()
print(dis)
dis.insert(0,0)
dis=np.array(dis)/1852
y=np.zeros(len(dis))
#plt.scatter(dis,y,marker='x',s=10)
plt.xlabel("各测线得到水平位置")
plt.ylim(-1.2,1.2)
plt.yticks(alpha=0)
plt.tick_params(axis='y',width=0)
y=np.linspace(-1,1,10000)
for i in range(len(dis)-1):
x=np.full((1,10000),dis[i])
plt.scatter(x,y,s=0.0001,color='c')
tx=np.linspace(dis[i],dis[i+1],1000)
if i%2==0:
ty=1
else:
ty=-1
ty=np.full((1,1000),ty)
plt.scatter(tx,ty,s=0.0001,color='c')
x=np.full((1,10000),dis[-1])
plt.scatter(x,y,x=0.0001,color='c')
plt.show()
path=r'C:\Users\Administrator\Desktop\大学\数学建模\2023国B\距离.xlsx'
pd.DataFrame(dis).to_excel(path)
path = r'C:\Users\Administrator\Desktop\大学\数学建模\2023国B\距离.xlsx'
pd.DataFrame(ans).to_excel(path)
4、
python
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif']=['SimHei'] #显示中文
def sin(a):
return np.sin(np.radians(a))
def cos(a):
return np.cos(np.radians(a))
def tan(a):
return np.tan(np.radians(a))
def get_Wleft(D):
return D*sin(theta/2)/sin(90-theta/2-alpha)
def get_WRight(D):
return D*sin(theta/2)/sin(90-theta/2+alpha)
angle=np.linspace(0,360,360)
low=110-2*2852*np.tan(np.radians(1.5))
high=110+2*2852*np.tan(np.radians(1.5))
alpha=1.5#坡度
theta=120 #换能器的开角
n=0.1
cnt=[]
x = sin(theta / 2) * cos(alpha) * high / (sin(90 - theta / 2 - alpha) + sin(alpha) * sin(theta / 2))
x = high - x * tan(alpha)
print(x)
ans = []
ans.append(x)
while True:
high=x-(get_WRight(x)-(get_WRight(x)+get_Wleft(x))*n)*sin(alpha)
x=sin(theta/2)*cos(alpha)*high/(sin(90-theta/2-alpha)+sin(alpha)*sin(theta/2))
x=high-x*tan(alpha)
if x < low:
break
ans.append(x)
print(ans)
print(len(ans))
print(ans[-1])
index=np.array(len(ans))
plt.scatter(index,ans,color='g')
plt.xlabel("测线编号")
plt.ylabel("水深")
plt.show()
#path = r'C:\Users\Administrator\Desktop\大学\数学建模\2023国B\水深.xlsx'
#pd.DataFrame(ans).to_excel(path)
5、
python
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
def sin(a):
return np.sin(np.radians(a))
def cos(a):
return np.cos(np.radians(a))
def tan(a):
return np.tan(np.radians(a))
def get_Wleft(D):
return D*sin(theta/2)/sin(90-theta/2-alpha)
angle=90
alpha=np.linspace(0.5,10,100)
theta=np.linspace(90,150,100)
x_d=70
w=[]
for i in alpha:
for j in theta:
w.append(x_d*sin(j/2)*(1/sin(90-j/2-i)+1/sin(90-j/2+i)))
print(w)
w=np.array(w).reshape(100,100)
alpha,theta=np.meshgrid(alpha,theta)
#创建三位图形对象和坐标轴
fig=plt.figure()
ax=fig.add_subplot(111,projection='3d')
#绘制三维图形
ax.plot_surface(alpha,theta,w,cmap='viridis')
#设置坐标轴标签
ax.set_xlabel('alpha')
ax.set_ylabel('theta')
ax.set_zlabel('w')
#显示图形
plt.show()