Files
Calculators-for-University-…/python/degree.ipynb
T

138 lines
4.7 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 角度直接测量与不确定度评定\n",
"\n",
"本 Notebook 用于对分光计等仪器测得的角度多次测量数据(支持度分格式 `度.分`)进行不确定度合成与保留一位有效数字的规范修约输出。\n",
"\n",
"---\n",
"### 实验原理与数学公式\n",
"\n",
"#### 1. 角度单位换算与平均值计算\n",
"角度采用“分(arcminute)”为内部基准单位换算:\n",
"$$D^\\circ M' = D \\times 60' + M'$$\n",
"对 $n$ 次测量值 $\\theta_1, \\theta_2, \\dots, \\theta_n$(以分为单位):\n",
"$$\\bar{\\theta} = \\frac{1}{n} \\sum_{i=1}^n \\theta_i$$\n",
"$$s = \\sqrt{\\frac{1}{n-1} \\sum_{i=1}^n (\\theta_i - \\bar{\\theta})^2}$$\n",
"\n",
"#### 2. 不确定度评定公式\n",
"* **A 类不确定度**:\n",
"$$u_A = \\frac{s}{\\sqrt{n}}$$\n",
"* **B 类不确定度**(分光计游标盘分度值误差 $\\Delta_{\\mathrm{inst}}$ 通常为 $1'$):\n",
"$$u_B = \\frac{\\Delta_{\\mathrm{inst}}}{\\sqrt{3}}$$\n",
"* **合成不确定度**:\n",
"$$u = \\sqrt{u_A^2 + u_B^2}$$\n",
"\n",
"#### 3. 结果修约规则\n",
"不确定度 $u$ 按照“四舍六入五凑偶”保留一位有效数字,角度平均值末位与不确定度对齐,并还原输出为度分格式 $D^\\circ M'$。"
],
"id": "b15a8bae68dd9273"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import math\n",
"from decimal import Decimal\n",
"from python.utils import parse_angle_to_minutes, format_minutes_as_angle, scientific_round\n",
"\n",
"print(\"角度换算与修约模块加载完成。\")"
],
"id": "afc36384df4dec97"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 1. 角度测量数据与分度值输入\n",
"> **输入格式**:字符串 `'度.分'`(例如 `'120.15'` 代表 $120^\\circ 15'$)。"
],
"id": "2d31b33f8ef516db"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# 测量数据列表 (度.分 格式)\n",
"angle_data = [\"120.15\", \"120.16\", \"120.14\", \"120.15\", \"120.17\", \"120.15\"]\n",
"\n",
"# 仪器分度值 (单位: 分 ')\n",
"res_str = \"1\"\n",
"\n",
"print(f\"输入角度数据: {angle_data}\")\n",
"print(f\"仪器分度值: {res_str} '\")"
],
"id": "50959966653d1094"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 2. 统计计算与修约输出"
],
"id": "d91d9838fb92eb89"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# 转换为内部单位“分”\n",
"data_minutes = [parse_angle_to_minutes(s) for s in angle_data]\n",
"res = Decimal(res_str)\n",
"n = len(data_minutes)\n",
"\n",
"# 1. 平均值与标准差\n",
"mean_minutes = sum(data_minutes) / n\n",
"variance = sum((x - mean_minutes) ** 2 for x in data_minutes) / (n - 1) if n > 1 else Decimal(\"0\")\n",
"s = Decimal(str(math.sqrt(float(variance))))\n",
"\n",
"# 2. A类、B类及合成不确定度\n",
"u_A = s / Decimal(str(math.sqrt(n))) if n > 1 else Decimal(\"0\")\n",
"u_B = res / Decimal(str(math.sqrt(3)))\n",
"u = Decimal(str(math.sqrt(float(u_A**2 + u_B**2))))\n",
"\n",
"# 3. 科学修约与格式还原\n",
"u_float = float(u)\n",
"if u_float == 0:\n",
" final_result_str = f\"θ = {format_minutes_as_angle(mean_minutes)} ± 0'\"\n",
"else:\n",
" first_digit_pos = math.floor(math.log10(u_float))\n",
" prec = Decimal('1e' + str(first_digit_pos))\n",
" mean_final_val, u_final = scientific_round(mean_minutes, u)\n",
" mean_str = format_minutes_as_angle(mean_final_val, prec)\n",
" final_result_str = f\"θ = {mean_str} ± {u_final}'\"\n",
"\n",
"print(\"=\" * 45)\n",
"print(\" 角 度 测 量 不 确 定 度 分 析 \")\n",
"print(\"=\" * 45)\n",
"print(f\"测量次数 n : {n}\")\n",
"print(f\"角度平均值 : {format_minutes_as_angle(mean_minutes)} ({mean_minutes:.4f}')\")\n",
"print(f\"样本标准差 s : {s:.6f}'\")\n",
"print(f\"A 类不确定度 u_A : {u_A:.6f}'\")\n",
"print(f\"B 类不确定度 u_B : {u_B:.6f}'\")\n",
"print(f\"合成不确定度 u : {u:.6f}'\")\n",
"print(\"-\" * 45)\n",
"print(f\"★ 最终修约结果 : {final_result_str}\")\n",
"print(\"=\" * 45)"
],
"id": "ef15abbb8e0d991c"
}
],
"metadata": {
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 5
}