关于最终通过名单个人结论及给你的建议:
- 学院现最高本科生为 19 级,发展优先级:研究生全部,19级 >> 20级。
- 20级单一标准:志愿时长及对学院贡献(指党建等各项学院工作,非科研竞赛)。对社会贡献>>科研竞赛。
所以dddd,如果你要准备在HDU-ITMO入党:
- 提高你在学院影响力,学习不能差,多拿奖学金,争取先成为发展分子。
- 志愿/学院党建等工作/对社会有卓越贡献。
- 搞科研等大三/大四。
Personal Blog
关于最终通过名单个人结论及给你的建议:
所以dddd,如果你要准备在HDU-ITMO入党:
树莓派 frpc 设置:
从 github 中找到 arm 版本 wget 下载
frpc.ini 参考配置
1 2 3 4 5 6 7 8 9 10 |
[common] server_addr = you server ip server_port = 7000 token = your password [jupyter] type = http local_ip = 127.0.0.1 local_port = 8888 custom_domains = your domain |
jupyter 设置跟之前文章相同,即 ip, allow_remote_access等设置
服务器端 frps 配置: 云端开启7000~7003端口
1 2 3 4 5 6 7 8 |
[common] bind_port = 7000 vhost_http_port = 7002 token = your password dashboard_port = 7001 dashboard_user = Your dashboard usr name dashboard_pwd = Your dashboard password vhost_http_port = 7003 |
云端 nginx 参考配置:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
server{ listen 80; listen [::]:80; server_name yourdomain; location / { proxy_pass http://127.0.0.1:7003; proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_read_timeout 120s; proxy_next_upstream error; } } |
最终效果即通过域名 python.pancake2021.work 访问树莓派 jupyter
全部是正确答案,慎用。Adams和Milne需要用另外的算法如runge-kutta(代码示例求法)求前3个数,当然也可以用Euler和Euler Improved,大家不要都一样啦。Python缩进规范请注意!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
def solveByEulerImproved(f, epsilon, a, y_a, b): function = Result.get_function(f) n = 1 delta = float("inf") while abs(delta) >= epsilon / 10: n *= 2 h = (b - a) / n pre_y = y_a pre_fy = function(a, y_a) for i in range(n): x = a + (i + 1 / 2) * h yHalf = pre_y + pre_fy * h / 2 fyHalf = function(x, yHalf) y = pre_y + h * fyHalf delta = pre_y - y pre_y = y pre_fy = function(x + h / 2, y) return y |
Euler method 理论上代码正确,但是实际上因为算法的原因,与测试样例的值偏差会过大,要通过测试样例只需要初始化时把 n = 10000000
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
def solveByEuler(f, epsilon, a, y_a, b): function = Result.get_function(f) n = 1 delta = float("inf") while abs(delta) >= epsilon / 10: n *= 2 h = (b - a) / n pre_y = y_a for i in range(n): x = a + i * h fy = function(x, pre_y) y = pre_y + h * fy delta = pre_y - y pre_y = y return y |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
def solveByRungeKutta(f, epsilon, a, y_a, b): function = Result.get_function(f) n = 1 delta = float("inf") while abs(delta) >= epsilon / 10: n *= 2 h = (b - a) / n pre_y = y_a for i in range(n): x = a + i * h k1 = h * function(x, pre_y) k2 = h * function(x + h / 2, pre_y + k1 / 2) k3 = h * function(x + h / 2, pre_y + k2 / 2) k4 = h * function(x + h, pre_y + k3) y = (k1 + 2 * k2 + 2 * k3 + k4) / 6 + pre_y delta = pre_y - y pre_y = y return y |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
def runge_kutta(h, a, y_a, function): y_dot = [function(a, y_a)] pre_y = y_a for i in range(3): x = a + i * h k1 = h * function(x, pre_y) k2 = h * function(x + h / 2, pre_y + k1 / 2) k3 = h * function(x + h / 2, pre_y + k2 / 2) k4 = h * function(x + h, pre_y + k3) y = (k1 + 2 * k2 + 2 * k3 + k4) / 6 + pre_y y_dot.append(function(x + h, y)) pre_y = y return y, y_dot def solveByAdams(f, epsilon, a, y_a, b): function = Result.get_function(f) n = 2 delta = float("inf") while abs(delta) >= epsilon / 10: n *= 2 h = (b - a) / n y, y_dot = Result.runge_kutta(h, a, y_a, function) for i in range(n - 3): delta = (55 * y_dot[-1] - 59 * y_dot[-2] + 37 * y_dot[-3] - 9 * y_dot[-4]) / 24 * h y += delta y_dot.append(function(a + (i + 4) * h, y)) return y |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
def runge_kutta(h, a, y_a, function): y_dot = [function(a, y_a)] y_ = [y_a] pre_y = y_a for i in range(3): x = a + i * h k1 = h * function(x, pre_y) k2 = h * function(x + h / 2, pre_y + k1 / 2) k3 = h * function(x + h / 2, pre_y + k2 / 2) k4 = h * function(x + h, pre_y + k3) y = (k1 + 2 * k2 + 2 * k3 + k4) / 6 + pre_y y_dot.append(function(x + h, y)) y_.append(y) pre_y = y return y_, y_dot def solveByMilne(f, epsilon, a, y_a, b): function = Result.get_function(f) n = 2 delta = float("inf") while abs(delta) >= epsilon / 10: n *= 2 h = (b - a) / n y, y_dot = Result.runge_kutta(h, a, y_a, function) for i in range(n - 3): y.append(y[-4] + 4 * h / 3 * (2 * y_dot[-1] - y_dot[-2] + 2 * y_dot[-3])) y_dot.append(function(a + (i + 4) * h, y[-1])) y[-1] = y[-3] + h / 3 * (y_dot[-1] + 4 * y_dot[-2] + y_dot[-3]) delta = y[-1] - y[-2] y_dot[-1] = function(a + (i + 4) * h, y[-1]) return y[-1] |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
class ODE: def __init__(self, function, x0, y0): self.function = function self.x0 = x0 self.y0 = y0 def euler(self, h, step): result = [] pre_y = self.y0 for i in range(step): x = self.x0 + i * h fy = self.function(x, pre_y) y = pre_y + h * fy result.append(y) pre_y = y # print("y_{} = {}".format(i + 1, y)) return result def eulerImproved(self, h, step): result = [] pre_y = self.y0 pre_fy = self.y0 for i in range(step): x = self.x0 + (i + 1 / 2) * h yHalf = pre_y + pre_fy * h / 2 fyHalf = self.function(x, yHalf) y = pre_y + h * fyHalf result.append(y) pre_y = y pre_fy = function(x + h / 2, y) # print("y_{} = {}".format(i + 1, y)) return result def runge_kutta(self, h, step): result = [] pre_y = self.y0 for i in range(step): x = self.x0 + i * h k1 = h * self.function(x, pre_y) k2 = h * self.function(x + h / 2, pre_y + k1 / 2) k3 = h * self.function(x + h / 2, pre_y + k2 / 2) k4 = h * self.function(x + h, pre_y + k3) y = (k1 + 2 * k2 + 2 * k3 + k4) / 6 + pre_y result.append(y) pre_y = y # print("y_{} = {}".format(i + 1, y)) return result def milne(self, h, step): y = [self.y0] + self.runge_kutta(h, 3) y_dot = [function(self.x0 + i * h, y[i]) for i in range(4)] for i in range(step - 3): y.append(y[-4] + 4 * h / 3 * (2 * y_dot[-1] - y_dot[-2] + 2 * y_dot[-3])) y_dot.append(function(self.x0 + (i + 4) * h, y[-1])) y[-1] = y[-3] + h / 3 * (y_dot[-1] + 4 * y_dot[-2] + y_dot[-3]) y_dot[-1] = function(self.x0 + (i + 4) * h, y[-1]) # print("y_{} = {}".format(i + 4, y[-1])) return y[1:] def adams(self, h, step): y = [self.y0] + self.runge_kutta(h, 3) y_dot = [function(self.x0 + i * h, y[i]) for i in range(4)] for i in range(step - 3): y.append(y[-1] + (55 * y_dot[-1] - 59 * y_dot[-2] + 37 * y_dot[-3] - 9 * y_dot[-4]) / 24 * h) y_dot.append(function(self.x0 + (i + 4) * h, y[-1])) # print("y_{} = {}".format(i + 4, y[-1])) return y[1:] if __name__ == "__main__": function = lambda x, y: y - 2 * x / y x0 = 0 y0 = 1 h = 0.002 step = 1000 ode = ODE(function, x0, y0) print(ode.euler(h, step)[-1]) print("--------------------------------------------") print(ode.eulerImproved(h, step)[-1]) print("--------------------------------------------") print(ode.runge_kutta(h, step)[-1]) print("--------------------------------------------") print(ode.adams(h, step)[-1]) print("--------------------------------------------") print(ode.milne(h, step)[-1]) |
浙ICP备2021019730-1 浙公网安备 33010902002953号
Copyright © 2022 PanCake