built environment
This commit is contained in:
@@ -1922,6 +1922,106 @@
|
||||
"print(\"✓ All tests passed! Standalone predictor matches original model perfectly.\")\n",
|
||||
"print(\"\\nThe standalone predictor is ready for integration into your simulator!\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "21babeb3",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Now, let's find the equilibrium height for our pod, given mass of 5.8 kg. \n",
|
||||
"\n",
|
||||
"5.8 kg * 9.81 $m/s^2$ = 56.898 N"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 279,
|
||||
"id": "badbc379",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"======================================================================\n",
|
||||
"EQUILIBRIUM GAP HEIGHT FINDER (Analytical Solution)\n",
|
||||
"======================================================================\n",
|
||||
"Pod mass: 5.8 kg\n",
|
||||
"Total weight: 56.898 N\n",
|
||||
"Target force per yoke: 28.449 N\n",
|
||||
"Parameters: currL = 0 A, currR = 0 A, roll = 0°\n",
|
||||
"\n",
|
||||
"using scipy.optimize.fsolve:\n",
|
||||
" Gap: 16.491741 mm → Force: 28.449000 N\n",
|
||||
"\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# Find equilibrium gap height for 5.8 kg pod using polynomial root finding\n",
|
||||
"import numpy as np\n",
|
||||
"from maglev_predictor import MaglevPredictor\n",
|
||||
"from scipy.optimize import fsolve\n",
|
||||
"\n",
|
||||
"# Initialize predictor\n",
|
||||
"predictor = MaglevPredictor()\n",
|
||||
"\n",
|
||||
"# Target force for 5.8 kg pod (total force = weight)\n",
|
||||
"# Since we have TWO yokes (front and back), each produces this force\n",
|
||||
"target_force_per_yoke = 5.8 * 9.81 / 2 # 28.449 N per yoke\n",
|
||||
"\n",
|
||||
"print(\"=\" * 70)\n",
|
||||
"print(\"EQUILIBRIUM GAP HEIGHT FINDER (Analytical Solution)\")\n",
|
||||
"print(\"=\" * 70)\n",
|
||||
"print(f\"Pod mass: 5.8 kg\")\n",
|
||||
"print(f\"Total weight: {5.8 * 9.81:.3f} N\")\n",
|
||||
"print(f\"Target force per yoke: {target_force_per_yoke:.3f} N\")\n",
|
||||
"print(f\"Parameters: currL = 0 A, currR = 0 A, roll = 0°\")\n",
|
||||
"print()\n",
|
||||
"\n",
|
||||
"# Method 2: Use scipy.optimize.fsolve for verification\n",
|
||||
"def force_error(gap_height):\n",
|
||||
" # Handle array input from fsolve (convert to scalar)\n",
|
||||
" gap_height = float(np.atleast_1d(gap_height)[0])\n",
|
||||
" force, _ = predictor.predict(currL=0, currR=0, roll=0, gap_height=gap_height)\n",
|
||||
" return force - target_force_per_yoke\n",
|
||||
"\n",
|
||||
"# Try multiple initial guesses to find all solutions\n",
|
||||
"initial_guesses = [8, 10, 15, 20, 25]\n",
|
||||
"scipy_solutions = []\n",
|
||||
"\n",
|
||||
"print(\"using scipy.optimize.fsolve:\")\n",
|
||||
"for guess in initial_guesses:\n",
|
||||
" solution = fsolve(force_error, guess)[0]\n",
|
||||
" if 5 <= solution <= 30: # Valid range\n",
|
||||
" force, torque = predictor.predict(currL=0, currR=0, roll=0, gap_height=solution)\n",
|
||||
" error = abs(force - target_force_per_yoke)\n",
|
||||
" if error < 0.01: # Valid solution (within 10 mN)\n",
|
||||
" scipy_solutions.append((solution, force))\n",
|
||||
"\n",
|
||||
"# Remove duplicates (solutions within 0.1 mm)\n",
|
||||
"unique_solutions = []\n",
|
||||
"for sol, force in scipy_solutions:\n",
|
||||
" is_duplicate = False\n",
|
||||
" for unique_sol, _ in unique_solutions:\n",
|
||||
" if abs(sol - unique_sol) < 0.1:\n",
|
||||
" is_duplicate = True\n",
|
||||
" break\n",
|
||||
" if not is_duplicate:\n",
|
||||
" unique_solutions.append((sol, force))\n",
|
||||
"\n",
|
||||
"for gap_val, force in unique_solutions:\n",
|
||||
" print(f\" Gap: {gap_val:.6f} mm → Force: {force:.6f} N\")\n",
|
||||
"print()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "3ec4bb72",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
|
||||
Reference in New Issue
Block a user