2024美赛B题深度剖析|详细建模+代码实现

首先回顾一下本次美赛B题:

问题1的解决思路如下:

python示例代码:

import numpy as np
import matplotlib.pyplot as plt

# 模拟时间
time = np.linspace(0, 10, 100)

# 初始位置
x0, y0 = 0, 0

# 期望速度函数(可根据实际情况调整)
def expected_velocity(t):
    return np.sin(t)

# 不确定性项的标准差(可根据实际情况调整)
sigma_x = 0.1
sigma_y = 0.1

# 模拟机械故障和环境不确定性的随机项
delta_x = np.random.normal(0, sigma_x, len(time))
delta_y = np.random.normal(0, sigma_y, len(time))

# 计算位置
x = x0 + np.cumsum(expected_velocity(time) + delta_x)
y = y0 + np.cumsum(expected_velocity(time) + delta_y)

# 可视化模拟结果
plt.figure(figsize=(10, 6))
plt.plot(time, x, label='Simulated X Position')
plt.plot(time, y, label='Simulated Y Position')
plt.xlabel('Time')
plt.ylabel('Position')
plt.legend()
plt.title('Simulated Submarine Position Over Time')
plt.show()

matlab示例代码:

% 模拟时间
time = linspace(0, 10, 100);

% 初始位置
x0 = 0;
y0 = 0;

% 期望速度函数(可根据实际情况调整)
expected_velocity = @(t) sin(t);

% 不确定性项的标准差(可根据实际情况调整)
sigma_x = 0.1;
sigma_y = 0.1;

% 模拟机械故障和环境不确定性的随机项
delta_x = sigma_x * randn(size(time));
delta_y = sigma_y * randn(size(time));

% 计算位置
x = x0 + cumsum(expected_velocity(time) + delta_x);
y = y0 + cumsum(expected_velocity(time) + delta_y);

% 可视化模拟结果
figure;
plot(time, x, 'LineWidth', 1.5, 'DisplayName', 'Simulated X Position');
hold on;
plot(time, y, 'LineWidth', 1.5, 'DisplayName', 'Simulated Y Position');
xlabel('Time');
ylabel('Position');
legend('Location', 'Best');
title('Simulated Submarine Position Over Time');
grid on;

  • 10
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值