{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "3b66972b",
   "metadata": {},
   "source": [
    "# Molla statica 1 Calibro\n",
    "Ac  = 3.20021 ± 0.00923\n",
    "\n",
    "# Molla statica 1 Sonar\n",
    "Ac  = 3.21962 ± 0.00633\n",
    "\n",
    "# Molla dinamica 1 Sonar\n",
    "KdC      = 3.2792872 ± 0.00924\n",
    "\n",
    "# Molla dinamica 1 Cronometro\n",
    "KdtC     = 3.66092 ± 0.10078\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "b349ba73",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "from scipy.stats import t as student_t"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "a68eb302",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "t = 3.807\n",
      "p-value (two-tailed) = 0.1924 %\n"
     ]
    }
   ],
   "source": [
    "# Valori statici (sonar)\n",
    "Nd = 10\n",
    "Ad =  3.220\n",
    "uAd = 0.006\n",
    "\n",
    "#Valori statici (calibro)\n",
    "Ns = 6\n",
    "As = 3.200\n",
    "uAs = 0.015\n",
    "\n",
    "#Nomi coerenti con Cannelli\n",
    "GdL = Nd + Ns - 2\n",
    "\n",
    "s2 = ( (Nd - 1) * uAd**2  +  (Ns - 1) * uAs**2 ) / GdL\n",
    "\n",
    "sigma2 = ( s2 / Nd )  + ( s2 / Ns )\n",
    "\n",
    "t = ( Ad - As ) / np.sqrt( sigma2 )\n",
    "\n",
    "\n",
    "p_value = 2 * (1 - student_t.cdf(abs(t), df=GdL))\n",
    "print(f\"t = {t:.3f}\")\n",
    "print(f\"p-value (two-tailed) = {p_value * 100:.4f} %\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "459b7f56",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "t = -5.278\n",
      "p-value (two-tailed) = 0.0117 %\n"
     ]
    }
   ],
   "source": [
    "# Valori statici (sonar)\n",
    "Nd = 10\n",
    "Ad =  3.220\n",
    "uAd = 0.006 * 3\n",
    "\n",
    "#Valori dinamici (sonar)\n",
    "Ns = 6\n",
    "As =  3.279\n",
    "uAs = 0.009 * 3\n",
    "\n",
    "#Nomi coerenti con Cannelli\n",
    "GdL = Nd + Ns - 2\n",
    "\n",
    "s2 = ( (Nd - 1) * uAd**2  +  (Ns - 1) * uAs**2 ) / GdL\n",
    "\n",
    "sigma2 = ( s2 / Nd )  + ( s2 / Ns )\n",
    "\n",
    "t = ( Ad - As ) / np.sqrt( sigma2 )\n",
    "\n",
    "\n",
    "p_value = 2 * (1 - student_t.cdf(abs(t), df=GdL))\n",
    "print(f\"t = {t:.3f}\")\n",
    "print(f\"p-value (two-tailed) = {p_value * 100:.4f} %\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "5d82905f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "t = 0.701\n",
      "p-value (two-tailed) = 49.4616 %\n"
     ]
    }
   ],
   "source": [
    "# Valori dinamici (sonar)\n",
    "Nd = 10\n",
    "Ad =  3.279\n",
    "uAd = 0.09 *3\n",
    "\n",
    "#Valori statici (calibro)\n",
    "Ns = 6\n",
    "As = 3.200\n",
    "uAs = 0.015 * 3\n",
    "\n",
    "#Nomi coerenti con Cannelli\n",
    "GdL = Nd + Ns - 2\n",
    "\n",
    "s2 = ( (Nd - 1) * uAd**2  +  (Ns - 1) * uAs**2 ) / GdL\n",
    "\n",
    "sigma2 = ( s2 / Nd )  + ( s2 / Ns )\n",
    "\n",
    "t = ( Ad - As ) / np.sqrt( sigma2 )\n",
    "\n",
    "\n",
    "p_value = 2 * (1 - student_t.cdf(abs(t), df=GdL))\n",
    "print(f\"t = {t:.3f}\")\n",
    "print(f\"p-value (two-tailed) = {p_value * 100:.4f} %\")\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": ".venv",
   "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.13.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
