{"cells":[{"cell_type":"markdown","metadata":{},"source":["## 关于这个笔记本\n","\n","该笔记本由 B220400 班某咸鱼创建,用于自动化处理“波尔共振仪研究受迫振动”实验的数据。\n","\n","数据请填入 `free_vibration.csv`,`damped_vibration.csv` 和 `forced_vibration.csv`,并将变量 `DAMPED_VIBRATION_DATA_10T` 修改为你自己的数据。"]},{"cell_type":"code","execution_count":null,"metadata":{},"outputs":[],"source":["FREE_VIBRATION_DATA_FILE = 'free_vibration.csv'\n","DAMPED_VIBRATION_DATA_FILE = 'damped_vibration.csv'\n","DAMPED_VIBRATION_DATA_10T = 15.740\n","FORCED_VIBRATION_DATA_FILE = 'forced_vibration.csv'"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2023-11-14T12:01:39.786254Z","iopub.status.busy":"2023-11-14T12:01:39.785801Z","iopub.status.idle":"2023-11-14T12:01:40.354779Z","shell.execute_reply":"2023-11-14T12:01:40.353474Z","shell.execute_reply.started":"2023-11-14T12:01:39.786228Z"},"trusted":true},"outputs":[],"source":["import numpy as np\n","import pandas as pd\n","import seaborn as sns\n","import matplotlib.pyplot as plt\n","%matplotlib inline"]},{"cell_type":"markdown","metadata":{},"source":["## Free Vibration 自由振动"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2023-11-14T12:01:40.480480Z","iopub.status.busy":"2023-11-14T12:01:40.479908Z","iopub.status.idle":"2023-11-14T12:01:40.770339Z","shell.execute_reply":"2023-11-14T12:01:40.769383Z","shell.execute_reply.started":"2023-11-14T12:01:40.480444Z"},"trusted":true},"outputs":[],"source":["free_vibration_data = pd.read_csv(FREE_VIBRATION_DATA_FILE)\n","\n","X = np.array(free_vibration_data[r'$T_0$'])[:, np.newaxis]\n","y = np.array(free_vibration_data[r'$\\theta$'])\n","\n","from sklearn.linear_model import LinearRegression\n","model = LinearRegression()\n","model.fit(X, y)\n","\n","prediction_line_label = rf'$\\theta={float(model.coef_)}T_0+{float(model.intercept_)}$'\n","free_vibration_plot = sns.regplot(data=free_vibration_data, x=r'$T_0$', y=r'$\\theta$', line_kws={'label': prediction_line_label}, ci=None)\n","free_vibration_plot.set_title(r'Free Vibration')\n","free_vibration_plot.set_xlabel(r'$T_0/s$')\n","free_vibration_plot.set_ylabel(r'$\\theta/(\\degree)$')\n","free_vibration_plot.legend()"]},{"cell_type":"markdown","metadata":{},"source":["## Forced Vibration 受迫振动"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2023-11-14T12:01:41.686008Z","iopub.status.busy":"2023-11-14T12:01:41.685662Z","iopub.status.idle":"2023-11-14T12:01:41.707890Z","shell.execute_reply":"2023-11-14T12:01:41.706177Z","shell.execute_reply.started":"2023-11-14T12:01:41.685978Z"},"trusted":true},"outputs":[],"source":["forced_vibration_data = pd.read_csv(FORCED_VIBRATION_DATA_FILE)\n","\n","from_theta_to_t0_model = LinearRegression()\n","from_theta_to_t0_model.fit(np.array(free_vibration_data[r'$\\theta$'])[:, np.newaxis], np.array(free_vibration_data[r'$T_0$']))\n","\n","forced_vibration_data[r'$T_0$']=from_theta_to_t0_model.predict(np.array(forced_vibration_data[r'$\\theta$'])[:, np.newaxis])\n","forced_vibration_data[r'$\\frac{\\omega}{\\omega_0}$']=forced_vibration_data[r'$T_0$'] / forced_vibration_data[r'$T$']\n","\n","forced_vibration_data"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2023-11-14T12:01:41.709943Z","iopub.status.busy":"2023-11-14T12:01:41.709584Z","iopub.status.idle":"2023-11-14T12:01:42.169976Z","shell.execute_reply":"2023-11-14T12:01:42.169039Z","shell.execute_reply.started":"2023-11-14T12:01:41.709908Z"},"trusted":true},"outputs":[],"source":["sns.lmplot(data=forced_vibration_data, x=r'$\\frac{\\omega}{\\omega_0}$', y=r'$\\theta$', order=4, ci=None)"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2023-11-14T12:01:42.171953Z","iopub.status.busy":"2023-11-14T12:01:42.171403Z","iopub.status.idle":"2023-11-14T12:01:42.635555Z","shell.execute_reply":"2023-11-14T12:01:42.634546Z","shell.execute_reply.started":"2023-11-14T12:01:42.171919Z"},"trusted":true},"outputs":[],"source":["sns.lmplot(data=forced_vibration_data, x=r'$\\frac{\\omega}{\\omega_0}$', y=r'$\\varphi$', order=3, ci=None)"]},{"cell_type":"markdown","metadata":{},"source":["## Damped Vibration 阻尼振动"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2023-11-14T12:01:42.652122Z","iopub.status.busy":"2023-11-14T12:01:42.651547Z","iopub.status.idle":"2023-11-14T12:01:42.667880Z","shell.execute_reply":"2023-11-14T12:01:42.666400Z","shell.execute_reply.started":"2023-11-14T12:01:42.652093Z"},"trusted":true},"outputs":[],"source":["damped_vibration_data = pd.read_csv(DAMPED_VIBRATION_DATA_FILE)\n","damped_vibration_data_T = DAMPED_VIBRATION_DATA_10T / 10\n","damped_vibration_data[r'$\\frac{\\theta_i}{\\theta_{i+5}}$'] = damped_vibration_data[r'$\\theta_i$'] / damped_vibration_data[r'$\\theta_{i+5}$']\n","from math import log\n","damped_vibration_data[r'$\\beta$'] = damped_vibration_data[r'$\\frac{\\theta_i}{\\theta_{i+5}}$'].map(log) / 5 / damped_vibration_data_T\n","\n","damped_vibration_data"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2023-11-14T12:01:42.669879Z","iopub.status.busy":"2023-11-14T12:01:42.669499Z","iopub.status.idle":"2023-11-14T12:01:42.685337Z","shell.execute_reply":"2023-11-14T12:01:42.683931Z","shell.execute_reply.started":"2023-11-14T12:01:42.669840Z"},"trusted":true},"outputs":[],"source":["damped_vibration_data_beta = damped_vibration_data[r'$\\beta$'].mean()\n","print(f'Beta 的平均值 = {damped_vibration_data_beta}')"]}],"metadata":{"kaggle":{"accelerator":"none","dataSources":[{"datasetId":4000601,"sourceId":6964691,"sourceType":"datasetVersion"}],"dockerImageVersionId":30579,"isGpuEnabled":false,"isInternetEnabled":true,"language":"python","sourceType":"notebook"},"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.11.2"}},"nbformat":4,"nbformat_minor":4}