2023数学建模国赛B代码

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()

相关推荐
数模加油站10 小时前
25认证杯C题成品论文第一弹【冲奖硬核+无盲点解析】
算法·数学建模·认证杯·25认证杯
ECT-OS-JiuHuaShan1 天前
否定之否定的辩证法,谁会不承认?但又有多少人说的透?
开发语言·人工智能·数学建模·生活·学习方法·量子计算·拓扑学
数学建模导师3 天前
2025亚太杯11月国际赛数学建模选题建议及思路来啦!(论文写作模板+优秀获奖论文)
数学建模
88号技师3 天前
2025年9月一区SCI-孤行尺蠖觅食优化算法Solitary Inchworm Foraging-附Matlab免费代码
开发语言·算法·数学建模·matlab·优化算法
smppbzyc4 天前
2025APMCM亚太杯数学建模B题【 辐射制冷技术的建模与优化】原创论文分享
数学建模·亚太杯·2025亚太杯数学建模b题·2025亚太杯国际赛·2025亚太杯
数字化脑洞实验室4 天前
未来求解器技术有哪些发展趋势?AI与求解器结合能带来哪些突破?
数学建模
热心网友俣先生5 天前
2025年APMCM亚太数学建模C题AI+人工精翻版本+数据收集方式介绍+数据分享
c语言·人工智能·数学建模
2501_941798736 天前
如何通过数据分析优化业务决策,提高企业竞争力
数学建模
嵌入式冰箱6 天前
2025年APMCM亚太数学建模ABC题详细教学分析
数学建模
小陈爱建模7 天前
[已更新]2025亚太杯A题亚太赛A题 APMCM大学生数学建模详细教学分析
数学建模