{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "colab": { "provenance": [] }, "kernelspec": { "name": "python3", "display_name": "Python 3" }, "language_info": { "name": "python" } }, "cells": [ { "cell_type": "markdown", "source": [ "## **Activity 3.3 : Estimate the relative measurement errors**" ], "metadata": { "id": "i8ZKTw7OUyAu" } }, { "cell_type": "markdown", "source": [ "To check the **relative errors** in calculations (orbital period and radius) you must compare your results obtained in this Scientific Challenge with those obtained after searching on internet.\n", "\n", "To calculate the relative error of any measurement apply the following equation:\n", "\\begin{equation}\n", " E_R = \\frac{|Measured Value-Real Value|}{Real Value} x 100\n", "\\end{equation}\n", "\n", "It is only used if we only have one measurement." ], "metadata": { "id": "Z8Zcz9egU2V_" } }, { "cell_type": "code", "source": [ "def calculate_relative_error(measured_value, real_value):\n", " measured_mass = float(measured_value)\n", " real_mass = float(real_value)\n", "\n", " relative_error = abs((measured_mass - real_mass) / real_mass) * 100\n", " return relative_error\n", "\n", "# Prompt the user to enter the measured value and real value in scientific notation\n", "measured_value = input(\"Enter the measured value of Jupiter's mass in scientific notation (in kg): \")\n", "real_value = input(\"Enter the real value of Jupiter's mass in scientific notation (in kg): \")\n", "\n", "# Calculate the relative error\n", "result = calculate_relative_error(measured_value, real_value)\n", "\n", "# Print the result\n", "print(\"The relative error is: {:.2f}%\".format(result))\n" ], "metadata": { "id": "zN8maKeQoaEP" }, "execution_count": null, "outputs": [] }, { "cell_type": "markdown", "source": [ "**Note 1**: A negative value for the relative error will probably mean that the absolute value has not been applied.\n", "\n", "**Note 2**: An error of less than or equal to 5% is acceptable." ], "metadata": { "id": "GktMQ0EmU5bN" } }, { "cell_type": "markdown", "source": [ " Also, we are going to calculate the **accidental error** of the four measurements you did for each galilean moon\n", "\n", "> \\begin{equation}\n", " Error = \\sqrt \\frac{\\sum_{i=1}^{n}(x_{i}- \\bar{x})^2}{n}\n", "\\end{equation}\n", "\n", " where\n", " \\begin{equation}\n", " x_{i}\n", " \\end{equation}\n", "are each value of the mass and\n", "where\n", " \\begin{equation}\n", "\\bar{x}\n", " \\end{equation}\n", " is the mean of all the n values" ], "metadata": { "id": "zFlPNtWPiB9h" } }, { "cell_type": "code", "source": [ "import math\n", "\n", "def get_float_input(message):\n", " while True:\n", " try:\n", " value = float(input(message))\n", " return value\n", " except ValueError:\n", " print(\"Invalid input. Please enter a numeric value.\")\n", "\n", "def calculate_mean(values):\n", " return sum(values) / len(values)\n", "\n", "def calculate_accidental_error(values, mean):\n", " error_sum_of_squares = sum((value - mean) ** 2 for value in values)\n", " return math.sqrt(error_sum_of_squares / len(values))\n", "\n", "def main():\n", " num_values = int(input(\"Enter the number of mass values you will input : \"))\n", " values = []\n", "\n", " for i in range(num_values):\n", " value = get_float_input(f\"Enter mass value {i + 1}: \")\n", " values.append(value)\n", "\n", " mean_value = calculate_mean(values)\n", " print(\"Mean value:\", mean_value)\n", "\n", " error_values = [value - mean_value for value in values]\n", " accidental_error = calculate_accidental_error(values, mean_value)\n", " print(\"Accidental error of the mass of Jupiters: {:.2f}%\".format(accidental_error))\n", "\n", "if __name__ == \"__main__\":\n", " main()\n" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "K6JVpp10G8iG", "outputId": "9cccc8cf-5070-48bb-dbee-235d63b74a9f" }, "execution_count": null, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "Enter the number of mass values you will input : 4\n", "Enter mass value 1: 1\n", "Enter mass value 2: 2\n", "Enter mass value 3: 3\n", "Enter mass value 4: 4\n", "Mean value: 2.5\n", "Accidental error of the mass of Jupiters: 1.12%\n" ] } ] }, { "cell_type": "markdown", "source": [ "Now you can go to Phase 4 and show the scientist within you [Phase 4](https://cesar.esa.int/upload/202307/student_p4.ipynb)" ], "metadata": { "id": "Yf-Rq96Y9x1W" } } ] }